/** * Computes and returns the layout's grid origins. * * @param container the layout container to inspect * @return an object that comprises the cell origins and extents * @throws IllegalArgumentException if the layout is not FormLayout */ public static FormLayout.LayoutInfo getLayoutInfo(Container container) { if (!(container.getLayout() instanceof FormLayout)) { throw new IllegalArgumentException("The container must use an instance of FormLayout."); } FormLayout layout = (FormLayout) container.getLayout(); return layout.getLayoutInfo(container); }
private void layoutMainPanel() { FormLayout layout = new FormLayout( "right:d, $lcgap, 50dlu:g, 8dlu, right:d, $lcgap, max(65dlu;min)", "f:d, $nlgap, f:d, $nlgap, f:d"); layout.setRowGroups(new int[][] {{1, 3, 5}}); CellConstraints cc = new CellConstraints(); setLayout(layout); /* Create a sub panel to work around a column spanning problem in FormLayout */ JPanel subPanel = buildHorizontalSubPanel( "max(48dlu;min):g(0.5), 8dlu, d, $lcgap, max(48dlu;min):g(0.5)", ValidationFactory.wrap(priceField), "Label.Quantity", ValidationFactory.wrap(quantityField)); add("Label.Security", cc.xy(1, 1)); add(ValidationFactory.wrap(securityCombo), cc.xy(3, 1)); add("Label.Date", cc.xy(5, 1)); add(datePanel, cc.xy(7, 1)); add("Label.Price", cc.xy(1, 3)); add(subPanel, cc.xy(3, 3)); add("Label.Total", cc.xy(5, 3)); add(totalField, cc.xy(7, 3)); add("Label.Memo", cc.xy(1, 5)); add(memoField, cc.xy(3, 5)); add(getReconcileCheckBox(), cc.xyw(5, 5, 3)); }
private void jbInit() throws Exception { setOpaque(false); jpnlContent.setOpaque(false); FormLayout formLayout = new FormLayout( "5px, left:pref, 4dlu, 150dlu:grow, 5px", "5px, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5px"); jpnlContent.setLayout(formLayout); formLayout.setRowGroups(new int[][] {{2, 4, 6, 8, 10, 12}}); CellConstraints cc = new CellConstraints(); jpnlContent.add(jlblHostName, cc.xy(2, 2)); jpnlContent.add(jtfldHostName, cc.xy(4, 2)); jpnlContent.add(jlblUserName, cc.xy(2, 4)); jpnlContent.add(jtfldUserName, cc.xy(4, 4)); jpnlContent.add(jlblUserPass, cc.xy(2, 6)); jpnlContent.add(jtfldUserPass, cc.xy(4, 6)); jpnlContent.add(jlblFromEmail, cc.xy(2, 8)); jpnlContent.add(jtfldFromEmail, cc.xy(4, 8)); jpnlContent.add(jlblFromName, cc.xy(2, 10)); jpnlContent.add(jtfldFromName, cc.xy(4, 10)); jpnlContent.add(jchkbDebug, cc.xy(2, 12)); JPanel jpnlDummy = new JPanel(new BorderLayout()); jpnlDummy.add(jpnlContent, BorderLayout.NORTH); add(jpnlContent, BorderLayout.CENTER); }
/** * Builds the Music information panel. * * <p> * * @return the panel to display the music info */ private JComponent buildMusicPanel() { FormLayout layout = new FormLayout( "right:max(14dlu;pref), 4dlu, left:min(80dlu;pref), 100px, right:max(14dlu;pref),pref:grow, 4px", "p, 4px, p, 4px, p, 4px, p, 4px, p, 4px"); layout.setRowGroups(new int[][] {{1, 3}}); PanelBuilder builder = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); builder.addLabel(Resources.getString("label.file") + ": ", cc.xy(1, 1)); builder.add(location, cc.xyw(3, 1, 5)); builder.addLabel(Resources.getString("label.duration") + ": ", cc.xy(1, 3)); builder.add(duration, cc.xy(3, 3)); builder.addLabel(Resources.getString("label.layer") + ": ", cc.xy(5, 3)); builder.add(layer, cc.xy(6, 3)); builder.addLabel(Resources.getString("label.bitrate") + ": ", cc.xy(1, 5)); builder.add(bitRate, cc.xyw(3, 5, 4)); builder.addLabel(Resources.getString("label.version") + ": ", cc.xy(5, 5)); builder.add(version, cc.xy(6, 5)); builder.addLabel(Resources.getString("label.frequency") + ": ", cc.xy(1, 7)); builder.add(frequency, cc.xy(3, 7)); builder.addLabel(Resources.getString("label.mode") + ": ", cc.xy(5, 7)); builder.add(mode, cc.xy(6, 7)); builder.addLabel(Resources.getString("label.filesize") + ": ", cc.xy(1, 9)); builder.add(fileSize, cc.xy(3, 9)); builder.addLabel(Resources.getString("label.copyright") + ": ", cc.xy(5, 9)); builder.add(copyrighted, cc.xy(6, 9)); return builder.getPanel(); }
/** * Dumps the component constraints to the console. * * @param container the layout container to inspect */ public static void dumpConstraints(Container container) { System.out.println("COMPONENT CONSTRAINTS"); if (!(container.getLayout() instanceof FormLayout)) { System.out.println("The container's layout is not a FormLayout."); return; } FormLayout layout = (FormLayout) container.getLayout(); int childCount = container.getComponentCount(); for (int i = 0; i < childCount; i++) { Component child = container.getComponent(i); CellConstraints cc = layout.getConstraints(child); String ccString = cc == null ? "no constraints" : cc.toShortString(layout); System.out.print(ccString); System.out.print("; "); String childType = child.getClass().getName(); System.out.print(childType); if (child instanceof JLabel) { JLabel label = (JLabel) child; System.out.print(" \"" + label.getText() + "\""); } if (child.getName() != null) { System.out.print("; name="); System.out.print(child.getName()); } System.out.println(); } System.out.println(); }
private JPanel buildMiscPanel() { FormLayout layout = new FormLayout( "right:max(50dlu;pref), 3dlu, 50dlu, 3dlu, 50dlu", "p, 3dlu, p, 3dlu, p, 3dlu, p"); layout.setRowGroups(new int[][] {{1, 3, 5}}); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); Action chooseAction = new ChooseColorAction( builder.getPanel(), presentationModel.getModel(ExampleBean.PROPERTYNAME_COLOR)); CellConstraints cc = new CellConstraints(); builder.addLabel("JCheckBox", cc.xy(1, 1)); builder.add(checkBox, cc.xy(3, 1)); builder.addLabel("JSlider", cc.xy(1, 3)); builder.add(slider, cc.xy(3, 3)); builder.add(floatLabel, cc.xy(5, 3)); builder.addLabel("JSpinner", cc.xy(1, 5)); builder.add(spinner, cc.xy(3, 5)); builder.addLabel("JColorChooser", cc.xy(1, 7)); builder.add(colorPreview, cc.xy(3, 7, "fill, fill")); builder.add(new JButton(chooseAction), cc.xy(5, 7, "left, center")); return builder.getPanel(); }
private void prepareComponent() { CloseEventHandler closeEventHandler = new CloseEventHandler(); addWindowListener(closeEventHandler); Container contentPane = getContentPane(); contentPane.setLayout(new BorderLayout()); JPanel contentPanel = new JPanel(); // JPanel contentPanel = new FormDebugPanel(); contentPane.add(contentPanel, BorderLayout.CENTER); CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout( "4dlu, d:grow, 4dlu", // columns "4dlu, p, 2dlu, fill:100dlu:grow, 4dlu, " + // rows "p, 2dlu, p, 4dlu"); // btn rows PanelBuilder contentPB = new PanelBuilder(layout, contentPanel); int columnCount = layout.getColumnCount(); int rowCount = layout.getRowCount(); JLabel label = new JLabel(Localizer.getString("MediaTypeCondEditor_ConditionToAdd")); contentPB.add(label, cc.xywh(2, 2, 1, 1)); mediaTypeModel = new MediaTypeModel(); mediaTypeTable = new JTable(mediaTypeModel); JTableHeader tableHeader = mediaTypeTable.getTableHeader(); tableHeader.setResizingAllowed(false); tableHeader.setReorderingAllowed(false); // adjust column witdh of checkbox JCheckBox box = (JCheckBox) mediaTypeTable.getDefaultRenderer(Boolean.class); TableColumn column = mediaTypeTable.getColumnModel().getColumn(0); column.setMaxWidth(box.getPreferredSize().width + 2); column.setMinWidth(box.getPreferredSize().width + 2); mediaTypeTable.getColumnModel().getColumn(1).setCellRenderer(new MediaTypeCellRenderer()); // ToolTipManager.sharedInstance().registerComponent( mediaTypeTable ); contentPB.add(new JScrollPane(mediaTypeTable), cc.xywh(2, 4, 1, 1)); // button bar contentPB.add(new JSeparator(), cc.xywh(1, rowCount - 3, columnCount, 1)); JButton okBtn = new JButton(Localizer.getString("OK")); okBtn.addActionListener(new OkBtnListener()); okBtn.setDefaultCapable(true); okBtn.setRequestFocusEnabled(true); JButton cancelBtn = new JButton(Localizer.getString("Cancel")); cancelBtn.addActionListener(closeEventHandler); JPanel btnPanel = ButtonBarFactory.buildOKCancelBar(okBtn, cancelBtn); contentPB.add(btnPanel, cc.xywh(2, rowCount - 1, columnCount - 2, 1)); setDefaultCloseOperation(JDialog.DISPOSE_ON_CLOSE); getRootPane().setDefaultButton(okBtn); pack(); setLocationRelativeTo(getParent()); }
public void buildForm(ODatabaseDocumentTx db) { FormLayout layout = new FormLayout( "l:p, 4dlu, f:max(60dlu;p):g(.4), 15dlu," + "l:p, 4dlu, f:max(60dlu;p):g(.4), 15dlu, " + "l:p, 4dlu, f:max(88dlu;p):g(.2), 4dlu, f:max(88dlu;p):g(.2), 15dlu", "p,3dlu, " + // nota " p,3dlu, " + // cust "f:25dlu:g,3dlu, " + // jml "f:25dlu:g,3dlu, " + // total "p,3dlu, " + // diskon "f:25dlu:g,3dlu, " + // total "p,3dlu, " + "p,3dlu, " + "f:25dlu:g,3dlu, " + "p,3dlu, " + // "p,3dlu, " + // " p,3dlu, " + // "p,3dlu, " + "p,3dlu"); layout.setColumnGroups(new int[][] {{1, 5, 9}, {3, 7}}); FormBuilder builder = new FormBuilder(layout, true); builder.append(db, PenjualanDao.fcode, code, 1, 1, 1); builder.append(db, PenjualanDao.ftgl, tgl, 5, 1, 1); builder.append(db, PenjualanDao.fpelanggan, pelanggan, 1, 3, 5); builder.append(db, f2, PenjualanDao.fjml, jml, 1, 5, 1); builder.append(db, f2, PenjualanDao.fharga, harga, 5, 5, 1); builder.append(db, f2, PenjualanDao.ftotal1, total1, 1, 7, 5); builder.append(db, PenjualanDao.fdiskon, diskon, 1, 9, 1); builder.append(db, PenjualanDao.fdiskonp, diskonp, 5, 9, 1); builder.append(db, f2, PenjualanDao.ftotal, total, 1, 11, 5); builder.append(db, f2, PenjualanDao.fbayar, bayar, 9, 1, 3, 3); builder.append(db, f2, PenjualanDao.fhutang, k, 9, 5, 3); builder.append(db, f2, PenjualanDao.fkembali, kembali, 9, 7, 3); builder.append(save, 11, 11); builder.append(reset, 13, 11); JPanel p = builder.getPanel(); p.setBackground(Color.WHITE); JScrollPane pane = new JScrollPane(p); JLabel label = new JLabel(App.getIcon(db, "icon edit 16")); label.setText(App.getT(db, " Input Data Penjualan")); label.setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5)); panel.add(pane, BorderLayout.CENTER); panel.add(label, BorderLayout.NORTH); aksiReset(); }
/** * Dumps the layout's column specifications to the console. * * @param layout the <code>FormLayout</code> to inspect */ public static void dumpColumnSpecs(FormLayout layout) { System.out.print("COLUMN SPECS:"); for (int col = 1; col <= layout.getColumnCount(); col++) { ColumnSpec colSpec = layout.getColumnSpec(col); System.out.print(colSpec.toShortString()); if (col < layout.getColumnCount()) System.out.print(", "); } System.out.println(); }
/** * Dumps the layout's row specifications to the console. * * @param layout the <code>FormLayout</code> to inspect */ public static void dumpRowSpecs(FormLayout layout) { System.out.print("ROW SPECS: "); for (int row = 1; row <= layout.getRowCount(); row++) { RowSpec rowSpec = layout.getRowSpec(row); System.out.print(rowSpec.toShortString()); if (row < layout.getRowCount()) System.out.print(", "); } System.out.println(); }
public XFormField addComponent(XFormField component) { if (rowSpacing > 0 && !components.isEmpty()) addSpace(rowSpacing); layout.appendRow(rowSpec); int row = layout.getRowCount(); AbstractSwingXFormField<?> swingFormComponent = (AbstractSwingXFormField<?>) component; panel.add(swingFormComponent.getComponent(), cc.xyw(1, row, 4)); return component; }
/** Add a new row to the current tab. */ private void addColumn() { JPanel selected = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) selected.getLayout(); layout.appendColumn(new ColumnSpec("pref:grow")); int ndx = tabPane.getSelectedIndex(); for (int i = 0; i < layout.getRowCount(); i++) { addIcon(selected, i, layout.getColumnCount() - 1, ndx); } tabPane.repaint(); }
public void addSeparator(String label) { addSpace(rowSpacing); addSpace(rowSpacing); layout.appendRow(rowSpec); int row = layout.getRowCount(); if (StringUtils.isNullOrEmpty(label)) panel.add(new JSeparator(), cc.xywh(2, row, 3, 1)); else panel.add(new JLabel(label), cc.xywh(2, row, 3, 1)); addSpace(rowSpacing); }
/** * Creates a FormLayout instance. * * <p><b>Attributes:</b> * * <ul> * <li><code>columns</code> (required): The column specifications as documented in JGoodies * FormLayout. * <li><code>row</code> (required): The row specifications as documented in JGoodies FormLayout. * <li><code>columnGroups</code> (optional): The column groups, where each column in a group * gets the same group wide width. Groups are separated by semicolons, column indices in a * group are separated by colons. E.g. "1,5; 3,7,9" defines two groups, where first group * contains columns 1 and 5; and second group contains columns 3, 7 and 9. Note that column * indices are 1-based. * <li><code>rowGroups</code> (optional): The row groups, where each row in a group gets the * same group wide height. Groups are separated by semicolons, row indices in a group are * separated by colons. E.g. "1,5; 3,7,9" defines two groups, where first group contains * rows 1 and 5; and second group contains rows 3, 7 and 9. Note that row indices are * 1-based. * </ul> * * <p><b>Examples for Valid XML element notations:</b> * * <ul> * <li><code><layout type="FormLayout" columns="p, 3dlu, p" rows="p, 3dlu, p"/></code> * <li><code> * <layout type="FormLayout" columns="p, 3dlu, p, 3dlu, p, 3dlu, p" rows="p, 3dlu, p" * columnGroups="1,5; 3,7" rowGroups="1,3"/></code> * </ul> */ public LayoutManager convertLayoutElement(final Element element) { String encodedColumnSpecs = element.getAttributeNode("columns") != null ? element.getAttribute("columns") : null; String encodedRowSpecs = element.getAttributeNode("rows") != null ? element.getAttribute("rows") : null; int[][] columnGroupIndices = convertGroupIndices(element.getAttributeNode("columnGroups")); int[][] rowGroupIndices = convertGroupIndices(element.getAttributeNode("rowGroups")); FormLayout lm = new FormLayout(encodedColumnSpecs, encodedRowSpecs); if (columnGroupIndices != null) lm.setColumnGroups(columnGroupIndices); if (rowGroupIndices != null) lm.setRowGroups(rowGroupIndices); return lm; }
private JPanel buildTextPanel() { FormLayout layout = new FormLayout("right:max(50dlu;pref), 3dlu, 50dlu", "p, 3dlu, p, 3dlu, p, 14dlu, 3dlu, p"); layout.setRowGroups(new int[][] {{1, 3, 5}}); PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); CellConstraints cc = new CellConstraints(); builder.addLabel("JTextField", cc.xy(1, 1)); builder.add(textField, cc.xy(3, 1)); builder.addLabel("JPasswordField", cc.xy(1, 3)); builder.add(passwordField, cc.xy(3, 3)); builder.addLabel("JTextArea", cc.xy(1, 5)); builder.add(new JScrollPane(textArea), cc.xywh(3, 5, 1, 2)); builder.addLabel("JLabel", cc.xy(1, 8)); builder.add(textLabel, cc.xy(3, 8)); return builder.getPanel(); }
private void buildPanel() { initComponents(); FormLayout layout = new FormLayout("max(20dlu;d), 4dlu, 75dlu:grow(1.0)", "f:d, 3dlu, f:d, 10dlu, f:d"); CellConstraints cc = new CellConstraints(); layout.setRowGroups(new int[][] {{1, 3, 5}}); JPanel p = new JPanel(layout); p.setBorder(Borders.DIALOG); p.add(new JLabel(rb.getString("Label.Date")), cc.xy(1, 1)); p.add(datePanel, cc.xy(3, 1)); p.add(new JLabel(rb.getString("Label.Number")), cc.xy(1, 3)); p.add(numberCombo, cc.xy(3, 3)); p.add(StaticUIMethods.buildOKCancelBar(okButton, cancelButton), cc.xyw(1, 5, 3)); getContentPane().add(p, BorderLayout.CENTER); }
/* * If label starts with '###' do not show them. (non-Javadoc) if label ends * with '___' (3) right border is 30 and no ':' at the end * * @see com.eviware.x.form.XForm#addComponent(java.lang.String, * com.eviware.x.form.XFormField) */ public XFormField addComponent(String label, XFormField formComponent) { if (rowSpacing > 0 && !components.isEmpty()) addSpace(rowSpacing); components.put(label, formComponent); layout.appendRow(rowSpec); int row = layout.getRowCount(); AbstractSwingXFormField<?> swingFormComponent = (AbstractSwingXFormField<?>) formComponent; if (label != null && !label.startsWith("###")) { JLabel jlabel = null; if (label.endsWith("___")) { jlabel = new JLabel(label.substring(0, label.length() - 3)); jlabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 30)); } else { jlabel = new JLabel(label.endsWith(":") ? label : label + ":"); jlabel.setBorder(BorderFactory.createEmptyBorder(2, 0, 0, 0)); } panel.add(jlabel, cc.xy(2, row)); jlabel.setLabelFor(swingFormComponent.getComponent()); int ix = label.indexOf('&'); if (ix >= 0) { jlabel.setText(label.substring(0, ix) + label.substring(ix + 1)); jlabel.setDisplayedMnemonicIndex(ix); jlabel.setDisplayedMnemonic(label.charAt(ix + 1)); } swingFormComponent.getComponent().getAccessibleContext().setAccessibleDescription(label); } if (label != null && label.startsWith("###")) panel.add(swingFormComponent.getComponent(), cc.xyw(2, row, 4)); else panel.add(swingFormComponent.getComponent(), cc.xy(4, row)); components.put(label, formComponent); return formComponent; }
public void buildForm() { initComponent(); StringBuilder col = new StringBuilder(); StringBuilder row = new StringBuilder(); col.append("10px,"); col.append("r:p,10px,f:200px:g,"); col.append("20px,"); col.append("r:p,10px,f:200px:g,"); col.append("10px,"); row.append("15dlu,"); row.append("p,3dlu,"); row.append("p,3dlu,"); row.append("p,3dlu,"); row.append("p,3dlu,"); row.append("p,3dlu,"); row.append("p,3dlu,"); row.append("p,15dlu,"); FormLayout l = new FormLayout(col.toString(), row.toString()); l.setColumnGroups(new int[][] {{4, 8}}); FormBuilder b = new FormBuilder(l); // append(String i8n, Component c, int x, int y, int w) b.append(LPegawai.CODE, code, 2, 2, 1); b.append(LPegawai.STATUS, status, 2, 14, 1); b.append(LPegawai.NAMA, nama, 2, 4, 1); b.append(LPegawai.USERNAME, username, 2, 6, 1); b.append(LPegawai.PASSWORD, password, 2, 8, 1); b.append(LPegawai.ULANG_PASSWORD, ulang, 2, 10, 1); b.append(LPegawai.JENIS_IDENTITAS, jenisIdentitas, 6, 2, 1); b.append(LPegawai.NO_IDENTITAS, noIdentitas, 6, 4, 1); b.append(LPegawai.ALAMAT, salamat, 6, 6, 1, 5); b.append(LPegawai.KOTA, kota, 6, 12, 1); b.append(LPegawai.HP, hp, 6, 14, 1); b.append(LPegawai.HAK_AKSES, hakAkses, 2, 12, 1); panelForm = b.getPanel(); }
private void initialise(GoodiesForm goodiesForm) { System.out.println("GoodiesBlit running..."); // 1. Create the layout FormLayout layout = new FormLayout( "right:pref, 3dlu, pref:grow, 7dlu, right:pref, 3dlu, pref:grow", // 7 columns "p, 3dlu, p, 3dlu, p, 9dlu, p, 3dlu, p, 3dlu, p, 9dlu, p"); // 13 rows // 2. Specify column and row groups layout.setColumnGroups(new int[][] {{1, 5}, {3, 7}}); // 3. Create and configure builder PanelBuilder builder = new PanelBuilder(layout); builder.setDefaultDialogBorder(); // 4. Add components CellConstraints cc = new CellConstraints(); builder.addSeparator("General", cc.xyw(1, 1, 7)); builder.addLabel("Company", cc.xy(1, 3)); builder.add(new JTextField(), cc.xyw(3, 3, 5)); builder.addLabel("Contact", cc.xy(1, 5)); builder.add(new JTextField(), cc.xyw(3, 5, 5)); builder.addSeparator("Propeller", cc.xyw(1, 7, 7)); builder.addLabel("PTI [kW]", cc.xy(1, 9)); builder.add(new JTextField(), cc.xy(3, 9)); builder.addLabel("Power [kW]", cc.xy(5, 9)); builder.add(new JTextField(), cc.xy(7, 9)); builder.addLabel("R [mm]", cc.xy(1, 11)); builder.add(new JTextField(), cc.xy(3, 11)); builder.addLabel("D [mm]", cc.xy(5, 11)); builder.add(new JTextField(), cc.xy(7, 11)); builder.add( ButtonBarFactory.buildCenteredBar(new JButton("Ignite"), new JButton("Explode")), cc.xyw(1, 13, builder.getColumnCount())); JPanel goodiesPanel = builder.getPanel(); goodiesPanel.setPreferredSize(new Dimension(400, 250)); goodiesForm.getContentPane().add(goodiesPanel); }
private void layoutMainPanel() { FormLayout layout = new FormLayout( "right:d, $lcgap, 50dlu:g, 8dlu, right:d, $lcgap, max(48dlu;min)", "f:d, $nlgap, f:d, $nlgap, f:d, $nlgap, f:d"); layout.setRowGroups(new int[][] {{1, 3, 5, 7}}); CellConstraints cc = new CellConstraints(); setLayout(layout); setBorder(Borders.DIALOG_BORDER); add("Label.TransferTo", cc.xy(1, 1)); add(accountPanel, cc.xy(3, 1)); add("Label.Date", cc.xy(5, 1)); add(datePanel, cc.xy(7, 1)); add("Label.Memo", cc.xy(1, 3)); add(memoField, cc.xy(3, 3)); add("Label.Amount", cc.xy(5, 3)); add(ValidationFactory.wrap(amountField), cc.xy(7, 3)); add(createBottomPanel(), cc.xyw(1, 7, 7)); }
/** Main function for building the merge entry JPanel */ private void initialize() { joint = new TreeSet<>(one.getFieldNames()); joint.addAll(two.getFieldNames()); // Remove field starting with __ TreeSet<String> toberemoved = new TreeSet<>(); for (String field : joint) { if (field.startsWith("__")) { toberemoved.add(field); } } for (String field : toberemoved) { joint.remove(field); } // Create storage arrays rb = new JRadioButton[3][joint.size() + 1]; ButtonGroup[] rbg = new ButtonGroup[joint.size() + 1]; identical = new Boolean[joint.size() + 1]; jointStrings = new String[joint.size()]; // Create main layout String colSpecMain = "left:pref, 5px, center:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, center:3cm:grow"; String colSpecMerge = "left:pref, 5px, fill:3cm:grow, 5px, center:pref, 3px, center:pref, 3px, center:pref, 5px, fill:3cm:grow"; String rowSpec = "pref, pref, 10px, fill:5cm:grow, 10px, pref, 10px, fill:3cm:grow"; StringBuilder rowBuilder = new StringBuilder(""); for (int i = 0; i < joint.size(); i++) { rowBuilder.append("pref, "); } rowBuilder.append("pref"); FormLayout mainLayout = new FormLayout(colSpecMain, rowSpec); FormLayout mergeLayout = new FormLayout(colSpecMerge, rowBuilder.toString()); mainPanel.setLayout(mainLayout); mergePanel.setLayout(mergeLayout); JLabel label = new JLabel(Localization.lang("Use")); Font font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); mainPanel.add(label, cc.xyw(4, 1, 7, "center, bottom")); // Set headings JLabel headingLabels[] = new JLabel[6]; for (int i = 0; i < 6; i++) { headingLabels[i] = new JLabel(columnHeadings[i]); font = headingLabels[i].getFont(); headingLabels[i].setFont(font.deriveFont(font.getStyle() | Font.BOLD)); mainPanel.add(headingLabels[i], cc.xy(1 + (i * 2), 2)); } mainPanel.add(new JSeparator(), cc.xyw(1, 3, 11)); // Start with entry type EntryType type1 = one.getType(); EntryType type2 = two.getType(); mergedEntry.setType(type1); label = new JLabel(Localization.lang("Entry type")); font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); mergePanel.add(label, cc.xy(1, 1)); JTextArea type1ta = new JTextArea(type1.getName()); type1ta.setEditable(false); mergePanel.add(type1ta, cc.xy(3, 1)); if (type1.compareTo(type2) != 0) { identical[0] = false; rbg[0] = new ButtonGroup(); for (int k = 0; k < 3; k += 2) { rb[k][0] = new JRadioButton(); rbg[0].add(rb[k][0]); mergePanel.add(rb[k][0], cc.xy(5 + (k * 2), 1)); rb[k][0].addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateAll(); } }); } rb[0][0].setSelected(true); } else { identical[0] = true; } JTextArea type2ta = new JTextArea(type2.getName()); type2ta.setEditable(false); mergePanel.add(type2ta, cc.xy(11, 1)); // For all fields in joint add a row and possibly radio buttons int row = 2; int maxLabelWidth = -1; int tmpLabelWidth = 0; for (String field : joint) { jointStrings[row - 2] = field; label = new JLabel(CaseChangers.UPPER_FIRST.format(field)); font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); mergePanel.add(label, cc.xy(1, row)); String string1 = one.getField(field); String string2 = two.getField(field); identical[row - 1] = false; if ((string1 != null) && (string2 != null)) { if (string1.equals(string2)) { identical[row - 1] = true; } } tmpLabelWidth = label.getPreferredSize().width; if (tmpLabelWidth > maxLabelWidth) { maxLabelWidth = tmpLabelWidth; } if ("abstract".equals(field) || "review".equals(field)) { // Treat the abstract and review fields special JTextArea tf = new JTextArea(); tf.setLineWrap(true); tf.setEditable(false); JScrollPane jsptf = new JScrollPane(tf); mergeLayout.setRowSpec(row, RowSpec.decode("center:2cm:grow")); mergePanel.add(jsptf, cc.xy(3, row, "f, f")); tf.setText(string1); tf.setCaretPosition(0); } else { JTextArea tf = new JTextArea(string1); mergePanel.add(tf, cc.xy(3, row)); tf.setCaretPosition(0); tf.setEditable(false); } // Add radio buttons if the two entries do not have identical fields if (!identical[row - 1]) { rbg[row - 1] = new ButtonGroup(); for (int k = 0; k < 3; k++) { rb[k][row - 1] = new JRadioButton(); rbg[row - 1].add(rb[k][row - 1]); mergePanel.add(rb[k][row - 1], cc.xy(5 + (k * 2), row)); rb[k][row - 1].addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateAll(); } }); } if (string1 != null) { mergedEntry.setField(field, string1); rb[0][row - 1].setSelected(true); if (string2 == null) { rb[2][row - 1].setEnabled(false); } } else { rb[0][row - 1].setEnabled(false); mergedEntry.setField(field, string2); rb[2][row - 1].setSelected(true); } } else { mergedEntry.setField(field, string1); } if ("abstract".equals(field) || "review".equals(field)) { // Again, treat abstract and review special JTextArea tf = new JTextArea(); tf.setLineWrap(true); tf.setEditable(false); JScrollPane jsptf = new JScrollPane(tf); mergePanel.add(jsptf, cc.xy(11, row, "f, f")); tf.setText(string2); tf.setCaretPosition(0); } else { JTextArea tf = new JTextArea(string2); mergePanel.add(tf, cc.xy(11, row)); tf.setCaretPosition(0); tf.setEditable(false); } row++; } JScrollPane scrollPane = new JScrollPane( mergePanel, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); scrollPane.setBorder(BorderFactory.createEmptyBorder()); mainPanel.add(scrollPane, cc.xyw(1, 4, 11)); mainPanel.add(new JSeparator(), cc.xyw(1, 5, 11)); // Synchronize column widths String rbAlign[] = {"right", "center", "left"}; mainLayout.setColumnSpec(1, ColumnSpec.decode(Integer.toString(maxLabelWidth) + "px")); Integer maxRBWidth = -1; Integer tmpRBWidth; for (int k = 0; k < 3; k++) { tmpRBWidth = headingLabels[k + 2].getPreferredSize().width; if (tmpRBWidth > maxRBWidth) { maxRBWidth = tmpRBWidth; } } for (int k = 0; k < 3; k++) { mergeLayout.setColumnSpec( 5 + (k * 2), ColumnSpec.decode(rbAlign[k] + ":" + maxRBWidth + "px")); } // Setup a PreviewPanel and a Bibtex source box for the merged entry label = new JLabel(Localization.lang("Merged entry")); font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); mainPanel.add(label, cc.xyw(1, 6, 6)); String layoutString = Globals.prefs.get(JabRefPreferences.PREVIEW_0); pp = new PreviewPanel(null, mergedEntry, null, new MetaData(), layoutString); // JScrollPane jsppp = new JScrollPane(pp, JScrollPane.VERTICAL_SCROLLBAR_AS_NEEDED, // JScrollPane.HORIZONTAL_SCROLLBAR_NEVER); mainPanel.add(pp, cc.xyw(1, 8, 6)); label = new JLabel(Localization.lang("Merged BibTeX source code")); font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); mainPanel.add(label, cc.xyw(8, 6, 4)); jta = new JTextArea(); jta.setLineWrap(true); JScrollPane jspta = new JScrollPane(jta); mainPanel.add(jspta, cc.xyw(8, 8, 4)); jta.setEditable(false); StringWriter sw = new StringWriter(); try { new BibtexEntryWriter(new LatexFieldFormatter(), false).write(mergedEntry, sw); } catch (IOException ex) { LOGGER.error("Error in entry" + ": " + ex.getMessage(), ex); } jta.setText(sw.getBuffer().toString()); jta.setCaretPosition(0); // Add some margin around the layout mainLayout.appendRow(RowSpec.decode("10px")); mainLayout.appendColumn(ColumnSpec.decode("10px")); mainLayout.insertRow(1, RowSpec.decode("10px")); mainLayout.insertColumn(1, ColumnSpec.decode("10px")); if (mainPanel.getHeight() > DIM.height) { mainPanel.setSize(new Dimension(mergePanel.getWidth(), DIM.height)); } if (mainPanel.getWidth() > DIM.width) { mainPanel.setSize(new Dimension(DIM.width, mergePanel.getHeight())); } // Everything done, allow any action to actually update the merged entry doneBuilding = true; // Show what we've got mainPanel.setVisible(true); javax.swing.SwingUtilities.invokeLater( new Runnable() { @Override public void run() { scrollPane.getVerticalScrollBar().setValue(0); } }); }
/** build graphically the appearance of resolve symbols manager */ public void buildAndShow(String text) { if (this.importManager == null) return; List<String> unresolvedSymbols = this.importManager.getParser().getUnresolvedSymbols(text); this.addWindowListener( new WindowAdapter() { public void windowClosed(WindowEvent e) { ImportManagerUI.this.hasCanceled = true; } }); FormLayout lay = new FormLayout("pref, fill:pref:grow", ""); JPanel panel = new JPanel(lay); CellConstraints cc = new CellConstraints(); if (unresolvedSymbols == null) return; JComboBox currentCombo = null; if (this.importManager.getServiceProvider() != null) { String currentSymbol = null; int index = 1; for (Iterator<String> symbols = unresolvedSymbols.iterator(); symbols.hasNext(); ) { currentSymbol = symbols.next(); /* build the corresponding list of packages */ List<String> packageList = this.importManager.getServiceProvider().getPackagesNameContainingClass(currentSymbol); if (packageList == null) continue; if (packageList.size() == 0) continue; if (packageList.size() == 1) { this.importManager.addImportPart(currentSymbol, packageList.get(0)); continue; } /* update layout */ lay.appendRow(new RowSpec("pref")); currentCombo = new JComboBox(packageList.toArray()); /** feed Map */ if (this.mappings == null) this.mappings = new HashMap<String, JComboBox>(); this.mappings.put(currentSymbol, currentCombo); panel.add( new JLabel("<html><b><code>" + currentSymbol + "</code></b> </html>"), cc.xy(1, index)); panel.add(currentCombo, cc.xy(2, index, cc.FILL, cc.FILL)); index += 1; } if (index == 1) return; /* add valid and cancel buttons */ JButton valid = new JButton("OK"); valid.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ImportManagerUI.this.setVisible(false); } }); JButton cancel = new JButton("Cancel"); cancel.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { ImportManagerUI.this.setVisible(false); ImportManagerUI.this.hasCanceled = true; } }); JPanel panelValid = new JPanel(new FormLayout("pref, 4px, pref", "pref")); panelValid.add(valid, cc.xy(1, 1)); panelValid.add(cancel, cc.xy(3, 1)); lay.appendRow(new RowSpec("5px")); lay.appendRow(new RowSpec("pref")); panel.add(panelValid, cc.xywh(1, index + 1, 2, 1, cc.RIGHT, cc.DEFAULT)); } this.setContentPane(panel); int x = ((int) Toolkit.getDefaultToolkit().getScreenSize().getWidth()) - this.getWidth(); int y = ((int) Toolkit.getDefaultToolkit().getScreenSize().getHeight()) - this.getHeight(); this.setLocation(x / 2, y / 2); this.pack(); this.setVisible(true); if (!this.hasCanceled()) { /* complete the information of the import manager */ String currentKey = null; for (Iterator<String> keys = this.mappings.keySet().iterator(); keys.hasNext(); ) { currentKey = keys.next(); this.importManager.addImportPart( currentKey, this.mappings.get(currentKey).getSelectedItem().toString()); } } }
public void addSpace(int size) { if (size > 0) layout.appendRow(new RowSpec(size + "px")); }
private void jbInit() throws Exception { jtfldEnterprise.setText(res.getString("enterpriseCell.label.enterprise")); jtfldEnterprise.setField("enterpriseID"); jlbtnEnterprise.setText(res.getString("enterpriseCell.label.enterprise")); jlbtnEnterprise.setUrl("pt.inescporto.siasoft.comun.ejb.session.Enterprise"); jlbtnEnterprise.setTitle(res.getString("enterpriseCell.label.list")); jlbtnEnterprise.setDefaultFill(jtfldEnterprise); jlfldEnterprise.setUrl("pt.inescporto.siasoft.comun.ejb.session.Enterprise"); jlfldEnterprise.setDefaultRefField(jtfldEnterprise); jlblEnterpriseCellID.setText(res.getString("enterpriseCell.label.code")); jtfldEnterpriseCellID.setField("enterpriseCellID"); jtfldEnterpriseCellID.setHolder(jlblEnterpriseCellID); jlblEnterpriseCellDescription.setText(res.getString("enterpriseCell.label.desc")); jtfldEnterpriseCellDescription.setField("enterpriseCellDescription"); jtfldEnterpriseCellDescription.setHolder(jlblEnterpriseCellDescription); jtfldFatherCellID.setText(res.getString("enterpriseCell.label.father")); jtfldFatherCellID.setField("fatherCellID"); jlbtnFatherCellID.setText(res.getString("enterpriseCell.label.father")); jlbtnFatherCellID.setLinkCondition("enterpriseID = '" + jtfldEnterprise.getText() + "'"); jlbtnFatherCellID.setUrl("pt.inescporto.siasoft.go.fun.ejb.session.EnterpriseCell"); jlbtnFatherCellID.setTitle(res.getString("enterpriseCell.label.depList")); jlbtnFatherCellID.setDefaultFill(jtfldFatherCellID); jlfldFatherCellID.setUrl("pt.inescporto.siasoft.go.fun.ejb.session.EnterpriseCell"); jlfldFatherCellID.setRefFieldList(new JTextField[] {jtfldEnterprise, jtfldFatherCellID}); jlblEnterpriseCellObs.setText(res.getString("enterpriseCell.label.obs")); jtfldEnterpriseCellObs.setField("enterpriseCellObs"); jtfldEnterpriseCellObs.setHolder(jlblEnterpriseCellObs); jtfldEnterpriseCellObs.setWrapStyleWord(true); jtfldEnterpriseCellObs.setLineWrap(true); JScrollPane jspObs = new JScrollPane(jtfldEnterpriseCellObs); FormLayout formLayout = new FormLayout( "5px, left:pref, 4dlu, 70dlu, 4dlu, 70dlu, 100dlu:grow, 5px", "5px, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, 50dlu:grow, 5px"); JPanel jpnlContent = new JPanel(new BorderLayout()); jpnlContent.setLayout(formLayout); if (MenuSingleton.isSupplier()) formLayout.setRowGroups(new int[][] {{2, 4, 6, 8}}); else formLayout.setRowGroups(new int[][] {{4, 6, 8}}); CellConstraints cc = new CellConstraints(); if (MenuSingleton.isSupplier()) { jpnlContent.add(jlbtnEnterprise, cc.xy(2, 2, CellConstraints.FILL, CellConstraints.FILL)); jpnlContent.add(jtfldEnterprise, cc.xy(4, 2)); jpnlContent.add(jlfldEnterprise, cc.xyw(6, 2, 2)); } jpnlContent.add(jlblEnterpriseCellID, cc.xy(2, 4)); jpnlContent.add(jtfldEnterpriseCellID, cc.xy(4, 4)); jpnlContent.add(jlblEnterpriseCellDescription, cc.xy(2, 6)); jpnlContent.add(jtfldEnterpriseCellDescription, cc.xyw(4, 6, 4)); jpnlContent.add(jlbtnFatherCellID, cc.xy(2, 8, CellConstraints.FILL, CellConstraints.FILL)); jpnlContent.add(jtfldFatherCellID, cc.xy(4, 8)); jpnlContent.add(jlfldFatherCellID, cc.xyw(6, 8, 2)); jpnlContent.add(jlblEnterpriseCellObs, cc.xy(2, 10)); jpnlContent.add(jspObs, cc.xyw(4, 10, 4, CellConstraints.FILL, CellConstraints.FILL)); JPanel jpnlDummy = new JPanel(new BorderLayout()); jpnlDummy.add(jpnlContent, BorderLayout.NORTH); add(jpnlContent, BorderLayout.CENTER); }
/** * Called when preparing this settings pane for display the first time. Can be overriden to * implement the look of the settings pane. */ @Override protected void prepareComponent() { FormLayout layout = new FormLayout( "10dlu, right:d, 2dlu, d, 2dlu:grow", // columns "p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p, 3dlu, p"); // rows layout.setRowGroups(new int[][] {{3, 5, 7, 9, 11, 13, 15, 17, 19, 21, 23}}); setLayout(layout); PanelBuilder builder = new PanelBuilder(layout, this); CellConstraints cc = new CellConstraints(); builder.addSeparator(Localizer.getString("GeneralDownloadSettings"), cc.xywh(1, 1, 5, 1)); JLabel label = builder.addLabel( Localizer.getString("DownloadSettings_TotalParallelDownloads") + ": ", cc.xy(2, 3)); label.setToolTipText(Localizer.getString("DownloadSettings_TTTTotalParallelDownloads")); totalWorkersTF = new IntegerTextField(DownloadPrefs.MaxTotalDownloadWorker.get().toString(), 6, 2); totalWorkersTF.setToolTipText( Localizer.getString("DownloadSettings_TTTTotalParallelDownloads")); builder.add(totalWorkersTF, cc.xy(4, 3)); label = builder.addLabel( Localizer.getString("DownloadSettings_ParallelDownloadsPerFile") + ": ", cc.xy(2, 5)); label.setToolTipText(Localizer.getString("DownloadSettings_TTTParallelDownloadsPerFile")); workerPerDownloadTF = new IntegerTextField(DownloadPrefs.MaxWorkerPerDownload.get().toString(), 6, 2); workerPerDownloadTF.setToolTipText( Localizer.getString("DownloadSettings_TTTParallelDownloadsPerFile")); builder.add(workerPerDownloadTF, cc.xy(4, 5)); label = builder.addLabel( Localizer.getString("DownloadSettings_InitialSegmentSizeKb") + ": ", cc.xy(2, 7)); label.setToolTipText(Localizer.getString("DownloadSettings_TTTInitialSegmentSizeKb")); initialSegmentSizeTF = new IntegerTextField( String.valueOf(DownloadPrefs.SegmentInitialSize.get().intValue() / 1024), 6, 4); initialSegmentSizeTF.setToolTipText( Localizer.getString("DownloadSettings_TTTInitialSegmentSizeKb")); builder.add(initialSegmentSizeTF, cc.xy(4, 7)); label = builder.addLabel( Localizer.getString("DownloadSettings_SegmentTransferTimeSec") + ": ", cc.xy(2, 9)); label.setToolTipText(Localizer.getString("DownloadSettings_TTTSegmentTransferTimeSec")); segmentTransferTimeTF = new IntegerTextField(DownloadPrefs.SegmentTransferTargetTime.get().toString(), 6, 3); segmentTransferTimeTF.setToolTipText( Localizer.getString("DownloadSettings_TTTSegmentTransferTimeSec")); builder.add(segmentTransferTimeTF, cc.xy(4, 9)); builder.addLabel(Localizer.getString("PushTimeout") + ": ", cc.xy(2, 11)); pushTimeoutTF = new IntegerTextField( String.valueOf(DownloadPrefs.PushRequestTimeout.get().intValue() / 1000), 6, 3); builder.add(pushTimeoutTF, cc.xy(4, 11)); readoutMagmaChkbx = new JCheckBox( Localizer.getString("DownloadSettings_ReadoutDownloadedMagmas"), DownloadPrefs.AutoReadoutMagmaFiles.get().booleanValue()); readoutMagmaChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTReadoutDownloadedMagmas")); builder.add(readoutMagmaChkbx, cc.xywh(2, 13, 4, 1)); readoutMetalinkChkbx = new JCheckBox( Localizer.getString("DownloadSettings_ReadoutDownloadedMetalink"), DownloadPrefs.AutoReadoutMetalinkFiles.get().booleanValue()); readoutMetalinkChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTReadoutDownloadedMetalink")); builder.add(readoutMetalinkChkbx, cc.xywh(2, 15, 4, 1)); readoutRSSChkbx = new JCheckBox( Localizer.getString("DownloadSettings_ReadoutDownloadedRSS"), DownloadPrefs.AutoReadoutRSSFiles.get().booleanValue()); readoutRSSChkbx.setToolTipText(Localizer.getString("DownloadSettings_TTTReadoutDownloadedRSS")); builder.add(readoutRSSChkbx, cc.xywh(2, 17, 4, 1)); silentSubscriptionsChkbx = new JCheckBox( Localizer.getString("DownloadSettings_DownloadSubscriptionsSilently"), SubscriptionPrefs.DownloadSilently.get().booleanValue()); silentSubscriptionsChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTDownloadSubscriptionsSilently")); builder.add(silentSubscriptionsChkbx, cc.xywh(2, 19, 4, 1)); removeCompletedDownloadsChkbx = new JCheckBox( Localizer.getString("DownloadSettings_AutoRemoveCompletedDownloads"), DownloadPrefs.AutoRemoveCompleted.get().booleanValue()); removeCompletedDownloadsChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTAutoRemoveCompletedDownloads")); builder.add(removeCompletedDownloadsChkbx, cc.xywh(2, 21, 4, 1)); enableHitSnoopingChkbx = new JCheckBox( Localizer.getString("DownloadSettings_EnableHitSnooping"), ConnectionPrefs.EnableQueryHitSnooping.get().booleanValue()); enableHitSnoopingChkbx.setToolTipText( Localizer.getString("DownloadSettings_TTTEnableHitSnooping")); builder.add(enableHitSnoopingChkbx, cc.xywh(2, 23, 4, 1)); initConfigValues(); refreshEnableState(); }
/** * Dumps the layout's column groups to the console. * * @param layout the <code>FormLayout</code> to inspect */ public static void dumpColumnGroups(FormLayout layout) { dumpGroups("COLUMN GROUPS: ", layout.getColumnGroups()); }
private void updateStatesPanel() { // Group the states first into individual panels List<BooleanTokenOverlay> overlays = new ArrayList<BooleanTokenOverlay>(TabletopTool.getCampaign().getTokenStatesMap().values()); Map<String, JPanel> groups = new TreeMap<String, JPanel>(); groups.put("", new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow"))); for (BooleanTokenOverlay overlay : overlays) { String group = overlay.getGroup(); if (group != null && (group = group.trim()).length() != 0) { JPanel panel = groups.get(group); if (panel == null) { panel = new JPanel(new FormLayout("0px:grow 2px 0px:grow 2px 0px:grow 2px 0px:grow")); panel.setBorder(BorderFactory.createTitledBorder(group)); groups.put(group, panel); } } } // Add the group panels and bar panel to the states panel JPanel panel = getStatesPanel(); panel.removeAll(); FormLayout layout = new FormLayout("0px:grow"); panel.setLayout(layout); int row = 1; for (JPanel gPanel : groups.values()) { layout.appendRow(new RowSpec("pref")); layout.appendRow(new RowSpec("2px")); panel.add(gPanel, new CellConstraints(1, row)); row += 2; } layout.appendRow(new RowSpec("pref")); layout.appendRow(new RowSpec("2px")); JPanel barPanel = new JPanel(new FormLayout("right:pref 2px pref 5px right:pref 2px pref")); panel.add(barPanel, new CellConstraints(1, row)); // Add the individual check boxes. for (BooleanTokenOverlay state : overlays) { String group = state.getGroup(); panel = groups.get(""); if (group != null && (group = group.trim()).length() != 0) panel = groups.get(group); int x = panel.getComponentCount() % 4; int y = panel.getComponentCount() / 4; if (x == 0) { layout = (FormLayout) panel.getLayout(); if (y != 0) layout.appendRow(new RowSpec("2px")); layout.appendRow(new RowSpec("pref")); } panel.add(new JCheckBox(state.getName()), new CellConstraints(x * 2 + 1, y * 2 + 1)); } // Add sliders to the bar panel if (TabletopTool.getCampaign().getTokenBarsMap().size() > 0) { layout = (FormLayout) barPanel.getLayout(); barPanel.setName("bar"); barPanel.setBorder(BorderFactory.createTitledBorder("Bars")); int count = 0; row = 0; for (BarTokenOverlay bar : TabletopTool.getCampaign().getTokenBarsMap().values()) { int working = count % 2; if (working == 0) { // slider row layout.appendRow(new RowSpec("pref")); row += 1; } JPanel labelPanel = new JPanel(new FormLayout("pref", "pref 2px:grow pref")); barPanel.add(labelPanel, new CellConstraints(1 + working * 4, row)); labelPanel.add( new JLabel(bar.getName() + ":"), new CellConstraints(1, 1, CellConstraints.RIGHT, CellConstraints.TOP)); JSlider slider = new JSlider(0, 100); JCheckBox hide = new JCheckBox("Hide"); hide.putClientProperty("JSlider", slider); hide.addChangeListener( new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { JSlider js = (JSlider) ((JCheckBox) e.getSource()).getClientProperty("JSlider"); js.setEnabled(!((JCheckBox) e.getSource()).isSelected()); } }); labelPanel.add(hide, new CellConstraints(1, 3, CellConstraints.RIGHT, CellConstraints.TOP)); slider.setName(bar.getName()); slider.setPaintLabels(true); slider.setPaintTicks(true); slider.setMajorTickSpacing(20); slider.createStandardLabels(20); slider.setMajorTickSpacing(10); barPanel.add(slider, new CellConstraints(3 + working * 4, row)); if (working != 0) { // spacer row layout.appendRow(new RowSpec("2px")); row += 1; } count += 1; } } }
public void actionPerformed(ActionEvent e) { String cmd = e.getActionCommand(); if (cmd.equals("new")) { icons = new Hashtable[0]; fields = new Hashtable[0]; tabPane.removeAll(); repaint(); } else if (cmd.equals("open")) { JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileFilter() { public boolean accept(File f) { return f.getAbsolutePath().endsWith(".template") || f.isDirectory(); } public String getDescription() { return "OME Notes Templates"; } }; chooser.setFileFilter(filter); int status = chooser.showOpenDialog(this); if (status == JFileChooser.APPROVE_OPTION) { String file = chooser.getSelectedFile().getAbsolutePath(); try { Template t = new Template(file); TemplateTab[] tabs = t.getTabs(); for (int i = 0; i < tabs.length; i++) { int rows = tabs[i].getRows(); int cols = tabs[i].getColumns(); if (cols == 0) cols = 1; if (rows == 0) rows = 1; addTab(tabs[i].getName(), rows, cols); tabPane.setSelectedIndex(i); for (int j = 0; j < tabs[i].getNumFields(); j++) { TemplateField f = tabs[i].getField(j); int x = f.getRow(); int y = f.getColumn(); if (x == -1) x = 1; if (y == -1) y = j + 1; Point p = new Point(x, y); DraggableIcon icon = (DraggableIcon) icons[i].get(p); icon.label = new JLabel(f.getName()); JPanel panel = new JPanel(); panel.add(f.getComponent()); icon.setPanel(panel); } } } catch (Exception exc) { error("Failed to parse template", exc); } tabPane.setSelectedIndex(0); } } else if (cmd.equals("save")) { // build up the template from the components TemplateTab[] tabs = new TemplateTab[tabPane.getTabCount()]; for (int i = 0; i < tabs.length; i++) { tabs[i] = new TemplateTab(); tabs[i].setName(tabPane.getTitleAt(i)); JComponent c = (JComponent) tabPane.getComponentAt(i); FormLayout layout = (FormLayout) c.getLayout(); tabs[i].setRows(layout.getRowCount()); tabs[i].setColumns(layout.getColumnCount()); Object[] keys = icons[i].keySet().toArray(); for (int j = 0; j < keys.length; j++) { Point p = (Point) keys[j]; DraggableIcon icon = (DraggableIcon) icons[i].get(p); TemplateField f = (TemplateField) fields[i].get(p); if (icon.image != null) { Component[] components = icon.image.getComponents(); JLabel label = icon.label; JComponent component = (JComponent) components[0]; f.setComponent(component); for (int k = 0; k < COMPONENTS.length; k++) { if (component.getClass().equals(COMPONENTS[k])) { f.setType(COMPONENT_TYPES[k]); break; } } f.setRow(p.y); f.setColumn(p.x); f.setDefaultValue(TemplateTools.getComponentValue(component)); tabs[i].addField(f); } } } Template t = new Template(tabs, null); // prompt for filename to save to if (currentFile == null) { JFileChooser chooser = new JFileChooser(); FileFilter filter = new FileFilter() { public boolean accept(File f) { return true; } public String getDescription() { return "All files"; } }; chooser.setFileFilter(filter); int status = chooser.showSaveDialog(this); if (status == JFileChooser.APPROVE_OPTION) { currentFile = chooser.getSelectedFile().getAbsolutePath(); if (currentFile == null) return; } } try { t.save(currentFile); } catch (IOException io) { error("Failed to save template", io); } } else if (cmd.equals("quit")) dispose(); else if (cmd.equals("add row")) addRow(); else if (cmd.equals("add col")) addColumn(); else if (cmd.equals("prompt tab")) { // prompt for tab name JPopupMenu menu = new JPopupMenu(); newTabName = new JTextField(); newTabName.setPreferredSize(new Dimension(200, 25)); menu.add(newTabName); JButton b = new JButton("OK"); b.addActionListener(this); b.setActionCommand("new tab"); menu.add(b); JComponent s = (JComponent) e.getSource(); menu.show(s, s.getX(), s.getY()); newTabName.grabFocus(); } else if (cmd.equals("new tab")) { newTabName.getParent().setVisible(false); addTab(newTabName.getText(), 2, 2); } else if (cmd.equals("setName")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); String text = ((JTextField) menu.getComponents()[0]).getText(); Point p = new Point(icon.gridx, icon.gridy); int ndx = tabPane.getSelectedIndex(); TemplateField f = (TemplateField) fields[ndx].get(p); f.setName(text); f.setNameMap(null); // set the name if (icon.label != null) icon.remove(icon.label); icon.remove(icon.image); icon.label = new JLabel(text); icon.add(icon.label); icon.add(icon.image); icon.getParent().repaint(); } else if (cmd.equals("changeName")) { // prompt for new field name JPopupMenu menu = new JPopupMenu(); JTextField field = new JTextField(); field.setPreferredSize(new Dimension(200, 25)); menu.add(field); JButton b = new JButton("OK"); b.addActionListener(this); b.setActionCommand("setName"); menu.add(b); menu.show(lastMenuComponent, lastMenuX, lastMenuY); field.grabFocus(); } else if (cmd.equals("nameMap")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); MappingWindow w = new MappingWindow(this, true); w.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("map")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); MappingWindow w = new MappingWindow(this, false); w.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("repeat")) { JMenuItem item = (JMenuItem) e.getSource(); DraggableIcon icon = (DraggableIcon) ((JPopupMenu) item.getParent()).getInvoker(); TemplateField f = getField(icon); if (item.getText().equals("Repeat this field")) { item.setText("Don't repeat this field"); f.setRepeated(true); } else { item.setText("Repeat this field"); f.setRepeated(false); } } else if (cmd.equals("removeField")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); menu.setVisible(false); int idx = tabPane.getSelectedIndex(); Object[] keys = icons[idx].keySet().toArray(); for (int i = 0; i < keys.length; i++) { if (icons[idx].get(keys[i]).equals(icon)) { icons[idx].remove(keys[i]); fields[idx].remove(keys[i]); break; } } icon.remove(icon.label); icon.remove(icon.image); tabPane.repaint(); } else if (cmd.startsWith("removeRow")) { int row = Integer.parseInt(cmd.substring(cmd.indexOf(":") + 1)); JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); menu.setVisible(false); JPanel pane = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) pane.getLayout(); int rows = layout.getRowCount(); int cols = layout.getColumnCount(); int idx = tabPane.getSelectedIndex(); for (int i = 0; i < cols; i++) { pane.remove((JComponent) icons[idx].get(new Point(i + 1, row + 1))); } rekey(row, -1); layout.removeRow(row + 1); tabPane.repaint(); } else if (cmd.startsWith("removeColumn")) { int col = Integer.parseInt(cmd.substring(cmd.indexOf(":") + 1)); JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); menu.setVisible(false); JPanel pane = (JPanel) tabPane.getSelectedComponent(); FormLayout layout = (FormLayout) pane.getLayout(); int rows = layout.getRowCount(); int cols = layout.getColumnCount(); int idx = tabPane.getSelectedIndex(); for (int i = 0; i < rows; i++) { pane.remove((JComponent) icons[idx].get(new Point(col + 1, i + 1))); } rekey(-1, col); layout.removeColumn(col + 1); tabPane.repaint(); } else if (cmd.equals("removeTab")) { int ndx = tabPane.getSelectedIndex(); tabPane.remove(ndx); Hashtable[] h = new Hashtable[icons.length - 1]; Hashtable[] f = new Hashtable[fields.length - 1]; System.arraycopy(icons, 0, h, 0, ndx); System.arraycopy(icons, ndx + 1, h, ndx, h.length - ndx); System.arraycopy(fields, 0, f, 0, ndx); System.arraycopy(fields, ndx + 1, f, ndx, f.length - ndx); icons = h; fields = f; } else if (cmd.equals("specifyChoices")) { JMenuItem item = (JMenuItem) e.getSource(); DraggableIcon icon = (DraggableIcon) ((JPopupMenu) item.getParent()).getInvoker(); TemplateField f = getField(icon); EnumWindow w = new EnumWindow(this, f.getEnums()); w.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("setThumbSource")) { JPopupMenu menu = new JPopupMenu(); ButtonGroup g = new ButtonGroup(); JRadioButton dataset = new JRadioButton("Use thumbnail from dataset"); dataset.setSelected(true); g.add(dataset); JRadioButton file = new JRadioButton("Use thumbnail from file:"); g.add(file); menu.add(dataset); menu.add(file); JTextField field = new JTextField(); field.setPreferredSize(new Dimension(200, 25)); menu.add(field); JButton b = new JButton("OK"); b.addActionListener(this); b.setActionCommand("applyThumbSource"); menu.add(b); menu.show(lastMenuComponent, lastMenuX, lastMenuY); } else if (cmd.equals("applyThumbSource")) { JPopupMenu menu = (JPopupMenu) ((JComponent) e.getSource()).getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); Component[] c = menu.getComponents(); JRadioButton dataset = (JRadioButton) c[0]; String text = null; if (!dataset.isSelected()) { JTextField t = (JTextField) c[2]; text = t.getText(); getField(icon).setValueMap(text); } menu.setVisible(false); if (text != null) { try { BufferedImageReader reader = new BufferedImageReader(); reader.setId(text); BufferedImage thumb = reader.openThumbImage(0); JLabel label = (JLabel) icon.image.getComponents()[0]; label.setIcon(new ImageIcon(thumb)); reader.close(); } catch (FormatException exc) { error("Failed to open thumbnail (" + text + ")", exc); } catch (IOException exc) { error("Failed to open thumbnail (" + text + ")", exc); } } } else if (cmd.equals("ok")) { // this event came from an instance of EnumWindow JPanel parent = (JPanel) ((JButton) e.getSource()).getParent(); EnumWindow menu = (EnumWindow) parent.getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); TemplateField f = getField(icon); menu.setVisible(false); String[] options = menu.getOptions(); f.setEnums(options); JComboBox box = (JComboBox) icon.image.getComponents()[0]; for (int i = 0; i < options.length; i++) box.addItem(options[i]); repaint(); } else if (cmd.equals("chooseMapping")) { // this event came from an instance of MappingWindow JTabbedPane parent = (JTabbedPane) ((JButton) e.getSource()).getParent(); MappingWindow menu = (MappingWindow) parent.getParent(); DraggableIcon icon = (DraggableIcon) menu.getInvoker(); TemplateField f = getField(icon); String omexmlMap = null; if (menu.nameMap) f.setNameMap(omexmlMap); else f.setValueMap(omexmlMap); menu.setVisible(false); } }
private void initialize() { setLayout(new BorderLayout()); setOpaque(false); jlblEmergencySitDefID.setText(res.getString("emergSitdef.label.code")); jtfldEmergencySitDefID.setField("emergSitID"); jtfldEmergencySitDefID.setHolder(jlblEmergencySitDefID); jlblEmergencySitDescription.setText(res.getString("emergSitdef.label.description")); jtfldEmergencySitDescription.setField("emergSitDescription"); jtfldEmergencySitDescription.setHolder(jlblEmergencySitDescription); jtfldEnvAsp.setField("fkEnvAspID"); jtfldEnvAsp.setLabel(res.getString("emergSitlink.label.aa")); jlbtnEnvAsp.setUrl("pt.inescporto.siasoft.go.aa.ejb.session.EnvironmentAspect"); jlbtnEnvAsp.setText(res.getString("emergSitlink.label.aa")); jlbtnEnvAsp.setTitle(res.getString("emergSitlink.label.aalist")); jlbtnEnvAsp.setDefaultFill(jtfldEnvAsp); jlfldEnvAsp.setUrl("pt.inescporto.siasoft.go.aa.ejb.session.EnvironmentAspect"); jlfldEnvAsp.setDefaultRefField(jtfldEnvAsp); jtfldEmergSUserRespID.setField("fkUserID"); jtfldEmergSUserRespID.setText(res.getString("emergSitdef.buttonlabel.resp")); jlbtnEmergSUserResp.setText(res.getString("emergSitdef.buttonlabel.resp")); jlbtnEmergSUserResp.setUrl("pt.inescporto.siasoft.comun.ejb.session.User"); if (!MenuSingleton.isSupplier()) jlbtnEmergSUserResp.setLinkCondition( "enterpriseID = '" + MenuSingleton.getEnterprise() + "'"); jlbtnEmergSUserResp.setTitle(res.getString("emergSitdef.label.resplist")); jlbtnEmergSUserResp.setDefaultFill(jtfldEmergSUserRespID); jlfldEmergSUserRespDescription.setUrl("pt.inescporto.siasoft.comun.ejb.session.User"); jlfldEmergSUserRespDescription.setDefaultRefField(jtfldEmergSUserRespID); jtfldActivity.setLabel(res.getString("emergSitlink.label.activity")); jtfldActivity.setField("fkActivityID"); if (!MenuSingleton.isSupplier()) jlbtnActivity.setLinkCondition("fkEnterpriseID = '" + MenuSingleton.getEnterprise() + "'"); jlbtnActivity.setUrl("pt.inescporto.siasoft.proc.ejb.session.Activity"); jlbtnActivity.setText(res.getString("emergSitlink.label.activity")); jlbtnActivity.setTitle(res.getString("emergSitlink.label.activitylist")); jlbtnActivity.setDefaultFill(jtfldActivity); jlfldActivity.setUrl("pt.inescporto.siasoft.proc.ejb.session.Activity"); jlfldActivity.setDefaultRefField(jtfldActivity); jlblNormal.setText(res.getString("emergSitdef.label.normal")); jlblAnormal.setText(res.getString("emergSitdef.label.abnormal")); jlblEmergency.setText(res.getString("emergSitdef.label.emergency")); jrbNormal.setValue("N"); jrbAnormal.setValue("A"); jrbEmergency.setValue("E"); bgType.setField("typeEmerg"); bgType.add(jrbNormal); bgType.add(jrbAnormal); bgType.add(jrbEmergency); FormLayout formLayout = new FormLayout( "5px, left:pref, 4dlu, 50dlu, 4dlu, 50dlu, 4dlu, 50dlu, 4dlu, 50dlu, 4dlu, 50dlu, 4dlu:grow, 5px", "5px, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 5px"); FormLayout formLayout2 = new FormLayout( "65dlu, pref, 4dlu, pref, 20dlu, pref, 4dlu, pref, 20dlu, pref, 4dlu, pref, 65dlu", "5px, pref, 5px"); JPanel content = new JPanel(); content.setOpaque(false); content.setLayout(formLayout); JPanel typeContent = new JPanel(); typeContent.setOpaque(false); typeContent.setLayout(formLayout2); formLayout.setRowGroups(new int[][] {{2, 4, 6, 8}}); CellConstraints cc = new CellConstraints(); typeContent.setBorder( BorderFactory.createTitledBorder(res.getString("emergSitdef.label.type"))); ((TitledBorder) typeContent.getBorder()).setTitleFont(new Font("Dialog", Font.PLAIN, 12)); typeContent.add(jlblNormal, cc.xy(2, 2)); typeContent.add(jrbNormal, cc.xy(4, 2)); typeContent.add(jlblAnormal, cc.xy(6, 2)); typeContent.add(jrbAnormal, cc.xy(8, 2)); typeContent.add(jlblEmergency, cc.xy(10, 2)); typeContent.add(jrbEmergency, cc.xy(12, 2)); content.add(jlblEmergencySitDefID, cc.xy(2, 2)); content.add(jtfldEmergencySitDefID, cc.xy(4, 2)); content.add(jlblEmergencySitDescription, cc.xy(2, 4)); content.add(jtfldEmergencySitDescription, cc.xyw(4, 4, 10)); content.add(jlbtnEnvAsp, cc.xy(2, 6, CellConstraints.FILL, CellConstraints.DEFAULT)); content.add(jtfldEnvAsp, cc.xy(4, 6)); content.add(jlfldEnvAsp, cc.xyw(6, 6, 8)); content.add(jlbtnEmergSUserResp, cc.xy(2, 8, CellConstraints.FILL, CellConstraints.DEFAULT)); content.add(jtfldEmergSUserRespID, cc.xy(4, 8)); content.add(jlfldEmergSUserRespDescription, cc.xyw(6, 8, 8)); content.add(jlbtnActivity, cc.xy(2, 10, CellConstraints.FILL, CellConstraints.DEFAULT)); content.add(jtfldActivity, cc.xy(4, 10)); content.add(jlfldActivity, cc.xyw(6, 10, 8)); jrbEmergency.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (((TmplJRadioButton) e.getSource()).isSelected()) { jtpScenarios.setEnabledAt(1, true); } } }); jrbNormal.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (((TmplJRadioButton) e.getSource()).isSelected()) { jtpScenarios.setEnabledAt(1, false); } } }); jrbAnormal.addActionListener( new ActionListener() { public void actionPerformed(ActionEvent e) { if (((TmplJRadioButton) e.getSource()).isSelected()) { jtpScenarios.setEnabledAt(1, false); } } }); content.add(typeContent, cc.xyw(2, 12, 12)); add(content, BorderLayout.NORTH); add( new EmergencySituationScenarios(datasource, fwCListener, jtpScenarios), BorderLayout.CENTER); }
/** * Dumps the layout's row groups to the console. * * @param layout the <code>FormLayout</code> to inspect */ public static void dumpRowGroups(FormLayout layout) { dumpGroups("ROW GROUPS: ", layout.getRowGroups()); }