public void formTextArea(String fieldName, String value) { if (value == null) { value = ""; } int valueLen = value.length(); int cols = 50; int rows = 1; rows = Math.max(rows, NumberUtility.divideAndCeil(valueLen, cols)); rows = Math.max(rows, StringUtility.getLineCount(value)); m_out.print("<textarea rows=" + rows + " cols=" + cols + " name='" + fieldName + "'>"); print(value); m_out.print("</textarea>"); }
/** * @return the default number of columns based on the height of the field and the number of visible buttons (legacy * case). The value is always > 0 */ protected int calcDefaultGridColumnCount() { GridData parentData = m_group.getGridData(); if (parentData == null || parentData.h < 1) { return 1; // by default: vertical align (one column) } int numVisibleFields = m_fields.size(); if (numVisibleFields < 1) { return 1; // no fields } int height = Math.min(numVisibleFields, parentData.h); if (height <= 1) { return numVisibleFields; } return divideAndCeil(numVisibleFields, height); }
/** * Sets GridData on each button (= field) of the group. */ protected void applyGridData() { int numVisibleFields = m_fields.size(); m_gridColumns = Math.min(m_group.getGridColumnCount(), numVisibleFields); if (m_gridColumns <= 0) { m_gridColumns = calcDefaultGridColumnCount(); } m_gridRows = divideAndCeil(numVisibleFields, m_gridColumns); int i = 0; for (int r = 0; r < m_gridRows; r++) { for (int c = 0; c < m_gridColumns; c++) { if (i < numVisibleFields) { GridData data = GridDataBuilder.createFromHints(m_fields.get(i), 1); data.x = c; data.y = r; data.w = 1; data.h = 1; m_fields.get(i).setGridDataInternal(data); i++; } else { break; } } } }
reorgBounds.y = minY; VerticalGridMatrix reorgMatrix = new VerticalGridMatrix(reorgBounds.x, reorgBounds.y, reorgBounds.w, divideAndCeil(usedCells, reorgBounds.w)); reorgMatrix.addCells(occupiedCells); while (!reorgMatrix.computeGridData(sortedFieldsToReorganize)) {
@Override protected void layoutAllDynamic(List<IFormField> fields) { // calculate the used cells int cellCount = 0; for (IFormField f : fields) { GridData hints = getGridDataFromHints(f, getGridColumnCount()); cellCount += hints.w * hints.h; } int rowCount = divideAndCeil(cellCount, getGridColumnCount()); VerticalGridMatrix matrix = new VerticalGridMatrix(getGridColumnCount(), rowCount); while (!matrix.computeGridData(fields)) { matrix.resetAll(getGridColumnCount(), ++rowCount); } // setGridData for (IFormField f : fields) { GridData data = matrix.getGridData(f); f.setGridDataInternal(data); } setGridRows(matrix.getRowCount()); }