List of usage examples for com.jgoodies.forms.layout FormLayout setRowGroups
public void setRowGroups(int[][] groupOfIndices)
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. //from w ww .ja va2 s . co m * 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:ch.fork.AdHocRailway.ui.locomotives.configuration.LocomotiveConfig.java
License:Open Source License
private void buildPanel() { initComponents();/*from www .j av a 2s . c o m*/ final FormLayout layout = new FormLayout("right:pref, 3dlu, pref:grow, 30dlu, right:pref, 3dlu, pref:grow", "p:grow, 3dlu,p:grow, 3dlu,p:grow, 3dlu,p:grow, 3dlu,p:grow, 3dlu,p:grow, 3dlu,p:grow"); layout.setColumnGroups(new int[][] { { 1, 5 }, { 3, 7 } }); layout.setRowGroups(new int[][] { { 3, 5, 7, 9 } }); final PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); final CellConstraints cc = new CellConstraints(); builder.addSeparator("General", cc.xyw(1, 1, 3)); builder.addLabel("Name", cc.xy(1, 3)); builder.add(nameTextField, cc.xy(3, 3)); builder.addLabel("Description", cc.xy(1, 5)); builder.add(descTextField, cc.xy(3, 5)); builder.addLabel("Type", cc.xy(1, 7)); builder.add(locomotiveTypeComboBox, cc.xy(3, 7)); builder.addLabel("Image", cc.xy(1, 9)); builder.add(chooseImageButton, cc.xy(3, 9)); builder.add(imageLabel, cc.xyw(1, 11, 3)); builder.addSeparator("Interface", cc.xyw(5, 1, 3)); builder.addLabel("Bus", cc.xy(5, 3)); builder.add(busSpinner, cc.xy(7, 3)); builder.addLabel("Address 1", cc.xy(5, 5)); builder.add(address1Spinner, cc.xy(7, 5)); builder.addLabel("Address 2", cc.xy(5, 7)); builder.add(address2Spinner, cc.xy(7, 7)); builder.add(functionsTable, cc.xywh(5, 9, 3, 3)); builder.add(errorPanel, cc.xyw(1, 13, 3)); builder.add(buildButtonBar(), cc.xyw(5, 13, 3)); // add(builder.getPanel()); setLayout(new MigLayout()); add(new JLabel("Name")); add(nameTextField, "w 300!"); add(new JLabel("Bus"), "gap unrelated"); add(busSpinner, "w 150!, wrap"); add(new JLabel("Description")); add(descTextField, "w 300!"); add(new JLabel("Address 1"), "gap unrelated"); add(address1Spinner, "w 150!, wrap"); add(new JLabel("Type")); add(locomotiveTypeComboBox, "w 150!"); add(new JLabel("Address 2"), "gap unrelated"); add(address2Spinner, "w 150!, wrap"); add(new JLabel("Image")); add(chooseImageButton, "w 150!"); add(new JLabel("Functions"), "gap unrelated"); add(new JScrollPane(functionsTable), "h 200!, w 300!, span 1 2, wrap"); add(imageLabel, "align center, span 2, wrap"); add(buildButtonBar(), "span 4, align right"); }
From source file:ch.fork.AdHocRailway.ui.turnouts.configuration.TurnoutConfig.java
License:Open Source License
private void buildPanel() { initComponents();//from w w w. ja v a2 s . c om final FormLayout layout = new FormLayout( "right:pref, 3dlu, pref:grow, 30dlu, right:pref, 3dlu, pref:grow, 3dlu,pref:grow, 30dlu, pref", "p:grow, 3dlu,p:grow, 3dlu,p:grow, 3dlu,p:grow, 3dlu, p:grow, 3dlu, p:grow, 10dlu,p:grow"); layout.setColumnGroups(new int[][] { { 1, 5 }, { 3, 7 } }); layout.setRowGroups(new int[][] { { 3, 5, 7, 9, 11 } }); builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); final CellConstraints cc = new CellConstraints(); builder.addSeparator("General", cc.xyw(1, 1, 3)); builder.addLabel("Number", cc.xy(1, 3)); builder.add(numberTextField, cc.xy(3, 3)); builder.addLabel("Description", cc.xy(1, 5)); builder.add(descTextField, cc.xy(3, 5)); builder.addLabel("Type", cc.xy(1, 7)); builder.add(turnoutTypeComboBox, cc.xy(3, 7)); builder.addLabel("Default State", cc.xy(1, 9)); builder.add(turnoutDefaultStateComboBox, cc.xy(3, 9)); builder.addLabel("Orientation", cc.xy(1, 11)); builder.add(turnoutOrientationComboBox, cc.xy(3, 11)); builder.addSeparator("Interface", cc.xyw(5, 1, 5)); builder.addLabel("Bus 1", cc.xy(5, 3)); builder.add(bus1TextField, cc.xy(7, 3)); builder.addLabel("Address 1", cc.xy(5, 5)); builder.add(address1TextField, cc.xy(7, 5)); builder.addLabel("Bus 2", cc.xy(5, 7)); builder.add(bus2TextField, cc.xy(7, 7)); builder.addLabel("Address 2", cc.xy(5, 9)); builder.add(address2TextField, cc.xy(7, 9)); builder.add(switched1Checkbox, cc.xy(9, 5)); builder.add(switched2Checkbox, cc.xy(9, 9)); builder.addSeparator("Test", cc.xy(11, 1)); builder.add(testTurnoutWidget, cc.xywh(11, 3, 1, 9)); builder.add(errorPanel, cc.xyw(1, 13, 7)); builder.add(buildButtonBar(), cc.xyw(7, 13, 5)); add(builder.getPanel()); }
From source file:ch.zhaw.ias.dito.ui.ProcessPanel.java
License:BSD License
public ProcessPanel() { setBorder(BorderFactory.createEtchedBorder()); FormLayout layout = new FormLayout("5dlu, 50dlu:grow, 5dlu", "5dlu, fill:pref, fill:pref:grow, fill:pref, fill:pref:grow, fill:pref, fill:pref:grow, fill:pref, fill:pref:grow, fill:pref, 5dlu, fill:20dlu, 5dlu, fill:8dlu, 5dlu"); int[][] rowGroups = new int[][] { { 2, 4, 6, 8 }, { 3, 5, 7 } }; layout.setRowGroups(rowGroups); CellConstraints cc = new CellConstraints(); PanelBuilder pb = new PanelBuilder(layout); panels.put(ScreenEnum.INPUT,//from w w w. ja v a 2s .co m new ProcessStepPanel(ScreenEnum.INPUT, ConfigProperty.INPUT_FILENAME, ConfigProperty.INPUT_SIZE)); panels.put(ScreenEnum.QUESTION, new ProcessStepPanel(ScreenEnum.QUESTION, ConfigProperty.QUESTION_NUMBER)); panels.put(ScreenEnum.METHOD, new ProcessStepPanel(ScreenEnum.METHOD, ConfigProperty.METHOD_NAME, ConfigProperty.RANDOM_SAMPLE)); panels.put(ScreenEnum.ANALYSIS, new ProcessStepPanel(ScreenEnum.ANALYSIS)); panels.put(ScreenEnum.OUTPUT, new ProcessStepPanel(ScreenEnum.OUTPUT, ConfigProperty.OUTPUT_FILENAME, ConfigProperty.OUTPUT_PRECISION)); pb.add(panels.get(ScreenEnum.INPUT), cc.xy(2, 2)); pb.add(new ArrowPanel(), cc.xy(2, 3)); pb.add(panels.get(ScreenEnum.QUESTION), cc.xy(2, 4)); pb.add(new ArrowPanel(), cc.xy(2, 5)); pb.add(panels.get(ScreenEnum.METHOD), cc.xy(2, 6)); pb.add(new ArrowPanel(), cc.xy(2, 7)); pb.add(panels.get(ScreenEnum.ANALYSIS), cc.xy(2, 8)); pb.add(new ArrowPanel(), cc.xy(2, 9)); pb.add(panels.get(ScreenEnum.OUTPUT), cc.xy(2, 10)); pb.add(progress, cc.xy(2, 12)); pb.add(status, cc.xy(2, 14)); this.setLayout(new BorderLayout()); add(pb.getPanel(), BorderLayout.CENTER); Logger.INSTANCE.addInterface(this); }
From source file:com.intellij.uiDesigner.actions.GroupRowsColumnsAction.java
License:Apache License
protected void actionPerformed(CaptionSelection selection) { FormLayout layout = (FormLayout) selection.getContainer().getLayout(); int[][] oldGroups = selection.isRow() ? layout.getRowGroups() : layout.getColumnGroups(); int[][] newGroups = new int[oldGroups.length + 1][]; System.arraycopy(oldGroups, 0, newGroups, 0, oldGroups.length); int[] cellsToGroup = getCellsToGroup(selection); newGroups[oldGroups.length] = new int[cellsToGroup.length]; for (int i = 0; i < cellsToGroup.length; i++) { newGroups[oldGroups.length][i] = cellsToGroup[i] + 1; }//from ww w .ja va 2 s .c o m if (selection.isRow()) { layout.setRowGroups(newGroups); } else { layout.setColumnGroups(newGroups); } }
From source file:com.intellij.uiDesigner.actions.UngroupRowsColumnsAction.java
License:Apache License
protected void actionPerformed(CaptionSelection selection) { FormLayout layout = (FormLayout) selection.getContainer().getLayout(); int[][] oldGroups = selection.isRow() ? layout.getRowGroups() : layout.getColumnGroups(); List<int[]> newGroups = new ArrayList<int[]>(); int[] selInts = selection.getSelection(); for (int[] group : oldGroups) { if (!GroupRowsColumnsAction.intersect(group, selInts)) { newGroups.add(group);//from ww w .j av a 2 s. c om } } int[][] newGroupArray = newGroups.toArray(new int[newGroups.size()][]); if (selection.isRow()) { layout.setRowGroups(newGroupArray); } else { layout.setColumnGroups(newGroupArray); } }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
@Override public int deleteGridCells(final RadContainer grid, final int cellIndex, final boolean isRow) { int result = 1; FormLayout formLayout = (FormLayout) grid.getLayout(); adjustDeletedCellOrigins(grid, cellIndex, isRow); if (isRow) {//from w w w.jav a 2s. c o m int[][] groupIndices = formLayout.getRowGroups(); groupIndices = removeDeletedCell(groupIndices, cellIndex + 1); formLayout.setRowGroups(groupIndices); formLayout.removeRow(cellIndex + 1); updateGridConstraintsFromCellConstraints(grid); if (formLayout.getRowCount() > 0 && formLayout.getRowCount() % 2 == 0) { int gapRowIndex = (cellIndex >= grid.getGridRowCount()) ? cellIndex - 1 : cellIndex; if (GridChangeUtil.isRowEmpty(grid, gapRowIndex)) { formLayout.removeRow(gapRowIndex + 1); updateGridConstraintsFromCellConstraints(grid); result++; } } } else { int[][] groupIndices = formLayout.getColumnGroups(); groupIndices = removeDeletedCell(groupIndices, cellIndex + 1); formLayout.setColumnGroups(groupIndices); formLayout.removeColumn(cellIndex + 1); updateGridConstraintsFromCellConstraints(grid); if (formLayout.getColumnCount() > 0 && formLayout.getColumnCount() % 2 == 0) { int gapColumnIndex = (cellIndex >= grid.getGridColumnCount()) ? cellIndex - 1 : cellIndex; if (GridChangeUtil.isColumnEmpty(grid, gapColumnIndex)) { formLayout.removeColumn(gapColumnIndex + 1); updateGridConstraintsFromCellConstraints(grid); result++; } } } return result; }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
@Override public void createSnapshotLayout(final SnapshotContext context, final JComponent parent, final RadContainer container, final LayoutManager layout) { ColumnSpec[] colSpecs;// ww w.j a v a 2s .co m RowSpec[] rowSpecs; int[][] rowGroups; int[][] columnGroups; try { Method method = layout.getClass().getMethod("getRowCount", ArrayUtil.EMPTY_CLASS_ARRAY); int rowCount = ((Integer) method.invoke(layout, ArrayUtil.EMPTY_OBJECT_ARRAY)).intValue(); method = layout.getClass().getMethod("getColumnCount", ArrayUtil.EMPTY_CLASS_ARRAY); int columnCount = ((Integer) method.invoke(layout, ArrayUtil.EMPTY_OBJECT_ARRAY)).intValue(); rowSpecs = new RowSpec[rowCount]; colSpecs = new ColumnSpec[columnCount]; method = layout.getClass().getMethod("getRowSpec", int.class); for (int i = 0; i < rowCount; i++) { rowSpecs[i] = (RowSpec) createSerializedCopy(method.invoke(layout, i + 1)); } method = layout.getClass().getMethod("getColumnSpec", int.class); for (int i = 0; i < columnCount; i++) { colSpecs[i] = (ColumnSpec) createSerializedCopy(method.invoke(layout, i + 1)); } method = layout.getClass().getMethod("getRowGroups", ArrayUtil.EMPTY_CLASS_ARRAY); rowGroups = (int[][]) method.invoke(layout); method = layout.getClass().getMethod("getColumnGroups", ArrayUtil.EMPTY_CLASS_ARRAY); columnGroups = (int[][]) method.invoke(layout); } catch (Exception ex) { throw new RuntimeException(ex); } final FormLayout formLayout = new FormLayout(colSpecs, rowSpecs); formLayout.setRowGroups(rowGroups); formLayout.setColumnGroups(columnGroups); container.setLayout(formLayout); }
From source file:edu.ku.brc.af.auth.UserAndMasterPasswordMgr.java
License:Open Source License
/** * @return// w w w. ja va2 s. c om */ protected String[] getUserNamePasswordKey() { loadAndPushResourceBundle("masterusrpwd"); FormLayout layout = new FormLayout("p, 4dlu, p, 8px, p", "p, 2dlu, p, 2dlu, p, 16px, p, 2dlu, p, 2dlu, p"); layout.setRowGroups(new int[][] { { 1, 3, 5 } }); PanelBuilder pb = new PanelBuilder(layout); final JTextField dbUsrTxt = createTextField(30); final JPasswordField dbPwdTxt = createPasswordField(30); final JTextField usrText = createTextField(30); final JPasswordField pwdText = createPasswordField(30); final char echoChar = pwdText.getEchoChar(); final JLabel dbUsrLbl = createI18NFormLabel("USERNAME", SwingConstants.RIGHT); final JLabel dbPwdLbl = createI18NFormLabel("PASSWORD", SwingConstants.RIGHT); final JLabel usrLbl = createI18NFormLabel("USERNAME", SwingConstants.RIGHT); final JLabel pwdLbl = createI18NFormLabel("PASSWORD", SwingConstants.RIGHT); usrText.setText(usersUserName); CellConstraints cc = new CellConstraints(); int y = 1; pb.addSeparator(UIRegistry.getResourceString("MASTER_SEP"), cc.xyw(1, y, 5)); y += 2; pb.add(dbUsrLbl, cc.xy(1, y)); pb.add(dbUsrTxt, cc.xy(3, y)); y += 2; pb.add(dbPwdLbl, cc.xy(1, y)); pb.add(dbPwdTxt, cc.xy(3, y)); y += 2; pb.addSeparator(UIRegistry.getResourceString("USER_SEP"), cc.xyw(1, y, 5)); y += 2; pb.add(usrLbl, cc.xy(1, y)); pb.add(usrText, cc.xy(3, y)); y += 2; pb.add(pwdLbl, cc.xy(1, y)); pb.add(pwdText, cc.xy(3, y)); pb.setDefaultDialogBorder(); final CustomDialog dlg = new CustomDialog((Frame) null, getResourceString("MASTER_INFO_TITLE"), true, CustomDialog.OKCANCELAPPLYHELP, pb.getPanel()); dlg.setOkLabel(getResourceString("GENERATE_KEY")); dlg.setHelpContext("MASTERPWD_GEN"); dlg.setApplyLabel(showPwdLabel); dlg.createUI(); dlg.getOkBtn().setEnabled(false); popResourceBundle(); DocumentListener docListener = new DocumentAdaptor() { @Override protected void changed(DocumentEvent e) { String dbUserStr = dbUsrTxt.getText(); boolean enable = !dbUserStr.isEmpty() && !((JTextField) dbPwdTxt).getText().isEmpty() && !usrText.getText().isEmpty() && !((JTextField) pwdText).getText().isEmpty(); if (enable && isNotEmpty(dbUserStr) && dbUserStr.equalsIgnoreCase("root")) { loadAndPushResourceBundle("masterusrpwd"); UIRegistry.showLocalizedError("MASTER_NO_ROOT"); popResourceBundle(); enable = false; } dlg.getOkBtn().setEnabled(enable); } }; dbUsrTxt.getDocument().addDocumentListener(docListener); dbPwdTxt.getDocument().addDocumentListener(docListener); usrText.getDocument().addDocumentListener(docListener); pwdText.getDocument().addDocumentListener(docListener); currEcho = echoChar; dlg.getApplyBtn().addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { dlg.getApplyBtn().setText(currEcho == echoChar ? hidePwdLabel : showPwdLabel); currEcho = currEcho == echoChar ? 0 : echoChar; pwdText.setEchoChar(currEcho); dbPwdTxt.setEchoChar(currEcho); } }); dlg.setVisible(true); if (!dlg.isCancelled()) { return new String[] { dbUsrTxt.getText(), ((JTextField) dbPwdTxt).getText(), usrText.getText(), ((JTextField) pwdText).getText() }; } return null; }
From source file:edu.udo.scaffoldhunter.gui.datasetmanagement.ManageRulesetsDialog.java
License:Open Source License
/** * Initialises all GUI components/*from w w w . ja va 2 s . c o m*/ */ private void initGUI() { FormLayout containerLayout; PanelBuilder containerBuilder; FormLayout leftLayout; PanelBuilder leftBuilder; FormLayout rightLayout; PanelBuilder rightBuilder; ButtonStackBuilder rulesetListButtons; ButtonStackBuilder ruleAddRemoveButtons; ButtonStackBuilder ruleUpDownButtons; CellConstraints cc = new CellConstraints(); String listPrototypeElement = "____________________"; int listsNumRows = 15; JComboBox ascendingChooser; setTitle(_("ManageRulesets.WindowTitle")); setLayout(new BorderLayout()); setModal(true); container = new JPanel(); add(container, BorderLayout.CENTER); containerLayout = new FormLayout("p, 2dlu, p:g(1.0)", "f:p:g(1.0), p"); containerBuilder = new PanelBuilder(containerLayout, container); containerBuilder.setDefaultDialogBorder(); leftContainer = new JPanel(); leftContainer.setBorder(BorderFactory.createTitledBorder(_("ManageRulesets.Rulesets"))); containerBuilder.add(leftContainer, cc.rc(1, 1)); leftLayout = new FormLayout("p, 2dlu, p:g(1.0)", "f:p:g(1.0)"); leftBuilder = new PanelBuilder(leftLayout, leftContainer); rulesets = new DefaultListModel(); rulesetsList = new JList(rulesets); rulesetsList.setVisibleRowCount(listsNumRows); rulesetsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); rulesetsList.setPrototypeCellValue(listPrototypeElement); rulesetsList.addListSelectionListener(new RulesetsListSelectionListener()); rulesetsListScroll = new JScrollPane(rulesetsList); leftBuilder.add(rulesetsListScroll, cc.rc(1, 1)); newRulesetButton = new JButton(new NewRulesetAction()); deleteRulesetButton = new JButton(new DeleteRulesetAction(this)); rulesetListButtons = new ButtonStackBuilder(); rulesetListButtons.addGridded(newRulesetButton); rulesetListButtons.addRelatedGap(); rulesetListButtons.addGridded(deleteRulesetButton); leftBuilder.add(rulesetListButtons.getPanel(), cc.rc(1, 3)); rightContainer = new JPanel(); rightContainer.setBorder(BorderFactory.createTitledBorder(_("ManageRulesets.Ruleset"))); containerBuilder.add(rightContainer, cc.rc(1, 3)); rulesetTitle = new JTextField(); rulesetTitleListener = new RulesetTitleDocumentListener(); rulesetTitle.getDocument().addDocumentListener(rulesetTitleListener); defaultRulesetTitleBorder = rulesetTitle.getBorder(); ruleSelection = new RuleSelectionListener(); existingRules = new DefaultListModel(); existingRulesList = new JList(existingRules); existingRulesList.setVisibleRowCount(listsNumRows); existingRulesList.setMinimumSize(new Dimension(120, 20)); existingRulesList.addListSelectionListener(ruleSelection); existingRulesListScroll = new JScrollPane(existingRulesList); existingRulesListScroll.setMinimumSize(new Dimension(160, 20)); existingRulesListScroll.setPreferredSize(new Dimension(160, 20)); usedRules = new RulesetTableModel(); usedRulesTable = new JTable(usedRules); usedRulesTable.setAutoResizeMode(JTable.AUTO_RESIZE_LAST_COLUMN); usedRulesTable.getSelectionModel().addListSelectionListener(ruleSelection); usedRulesTableScroll = new JScrollPane(usedRulesTable); usedRulesTableScroll.setPreferredSize(new Dimension(300, 200)); ascendingChooser = new JComboBox(); ascendingChooser.addItem(_("ManageRulesets.UsedRules.Ascending.True")); ascendingChooser.addItem(_("ManageRulesets.UsedRules.Ascending.False")); usedRulesTable.getColumnModel().getColumn(0).setPreferredWidth(150); usedRulesTable.getColumnModel().getColumn(1).setCellEditor(new DefaultCellEditor(ascendingChooser)); usedRulesTable.getColumnModel().getColumn(1).getCellEditor() .addCellEditorListener(new CellEditorListener() { @Override public void editingStopped(ChangeEvent e) { rulesetChanged(); } @Override public void editingCanceled(ChangeEvent e) { // do nothing } }); usedRulesTable.getColumnModel().getColumn(1).setPreferredWidth(170); usedRulesTable.setRowHeight(ascendingChooser.getPreferredSize().height); usedRulesTable.getTableHeader().setReorderingAllowed(false); addRuleButton = new JButton(new AddRuleAction()); removeRuleButton = new JButton(new RemoveRuleAction()); ruleAddRemoveButtons = new ButtonStackBuilder(); ruleAddRemoveButtons.addButton(addRuleButton, removeRuleButton); ruleUpButton = new JButton(new RuleUpAction()); ruleDownButton = new JButton(new RuleDownAction()); ruleUpDownButtons = new ButtonStackBuilder(); ruleUpDownButtons.addButton(ruleUpButton, ruleDownButton); infoLabel = new JEditorPane(); infoLabel.setContentType("text/html"); infoLabel.setText(_("ManageRulesets.HelpNoSelection")); infoLabel.setEditable(false); infoLabel.setBackground(rightContainer.getBackground()); infoLabel.setPreferredSize(new Dimension(30, 40)); infoLabel.setMaximumSize(new Dimension(30, 40)); infoLabel.addHyperlinkListener(new HyperlinkListener() { @Override public void hyperlinkUpdate(HyperlinkEvent e) { // if clicked, open url in browser if (e.getEventType() == EventType.ACTIVATED) { UrlOpener.browse(e.getURL()); } } }); saveButton = new JButton(new SaveAction()); saveButton.setEnabled(false); rightLayout = new FormLayout("p, 2dlu, l:m, d, p:g, d, f:m", // 7 colums "t:p, 2dlu, p, d, f:p:g, d, p, d, f:p"); // 9 rows rightLayout.setColumnGroups(new int[][] { /* { 1, 5 }, */{ 2, 4, 6 } }); rightLayout.setRowGroups(new int[][] { { 2, 4, 6, 8 } }); rightBuilder = new PanelBuilder(rightLayout, rightContainer); rightBuilder.addLabel(_("ManageRulesets.RulesetLabel"), cc.rc(1, 1)); rightBuilder.add(rulesetTitle, cc.rcw(1, 3, 5)); rightBuilder.addLabel(_("ManageRulesets.ExistingRules"), cc.rc(3, 1)); rightBuilder.add(existingRulesListScroll, cc.rc(5, 1)); rightBuilder.add(ruleAddRemoveButtons.getPanel(), cc.rc(5, 3)); rightBuilder.addLabel(_("ManageRulesets.UsedRules"), cc.rc(3, 5)); rightBuilder.add(usedRulesTableScroll, cc.rc(5, 5)); rightBuilder.add(ruleUpDownButtons.getPanel(), cc.rc(5, 7)); rightBuilder.add(saveButton, cc.rchw(7, 7, 3, 1)); rightBuilder.addLabel(_("ManageRulesets.Help"), cc.rc(7, 1)); rightBuilder.add(infoLabel, cc.rcw(9, 1, 5)); okButton = StandardButtonFactory.createCloseButton(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { confirmIfUnsavedChanges(); dispose(); } }); getRootPane().setDefaultButton(okButton); containerBuilder.add(ButtonBarFactory.buildOKBar(okButton), cc.rcw(2, 1, 3)); setRulesetEditingEnable(false, false); }