List of usage examples for com.jgoodies.forms.layout FormLayout getConstraints
public CellConstraints getConstraints(Component component)
From source file:ai.aitia.meme.utils.FormsUtils.java
License:Open Source License
/** * Returns a DefaultFormBuilder containing the specified components and layout. * @param cols This parameter corresponds to the <code>encodedColumnSpecs</code> * parameter of FormLayout's ctor. Besides the encoding defined by FormLayout, * the following extensions are also available: the characters defined in the * global <code>{@link #gapLength}</code> variable (hereafter: gap-characters) * can be used to insert gap-columns. Gap columns must not appear in the * cell-specification (explained below) and they're automatically included in * column spans. // w ww . j a va 2s .com * Consecutive gap-characters are coalesced into 1 gap column by calculating * their cumulated pixel size. * @param rows A string describing general builder settings + cell-specification * + row/colum spans + row heights + row groups. See the examples. * The digits and underscores specify which component goes into which cell(s) * of the layout grid (cell-specification). There can be at most one character * for every (non-gap) column specified by <code>cols</code>. Rows must be * separated by the '|' character. Only underscores, digits and letters are * allowed in the cell-specification (space isn't). Underscore means that a * cell is empty. A digit/letter character refers to a component in the varargs * list: '0'..'9', 'A'..'Z', 'a'..'z' (in this order) denote the first 62 * components of the <code>args</code> list. Repeating the same digit specifies * the component's column span (and row span, if repeated in consecutive rows * in the same columns, like '3' in the example).<br> * After the cell-specification, but before the newline ('|') character * the row height and row grouping can also be specified. It must begin * with a space to separate it from the cell-specification. The row * height can be a gap-character (for constant heights only) or a string * that is interpreted by RowSpec.decodeSpecs(). If omitted, the height * spec. of the most recent row is inherited. Content rows inherit the * height of the previous content row, gap rows inherit the height of * the previous gap row. A row is a gap row if its cell-specification is * omitted.<br> * Row grouping forces equal heights to every member of the group. It * can be specified by "grp?" strings using any character in place of * '?' (except space and '|'. In the example 'grp1' uses '1'). Rows * using the same grouping character will be in the same group. * By default there're no groups. * <br> * General builder-settings can be specified at the beginning of the * string, enclosed in square brackets ([..]). (No space is allowed * after the closing ']'). This is intended for future extensions, too. * The list of available settings is described at the {@link Prop} * enumeration. Note that setting names are case-sensitive, and should * be separated by commas. * @param args List of components. Besides java.awt.Component objects, * the caller may use plain strings and instances of the {@link Separator} * class. Plain strings are used to create labels (with mnemonic-expansion). * Separator objects will create and add separators to the form. * Any of these objects may be followed optionally by a {@link CellConstraints}, * a {@link CellConstraints.Alignment} or a {@link CellInsets} object, * which overrides the cell's default alignment, can extend its row/column * span and adjust its insets.<br> * If the first element of <code>args</code> is a java.util.Map object, * it is treated as an additional mapping for gap-characters. This * overrides the default global mapping. Note that gap-characters can * help you to set up uniform spacing on your forms. For example, if * you use "-" as normal column-gap and "~" as normal row-gap, fine-tuning * the sizes of these gaps later is as easy as changing the mapping for "-" * and "~" — there's no need to update all the dlu sizes in all layouts. * @see * Example1: <pre> * build("6dlu, p, 6dlu, 50dlu, 6dlu", * "_0_1_ pref| 6dlu|" + * "_2_33 pref:grow(0.5) grp1||" + * "_4_33 grp1", * component0, component1, component2, component3, * component4, cellConstraintsForComponent4).getPanel() * </pre> * The same exaple with gap-characters: <pre> * build("~ p ~ 50dlu, 6dlu", * "01_ pref|~|" + * "233 pref:grow(0.5) grp1||" + * "433 grp1", * component0, component1, component2, component3, * component4, cellConstraintsForComponent4).getPanel() * </pre> * Example3 (only the second argument): <pre> * "[LineGapSize=6dlu, ParagraphGapSize=20dlu]_0_1||_2_3||_4_5" * </pre> * Note: this method can be used with no components and empty cell-specification, * too. In this case only a {@link DefaultFormBuilder} is created, configured * and returned. Its operations can then be used to append components to the form. */ @SuppressWarnings("unchecked") public static DefaultFormBuilder build(String cols, String rows, Object... args) { Context ctx = new Context(); // Parse column widths // int firstArg = 0; if (args.length > 0 && args[0] instanceof java.util.Map) { ctx.localGapSpec = (java.util.Map<Character, String>) args[0]; firstArg += 1; } StringBuilder colstmp = new StringBuilder(); ctx.contentCol = parseColumnWidths(colstmp, cols, ctx.localGapSpec, 0); // Parse the list of components (may include individual cell-constraints) // ctx.components = new ArrayList<Rec>(args.length); for (int i = firstArg; i < args.length; ++i) { Rec r = new Rec(args[i]); if (i + 1 < args.length) { if (args[i + 1] instanceof CellConstraints) { r.cc = (CellConstraints) args[++i]; r.useAlignment = true; } else if (args[i + 1] instanceof CellConstraints.Alignment) { CellConstraints.Alignment a = (CellConstraints.Alignment) args[++i]; if (a == CellConstraints.BOTTOM || a == CellConstraints.TOP) r.cc = new CellConstraints(1, 1, CellConstraints.DEFAULT, a); else if (a == CellConstraints.LEFT || a == CellConstraints.RIGHT) r.cc = new CellConstraints(1, 1, a, CellConstraints.DEFAULT); else if (a == CellConstraints.CENTER || a == CellConstraints.FILL) r.cc = new CellConstraints(1, 1, a, a); r.useAlignment = (r.cc != null); } else if (args[i + 1] instanceof CellInsets) { CellInsets ci = ((CellInsets) args[++i]); r.cc = ci.cc; r.useAlignment = ci.useAlignment; r.useInsets = true; //} //else if (args[i+1] == null) { // this would allow superfluous 'null' values // i += 1; } } ctx.components.add(r); } // Parse general settings (but don't apply yet) // EnumMap<Prop, Object> props = null; int i = rows.indexOf(']'); if (i >= 0) { String defaults = rows.substring(0, i); rows = rows.substring(++i); i = defaults.indexOf('['); ctx.input = defaults.substring(++i); props = Prop.parseGeneralSettings(ctx); } // Parse cell-specification, row heights and row groups // String cells[] = rows.split("\\|", -1); StringBuilder rowstmp = new StringBuilder(); java.util.HashMap<Character, int[]> rowGroups = new HashMap<Character, int[]>(); String lastContentRowHeight = "p", lastGapRowHeight = null; int rowcnt = 0; for (i = 0; i < cells.length; ++i) { rowcnt += 1; // See if it begins with a gap-character String g = (cells[i].length() > 0) ? getGap(cells[i].charAt(0), ctx.localGapSpec) : null; if (g != null) cells[i] = ' ' + cells[i]; int j = cells[i].indexOf(' '); boolean gapRow = (j == 0) || (cells[i].length() == 0); String rh = null; if (j >= 0) { String tmp[] = cells[i].substring(j + 1).split("\\s"); // expect height and grouping specifications cells[i] = cells[i].substring(0, j); ArrayList<String> gaps = new ArrayList<String>(); for (j = 0; j < tmp.length; ++j) { if (tmp[j].length() == 0) continue; if (tmp[j].length() == 4 && tmp[j].toLowerCase().startsWith("grp")) { Character groupch = tmp[j].charAt(3); rowGroups.put(groupch, appendIntArray(rowGroups.get(groupch), rowcnt)); } else { rh = tmp[j]; for (int k = 0, n = tmp[j].length(); k < n && addGap(gaps, getGap(tmp[j].charAt(k), ctx.localGapSpec)); ++k) ; } } if (!gaps.isEmpty()) { StringBuilder sb = new StringBuilder(); flushGaps(gaps, sb, false); rh = sb.substring(0, sb.length() - 1); } } if (rh == null) { if (gapRow && lastGapRowHeight == null) { ctx.b = new DefaultFormBuilder(new FormLayout(colstmp.toString(), "")); Prop.setBuilder(props, ctx); lastGapRowHeight = parseableRowSpec(ctx.b.getLineGapSpec()); } rh = gapRow ? lastGapRowHeight : lastContentRowHeight; } else { if (gapRow) lastGapRowHeight = rh; else lastContentRowHeight = rh; } if (i > 0) rowstmp.append(','); rowstmp.append(rh); } // Create builder // FormLayout fml = new FormLayout(colstmp.toString(), rowstmp.toString()); ctx.b = new DefaultFormBuilder(fml, debuggable()); // Apply builder settings (e.g. column groups) // Prop.setBuilder(props, ctx); props = null; // Set row groups // if (!rowGroups.isEmpty()) { int[][] tmp = new int[rowGroups.size()][]; // ??? i = 0; for (int[] a : rowGroups.values()) tmp[i++] = a; fml.setRowGroups(tmp); } rowGroups = null; JLabel lastLabel = null; java.util.HashSet<Character> done = new java.util.HashSet<Character>(ctx.components.size()); int h = cells.length; for (int y = 0; y < cells.length; ++y) { int w = cells[y].length(); int first = -1; for (int x = 0; x < w; ++x) { char ch = cells[y].charAt(x); if (ch == '_' || done.contains(ch)) continue; int idx = intValue(ch); Rec rec; try { rec = ctx.components.get(idx); } catch (IndexOutOfBoundsException e) { throw new IndexOutOfBoundsException( String.format("build() cells=\"%s\" ch=%c rows=\"%s\"", cells[y], ch, rows)); } CellConstraints cc = (rec.cc == null) ? new CellConstraints() : (CellConstraints) rec.cc.clone(); int sx = cc.gridWidth, sy = cc.gridHeight; // span x, span y while (x + sx < w && cells[y].charAt(x + sx) == ch) sx += 1; while (y + sy < h && ((x < cells[y + sy].length() && cells[y + sy].charAt(x) == ch) || (cells[y + sy].length() == 0 && y + sy + 1 < h && x < cells[y + sy + 1].length() && cells[y + sy + 1].charAt(x) == ch))) { sy += 1; } int colSpan = ctx.contentCol[x + sx - 1] - ctx.contentCol[x] + 1; ctx.b.setBounds(ctx.contentCol[x] + 1, ctx.b.getRow(), colSpan, sy); ctx.b.setLeadingColumnOffset(first & ctx.contentCol[x]); // 0 vagy x (itt nem kell a +1) first = 0; x += (sx - 1); Object comp = ctx.components.get(idx).component; if (comp instanceof Component) { ctx.b.append((Component) comp, colSpan); if (comp instanceof JLabel) lastLabel = (JLabel) comp; else { if (lastLabel != null) lastLabel.setLabelFor((Component) comp); lastLabel = null; } } else if (comp instanceof Separator) { comp = ctx.b.appendSeparator(comp.toString()); lastLabel = null; } else { comp = lastLabel = ctx.b.getComponentFactory().createLabel(comp.toString()); ctx.b.append(lastLabel, colSpan); } if (rec.useAlignment || rec.useInsets) { CellConstraints cc2 = fml.getConstraints((Component) comp); cc2.insets = cc.insets; cc2.hAlign = cc.hAlign; cc2.vAlign = cc.vAlign; fml.setConstraints((Component) comp, cc2); } done.add(ch); } lastLabel = null; ctx.b.nextLine(); } return ctx.b; }
From source file:com.aw.swing.mvp.ui.painter.ErrorBorderPainter.java
License:Open Source License
public void paintError(List components) { clearError(components);/* w w w . j ava2 s .com*/ for (Iterator iterator = components.iterator(); iterator.hasNext();) { BindingComponent bindingComponent = (BindingComponent) iterator.next(); JLabel label = (JLabel) ((JComponent) bindingComponent.getJComponent()) .getClientProperty(BindingComponent.ATTR_ICONO); if (label != null) { return; } logger.debug("creating icon for " + bindingComponent.getFieldName()); JComponent feedbackComponent = createFeedbackComponent(); if (feedbackComponent == null) { return; } Container container = bindingComponent.getJComponent().getParent(); // GMC Todo ver q pasa cuando no se envia null -> Ver como manejar este caso para los diferentes layouts // container.add(feedbackComponent, null); CellConstraints cc = new CellConstraints(); container.add(feedbackComponent, cc.xy(1, 1)); Point overlayPosition = getFeedbackComponentOrigin(feedbackComponent, bindingComponent.getJComponent()); overlayPosition.translate(-3, +2); feedbackComponent.setLocation(overlayPosition); FormLayout layout = ((FormLayout) container.getLayout()); CellConstraints cc1 = layout.getConstraints(bindingComponent.getJComponent()); container.add(feedbackComponent, cc1.xy(cc1.gridX - 1, cc1.gridY + 1, CellConstraints.RIGHT, CellConstraints.BOTTOM)); bindingComponent.getJComponent().putClientProperty(BindingComponent.ATTR_ICONO, feedbackComponent); } }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
private static void updateGridConstraintsFromCellConstraints(RadContainer grid) { FormLayout layout = (FormLayout) grid.getLayout(); for (RadComponent c : grid.getComponents()) { CellConstraints cc = layout.getConstraints(c.getDelegee()); GridConstraints gc = c.getConstraints(); copyCellToGridConstraints(gc, cc); }/*from w w w . j a v a2s . co m*/ }
From source file:org.archiviststoolkit.dialog.BatchLocationCreation.java
License:Open Source License
private void hideRepositoryPopupIfNecessary() { if (!Users.doesCurrentUserHaveAccess(Users.ACCESS_CLASS_SUPERUSER)) { repositoryTextField.setOpaque(false); repositoryTextField.setEditable(false); FormLayout formLayout = (FormLayout) contentPanel.getLayout(); CellConstraints cc = formLayout.getConstraints(repository); contentPanel.remove(repository); contentPanel.add(repositoryTextField, cc); useRepositoryPopup = false;/* ww w . j a v a 2 s. co m*/ } }
From source file:org.archiviststoolkit.dialog.QueryEditor.java
License:Open Source License
private void createPopupValues() { ArrayList<QueryField> fieldValues1 = new ArrayList<QueryField>(); ArrayList<QueryField> fieldValues2 = new ArrayList<QueryField>(); ArrayList<QueryField> sortFieldValues = new ArrayList<QueryField>(); Set<DatabaseFields> fields = new DatabaseTablesDAO().getFieldList(this.getClazz().getSimpleName()); for (DatabaseFields field : fields) { if (field.getIncludeInSearchEditor()) { fieldValues1.add(new QueryField(field, getClazz())); fieldValues2.add(new QueryField(field, getClazz())); }/*from w ww.j a v a 2 s . c o m*/ // if (field.getAllowSort()) { // sortFieldValues.add(new QueryField(field.getFieldName(), getClazz())); // } } Collections.sort(fieldValues1); Collections.sort(fieldValues2); Collections.sort(sortFieldValues); setFieldValues(fieldValues1, fieldValues2, sortFieldValues); FormLayout formLayout = (FormLayout) contentPane.getLayout(); placeHolder1.disableValueField(); currentValue1Component = placeHolder1; value1CellConstraints = formLayout.getConstraints(placeHolder1); placeHolder2.disableValueField(); currentValue2Component = placeHolder2; value2CellConstraints = formLayout.getConstraints(placeHolder2); }
From source file:org.archiviststoolkit.dialog.QueryEditorTextPanel.java
License:Open Source License
private void setComboBox(JComboBox comboBox) { FormLayout formLayout = (FormLayout) this.getLayout(); CellConstraints cc = formLayout.getConstraints(value); this.valueComboBox = comboBox; this.remove(value); this.add(valueComboBox, cc); useComboBox = true;/* w w w. j av a2 s . co m*/ }
From source file:org.archiviststoolkit.editor.LocationFields.java
License:Open Source License
private void hideRepositoryPopupIfNecessary() { if (!Users.doesCurrentUserHaveAccess(Users.ACCESS_CLASS_SUPERUSER)) { repositoryTextField.setOpaque(false); repositoryTextField.setEditable(false); FormLayout formLayout = (FormLayout) this.getLayout(); CellConstraints cc = formLayout.getConstraints(repository); this.remove(repository); this.add(repositoryTextField, cc); }//w w w.j a va 2 s .c o m }
From source file:org.archiviststoolkit.editor.UserFields.java
License:Open Source License
private void initAccess() { //hide repository popup if necessary if (!Users.doesCurrentUserHaveAccess(Users.ACCESS_CLASS_SUPERUSER)) { repositoryTextField.setOpaque(false); repositoryTextField.setEditable(false); FormLayout formLayout = (FormLayout) this.getLayout(); CellConstraints cc = formLayout.getConstraints(repository); this.remove(repository); this.add(repositoryTextField, cc); }/*from w w w .java2 s . co m*/ //if user is not at least a repository manager set the record to read only if (!Users.doesCurrentUserHaveAccess(Users.ACCESS_CLASS_REPOSITORY_MANAGER)) { setFormToReadOnly(); changePasswordButton.setVisible(false); } }
From source file:org.archiviststoolkit.mydomain.DomainEditorFields.java
License:Open Source License
public void convertComboBoxToNonEnterableTextField(JComboBox comboBox, String fieldName) { Container parent = comboBox.getParent(); FormLayout formLayout = (FormLayout) parent.getLayout(); CellConstraints cellConstraints = formLayout.getConstraints(comboBox); parent.remove(comboBox);//from w ww. j a v a 2 s . c om JTextField textField = BasicComponentFactory.createTextField(detailsModel.getModel(fieldName)); textField.setEditable(false); textField.setOpaque(false); parent.add(textField, cellConstraints); }
From source file:org.archiviststoolkit.structure.DefaultValuesFields.java
License:Open Source License
public DefaultValuesFields() { super();//from w w w . j a v a 2 s . c o m initComponents(); FormLayout layout = (FormLayout) this.getLayout(); valueCellConstraints = layout.getConstraints(valuePlaceHolder); this.remove(valuePlaceHolder); }