<commit_before>package org.minimalj.frontend.json;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.minimalj.frontend.Frontend.FormContent;
import org.minimalj.frontend.Frontend.IComponent;

public class JsonFormContent extends JsonComponent implements FormContent {

	public static final String CAPTION = "caption";
	public static final String VALIDATION_MESSAGE = "validationMessage";
	public static final String SPAN = "span";

	private final List<List<Map<String, Object>>> rows = new ArrayList<>();
	private final int columns;
	
	private List<Map<String, Object>> actualRow = new ArrayList<>();
	private int actualColumn;
	
	public JsonFormContent(int columns, int columnWidth) {
		super("Form");
		if (columns < 1) throw new IllegalArgumentException(JsonFormContent.class.getSimpleName() + " can only work with at least 1 column");
		this.columns = columns;

		put("columns", columns);
		put("columnWidth", columnWidth);
		
		put("rows", rows);
		
		createNewRow();
	}

	private void createNewRow() {
		actualRow = new ArrayList<>();
		rows.add(actualRow);
		actualColumn = 0;
	}
	
	@Override
	public void add(IComponent component) {
		JsonComponent jsonComponent = (JsonComponent) component;
		createNewRow();
		actualRow.add(jsonComponent);
		actualColumn = columns;
	}

	@Override
	public void add(String caption, IComponent component, int span) {
		JsonComponent jsonComponent = (JsonComponent) component;
		jsonComponent.put(CAPTION, caption);
		if (actualColumn >= columns) {
			createNewRow();
		}
		if (span > 1) {
			jsonComponent.put(SPAN, span);
		}
		actualRow.add(jsonComponent);
		actualColumn += span;
	}

	@Override
	public void setValidationMessages(IComponent component, List<String> validationMessages) {
		JsonComponent jsonComponent = (JsonComponent) component;
		if (validationMessages.size() == 1) {
			jsonComponent.put(VALIDATION_MESSAGE, validationMessages.get(0));
		} else if (!validationMessages.isEmpty()) {
			StringBuilder s = new StringBuilder();
			for (int i = 0; i<validationMessages.size()-1; i++) {
				s.append(validationMessages.get(i));
				s.append("<BR>");
			}
			s.append(validationMessages.get(validationMessages.size()-1));
		} else {
			jsonComponent.put(VALIDATION_MESSAGE, "");
		}
	}

}
<commit_msg>JsonClient: titles and texts should cover complete width of forms<commit_after>package org.minimalj.frontend.json;

import java.util.ArrayList;
import java.util.List;
import java.util.Map;

import org.minimalj.frontend.Frontend.FormContent;
import org.minimalj.frontend.Frontend.IComponent;

public class JsonFormContent extends JsonComponent implements FormContent {

	public static final String CAPTION = "caption";
	public static final String VALIDATION_MESSAGE = "validationMessage";
	public static final String SPAN = "span";

	private final List<List<Map<String, Object>>> rows = new ArrayList<>();
	private final int columns;
	
	private List<Map<String, Object>> actualRow = new ArrayList<>();
	private int actualColumn;
	
	public JsonFormContent(int columns, int columnWidth) {
		super("Form");
		if (columns < 1) throw new IllegalArgumentException(JsonFormContent.class.getSimpleName() + " can only work with at least 1 column");
		this.columns = columns;

		put("columns", columns);
		put("columnWidth", columnWidth);
		
		put("rows", rows);
		
		createNewRow();
	}

	private void createNewRow() {
		actualRow = new ArrayList<>();
		rows.add(actualRow);
		actualColumn = 0;
	}
	
	@Override
	public void add(IComponent component) {
		JsonComponent jsonComponent = (JsonComponent) component;
		createNewRow();
		if (columns > 1) {
			jsonComponent.put(SPAN, columns);
		}
		actualRow.add(jsonComponent);
		actualColumn = columns;
	}

	@Override
	public void add(String caption, IComponent component, int span) {
		JsonComponent jsonComponent = (JsonComponent) component;
		jsonComponent.put(CAPTION, caption);
		if (actualColumn >= columns) {
			createNewRow();
		}
		if (span > 1) {
			jsonComponent.put(SPAN, span);
		}
		actualRow.add(jsonComponent);
		actualColumn += span;
	}

	@Override
	public void setValidationMessages(IComponent component, List<String> validationMessages) {
		JsonComponent jsonComponent = (JsonComponent) component;
		if (validationMessages.size() == 1) {
			jsonComponent.put(VALIDATION_MESSAGE, validationMessages.get(0));
		} else if (!validationMessages.isEmpty()) {
			StringBuilder s = new StringBuilder();
			for (int i = 0; i<validationMessages.size()-1; i++) {
				s.append(validationMessages.get(i));
				s.append("<BR>");
			}
			s.append(validationMessages.get(validationMessages.size()-1));
		} else {
			jsonComponent.put(VALIDATION_MESSAGE, "");
		}
	}

}

{'fraction_non_alphanumeric': 0.11903765690376569, 'fraction_numerical': 0.0039748953974895395, 'mean_word_length': 4.495402298850575, 'pattern_counts': {'":': 0, '<': 27, '<?xml version=': 0, '>': 28, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '3870801', 'n_tokens_mistral': 1545, 'n_tokens_neox': 1380, 'n_words': 352}