List of usage examples for com.jgoodies.forms.layout FormLayout insertRow
public void insertRow(int rowIndex, RowSpec rowSpec)
From source file:aconsole.config.PropertyPanel.java
License:Open Source License
public int addColorButton(ColorProperty src, String label, String tooltip, FormLayout layout, PanelBuilder panelBuilder, CellConstraints cc, int row) { ColorLink cl = new ColorLink(); cl.prop = src;/*from www.j a v a2s .c o m*/ cl.btn = new ColorButton(); cl.btn.setToolTipText(tooltip); cl.reset(); layout.insertRow(row, RowSpec.decode("pref")); layout.insertRow(row + 1, RowSpec.decode("5dlu")); panelBuilder.add(new JLabel(label), cc.xyw(2, row, 1)); panelBuilder.add(cl.btn, cc.xyw(3, row, 1)); linklist.add(cl); return 2; }
From source file:clockplugin.ClockSettingsTab.java
License:GNU General Public License
public JPanel createSettingsPanel() { FormLayout layout = new FormLayout("5dlu,pref,3dlu,pref,pref:grow,10dlu", "5dlu,pref,pref,pref,pref,5dlu,pref,2dlu,pref," + "pref,10dlu,pref,pref"); PanelBuilder pb = new PanelBuilder(layout); CellConstraints cc = new CellConstraints(); mMove = new JCheckBox(mLocalizer.msg("moveonscreen", "Move clock on screen with TV-Browser")); mMove.setSelected(ClockPlugin.getInstance().getMoveOnScreen()); mShowBorder = new JCheckBox(mLocalizer.msg("clockborder", "Clock with border")); mShowBorder.setSelected(ClockPlugin.getInstance().getShowBorder()); mTitleClock = new JCheckBox(mLocalizer.msg("titlebar", "Clock in the title bar")); mTitleClock.setSelected(ClockPlugin.getInstance().getTitleBarClock()); mBox = new JCheckBox(mLocalizer.msg("forever", "Show clock forever")); mBox.setSelected(ClockPlugin.getInstance().getShowForever()); mBox.addActionListener(this); mUsePersonaColors = new JCheckBox(mLocalizer.msg("usePersonaColors", "Use Colors of Persona"), ClockPlugin.getInstance().isUsingPersonaColors()); mUseTransparency = new JCheckBox(mLocalizer.msg("useTransparency", "Clock transparent"), ClockPlugin.getInstance().isUsingTransparentBackground()); mTime = new JSpinner(); mTime.setModel(new SpinnerNumberModel(ClockPlugin.getInstance().getTimeValue(), 5, 30, 1)); mFontSize = new JSpinner(); mFontSize.setModel(new SpinnerNumberModel(ClockPlugin.getInstance().getFontValue(), 10, 30, 1)); pb.add(mMove, cc.xyw(2, 2, 4));/*w w w . ja va 2 s .c o m*/ pb.add(mShowBorder, cc.xyw(2, 3, 4)); pb.add(mTitleClock, cc.xyw(2, 4, 4)); pb.add(mBox, cc.xyw(2, 5, 4)); int y = 6; try { Class.forName("util.ui.persona.Persona"); layout.insertRow(y, RowSpec.decode("default")); pb.add(mUsePersonaColors, cc.xyw(2, y++, 4)); } catch (ClassNotFoundException e) { } boolean showTransparencySelection = false; GraphicsDevice[] devices = GraphicsEnvironment.getLocalGraphicsEnvironment().getScreenDevices(); GraphicsConfiguration config = devices[0].getDefaultConfiguration(); try { Class<?> awtUtilities = Class.forName("com.sun.awt.AWTUtilities"); Method m = awtUtilities.getMethod("isTranslucencyCapable", new Class<?>[] { GraphicsConfiguration.class }); showTransparencySelection = (Boolean) m.invoke(awtUtilities, new Object[] { config }); } catch (Exception e) { e.printStackTrace(); try { Method m = config.getClass().getMethod("isTranslucencyCapable()", new Class<?>[] { GraphicsConfiguration.class }); showTransparencySelection = (Boolean) m.invoke(config, new Object[0]); } catch (Exception e1) { e1.printStackTrace(); } } if (showTransparencySelection) { layout.insertRow(y, RowSpec.decode("default")); pb.add(mUseTransparency, cc.xyw(2, y++, 4)); } mLabel = pb.addLabel(mLocalizer.msg("desc", "Duration of showing the clock in seconds") + ":", cc.xy(2, ++y)); pb.add(mTime, cc.xy(4, y++)); pb.addLabel(mLocalizer.msg("fsize", "Font size of the clock") + ":", cc.xy(2, ++y)); pb.add(mFontSize, cc.xy(4, y)); y += 3; pb.addLabel(mLocalizer.msg("info1", "To move the clock on screen click it left"), cc.xyw(2, y++, 4)); pb.addLabel(mLocalizer.msg("info2", "and move the mouse with pressed left button."), cc.xyw(2, y, 4)); if (mBox.isSelected()) { mTime.setEnabled(false); mLabel.setEnabled(false); } return pb.getPanel(); }
From source file:com.intellij.uiDesigner.radComponents.RadFormLayoutManager.java
License:Apache License
private static void insertOrAppendRow(final FormLayout formLayout, final int index, final RowSpec rowSpec) { if (index == formLayout.getRowCount() + 1) { formLayout.appendRow(rowSpec);/* w ww .j a va 2s.c o m*/ } else { formLayout.insertRow(index, rowSpec); } }
From source file:com.jeta.swingbuilder.gui.main.ComponentsToolBar.java
License:Open Source License
/** * Creates the java beans palette toolbar. * //from w w w. j av a2 s . c om */ private Container createToolbar() { LinkedList button_list = new LinkedList(); button_list.addAll(registerDefaultBeans()); button_list.addAll(registerImportedBeans()); StringBuffer colspec = new StringBuffer(); StringBuffer rowspec = new StringBuffer(); int cols = button_list.size() / MAX_TOOLBAR_ROWS + (button_list.size() % MAX_TOOLBAR_ROWS == 0 ? 0 : 1); int rows = Math.min(button_list.size(), MAX_TOOLBAR_ROWS); for (int col = 1; col <= cols; col++) { if (col > 1) colspec.append(","); colspec.append("pref"); } for (int row = 1; row <= rows; row++) { if (row > 1) rowspec.append(","); rowspec.append("pref"); } ButtonGroup bgroup = new ButtonGroup(); JETAPanel toolbar = new JETAPanel(); toolbar.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 4, 0, 4)); FormLayout layout = new FormLayout(colspec.toString(), rowspec.toString()); CellConstraints cc = new CellConstraints(); toolbar.setLayout(layout); int row_count = button_list.size() / cols + (button_list.size() % cols == 0 ? 0 : 1); Iterator iter = button_list.iterator(); for (int col = 1; col <= cols; col++) { for (int row = 1; row <= row_count; row++) { if (iter.hasNext()) { Component btn = (Component) iter.next(); bgroup.add((AbstractButton) btn); JPanel btn_panel = new JPanel(new BorderLayout()); btn_panel.setBorder(BorderFactory.createEmptyBorder(1, 1, 1, 1)); btn_panel.add(btn, BorderLayout.CENTER); toolbar.add(btn_panel, cc.xy(col, row)); } else { break; } } } layout.insertRow(1, new RowSpec("5px")); toolbar.setController(new ToolbarController(toolbar, button_list)); assert (!iter.hasNext()); return toolbar; }
From source file:loci.ome.notes.editor.EnumWindow.java
License:Open Source License
private void addOption(String name) { remove(content);/*from ww w. j ava 2s .co m*/ FormLayout layout = (FormLayout) content.getLayout(); layout.insertRow(layout.getRowCount() - 2, new RowSpec("pref:grow")); layout.insertRow(layout.getRowCount() - 2, new RowSpec("pref")); JLabel label = new JLabel(name); JButton remove = new JButton("Remove"); remove.setActionCommand("remove"); remove.addActionListener(this); options.add(name); int last = layout.getRowCount() - 4; content.add(label, CC.xy(2, last)); content.add(remove, CC.xywh(7, last, 2, 1)); add(content); pack(); parent.repaint(); }
From source file:net.sf.jabref.gui.mergeentries.MergeEntries.java
License:Open Source License
/** * Main function for building the merge entry JPanel *//* w w w .j a va 2s .c om*/ 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 String type1 = one.getType(); String 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); type1ta.setEditable(false); mergePanel.add(type1ta, cc.xy(3, 1)); if (type1.compareTo(type2) == 0) { identical[0] = true; } else { 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(e -> updateAll()); } rb[0][0].setSelected(true); } JTextArea type2ta = new JTextArea(type2); 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) && (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]) { mergedEntry.setField(field, string1); } else { 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(e -> updateAll()); } if (string1 == null) { rb[0][row - 1].setEnabled(false); mergedEntry.setField(field, string2); rb[2][row - 1].setSelected(true); } else { mergedEntry.setField(field, string1); rb[0][row - 1].setSelected(true); if (string2 == null) { rb[2][row - 1].setEnabled(false); } } } 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 BibEntryWriter(new LatexFieldFormatter(), false).write(mergedEntry, sw, type); } 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(MARGIN)); mainLayout.appendColumn(ColumnSpec.decode(MARGIN)); mainLayout.insertRow(1, RowSpec.decode(MARGIN)); mainLayout.insertColumn(1, ColumnSpec.decode(MARGIN)); 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(() -> scrollPane.getVerticalScrollBar().setValue(0)); }
From source file:net.sf.jabref.gui.mergeentries.MergeEntriesDialog.java
License:Open Source License
/** * Sets up the dialog/*from w w w. j av a 2s . c om*/ * * @param selected Selected BibtexEntries */ private void init(List<BibEntry> selected) { // Check if there are two entries selected if (selected.size() != 2) { // None selected. Inform the user to select entries first. JOptionPane.showMessageDialog(panel.frame(), Localization.lang("You have to choose exactly two entries to merge."), MERGE_ENTRIES, JOptionPane.INFORMATION_MESSAGE); this.dispose(); return; } // Store the two entries BibEntry one = selected.get(0); BibEntry two = selected.get(1); MergeEntries mergeEntries = new MergeEntries(one, two, panel.getBibDatabaseContext().getMode()); // Create undo-compound NamedCompound ce = new NamedCompound(MERGE_ENTRIES); FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p"); this.setLayout(layout); this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1)); this.add(new JSeparator(), cc.xy(1, 3)); // Create buttons ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton cancel = new JButton(Localization.lang("Cancel")); cancel.setActionCommand("cancel"); cancel.addActionListener(e -> { panel.output(Localization.lang("Cancelled merging entries")); dispose(); }); JButton replaceentries = new JButton(MERGE_ENTRIES); replaceentries.setActionCommand("replace"); replaceentries.addActionListener(e -> { // Create a new entry and add it to the undo stack // Remove the other two entries and add them to the undo stack (which is not working...) BibEntry mergedEntry = mergeEntries.getMergeEntry(); panel.insertEntry(mergedEntry); ce.addEdit(new UndoableInsertEntry(panel.database(), mergedEntry, panel)); ce.addEdit(new UndoableRemoveEntry(panel.database(), one, panel)); panel.database().removeEntry(one); ce.addEdit(new UndoableRemoveEntry(panel.database(), two, panel)); panel.database().removeEntry(two); ce.end(); panel.undoManager.addEdit(ce); panel.output(Localization.lang("Merged entries")); dispose(); }); bb.addButton(new JButton[] { replaceentries, cancel }); this.add(bb.getPanel(), cc.xy(1, 5)); // Add some margin around the layout layout.appendRow(RowSpec.decode(MARGIN)); layout.appendColumn(ColumnSpec.decode(MARGIN)); layout.insertRow(1, RowSpec.decode(MARGIN)); layout.insertColumn(1, ColumnSpec.decode(MARGIN)); // Set up a ComponentListener that saves the last size and position of the dialog this.addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { // Save dialog position pw.storeWindowPosition(); } @Override public void componentMoved(ComponentEvent e) { // Save dialog position pw.storeWindowPosition(); } }); pw = new PositionWindow(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y); pw.setWindowPosition(); // Show what we've got setVisible(true); }
From source file:net.sf.jabref.gui.mergeentries.MergeEntryDOIDialog.java
License:Open Source License
/** * Sets up the dialog/*from w ww. j a v a2 s . co m*/ */ private void init() { mergeEntries = new MergeEntries(this.originalEntry, this.doiEntry, Localization.lang("Original entry"), Localization.lang("Entry from DOI"), panel.getBibDatabaseContext().getMode()); // Create undo-compound ce = new NamedCompound(Localization.lang("Merge from DOI")); FormLayout layout = new FormLayout("fill:700px:grow", "fill:400px:grow, 4px, p, 5px, p"); // layout.setColumnGroups(new int[][] {{3, 11}}); this.setLayout(layout); this.add(mergeEntries.getMergeEntryPanel(), cc.xy(1, 1)); this.add(new JSeparator(), cc.xy(1, 3)); // Create buttons ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton cancel = new JButton(Localization.lang("Cancel")); cancel.setActionCommand("cancel"); cancel.addActionListener(e -> buttonPressed(e.getActionCommand())); JButton replaceentry = new JButton(Localization.lang("Replace original entry")); replaceentry.setActionCommand("done"); replaceentry.addActionListener(e -> buttonPressed(e.getActionCommand())); bb.addButton(new JButton[] { replaceentry, cancel }); this.add(bb.getPanel(), cc.xy(1, 5)); // Add some margin around the layout layout.appendRow(RowSpec.decode(MARGIN)); layout.appendColumn(ColumnSpec.decode(MARGIN)); layout.insertRow(1, RowSpec.decode(MARGIN)); layout.insertColumn(1, ColumnSpec.decode(MARGIN)); pw = new PositionWindow(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y); pw.setWindowPosition(); // Set up a ComponentListener that saves the last size and position of the dialog addComponentListener(new ComponentAdapter() { @Override public void componentResized(ComponentEvent e) { // Save dialog position pw.storeWindowPosition(); } @Override public void componentMoved(ComponentEvent e) { // Save dialog position pw.storeWindowPosition(); } }); // Show what we've got setVisible(true); }
From source file:net.sf.jabref.gui.MergeEntriesDialog.java
License:Open Source License
private void init(BibtexEntry[] selected) { // Check if there are two entries selected if (selected.length != 2) { // None selected. Inform the user to select entries first. JOptionPane.showMessageDialog(frame, Globals.lang("You have to choose exactly two entries to merge."), Globals.lang("Merge entries"), JOptionPane.INFORMATION_MESSAGE); this.dispose(); return;// w ww . java 2 s. c om } // Store the two entries one = selected[0]; two = selected[1]; // Create undo-compound ce = new NamedCompound(Globals.lang("Merge entries")); joint = new TreeSet<String>(one.getAllFields()); joint.addAll(two.getAllFields()); // Remove field starting with __ Set<String> toberemoved = new TreeSet<String>(); 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 layout String colSpec = "left:pref, 5px, fill:4cm:grow, 5px, right:pref, 3px, center:pref, 3px, left:pref, 5px, fill:4cm:grow"; StringBuilder rowBuilder = new StringBuilder("pref, 10px, pref, "); for (int i = 0; i < joint.size(); i++) { rowBuilder.append("pref, "); } rowBuilder.append("10px, top:4cm:grow, 10px, pref"); FormLayout layout = new FormLayout(colSpec, rowBuilder.toString()); // layout.setColumnGroups(new int[][] {{3, 11}}); this.setLayout(layout); // Set headings for (int i = 0; i < 6; i++) { JLabel label = new JLabel(columnHeadings[i]); Font font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); this.add(label, cc.xy(1 + (i * 2), 1)); } this.add(new JSeparator(), cc.xyw(1, 2, 11)); // Start with entry type BibtexEntryType type1 = one.getType(); BibtexEntryType type2 = two.getType(); mergedEntry.setType(type1); JLabel label = new JLabel(Globals.lang("Entry type")); Font font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); this.add(label, cc.xy(1, 3)); JTextArea type1ta = new JTextArea(type1.getName()); type1ta.setEditable(false); this.add(type1ta, cc.xy(3, 3)); 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]); this.add(rb[k][0], cc.xy(5 + (k * 2), 3)); 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); this.add(type2ta, cc.xy(11, 3)); // For all fields in joint add a row and possibly radio buttons int row = 4; for (String field : joint) { jointStrings[row - 4] = field; label = new JLabel(StringUtil.toUpperFirstLetter(field)); font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); this.add(label, cc.xy(1, row)); String string1 = one.getField(field); String string2 = two.getField(field); identical[row - 3] = false; if ((string1 != null) && (string2 != null)) { if (string1.equals(string2)) { identical[row - 3] = true; } } if (field.equals("abstract")) { // Treat the abstract field special, maybe more fields? Review? Note? JTextArea tf = new JTextArea(); tf.setLineWrap(true); tf.setEditable(false); JScrollPane jsptf = new JScrollPane(tf); layout.setRowSpec(row, RowSpec.decode("center:2cm:grow")); this.add(jsptf, cc.xy(3, row, "f, f")); tf.setText(string1); tf.setCaretPosition(0); } else { JTextArea tf = new JTextArea(string1); this.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 - 3]) { rbg[row - 3] = new ButtonGroup(); for (int k = 0; k < 3; k++) { rb[k][row - 3] = new JRadioButton(); rbg[row - 3].add(rb[k][row - 3]); this.add(rb[k][row - 3], cc.xy(5 + (k * 2), row)); rb[k][row - 3].addChangeListener(new ChangeListener() { @Override public void stateChanged(ChangeEvent e) { updateAll(); } }); } if (string1 != null) { mergedEntry.setField(field, string1); rb[0][row - 3].setSelected(true); } else { mergedEntry.setField(field, string2); rb[2][row - 3].setSelected(true); } } else { mergedEntry.setField(field, string1); } if (field.equals("abstract")) { // Again, treat abstract special JTextArea tf = new JTextArea(); tf.setLineWrap(true); tf.setEditable(false); JScrollPane jsptf = new JScrollPane(tf); this.add(jsptf, cc.xy(11, row, "f, f")); tf.setText(string2); tf.setCaretPosition(0); } else { JTextArea tf = new JTextArea(string2); this.add(tf, cc.xy(11, row)); tf.setCaretPosition(0); tf.setEditable(false); } row++; } this.add(new JSeparator(), cc.xyw(1, row, 11)); row++; // Setup a PreviewPanel and a Bibtex source box for the merged entry label = new JLabel(Globals.lang("Merged entry")); font = label.getFont(); label.setFont(font.deriveFont(font.getStyle() | Font.BOLD)); this.add(label, cc.xy(1, row)); String layoutString = Globals.prefs.get(JabRefPreferences.PREVIEW_0); pp = new PreviewPanel(null, mergedEntry, null, new MetaData(), layoutString); // JScrollPane jsppp = new JScrollPane(pp); this.add(pp, cc.xyw(3, row, 3)); jta = new JTextArea(); jta.setLineWrap(true); JScrollPane jspta = new JScrollPane(jta); this.add(jspta, cc.xyw(9, row, 3)); jta.setEditable(false); StringWriter sw = new StringWriter(); try { mergedEntry.write(sw, new LatexFieldFormatter(), false); } catch (IOException ex) { System.err.println(Globals.lang("Error in entry" + ": " + ex.getMessage())); } jta.setText(sw.getBuffer().toString()); jta.setCaretPosition(0); row++; this.add(new JSeparator(), cc.xyw(1, row, 11)); row++; // Create buttons ButtonBarBuilder bb = new ButtonBarBuilder(); bb.addGlue(); JButton cancel = new JButton(Globals.lang("Cancel")); cancel.setActionCommand("cancel"); cancel.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buttonPressed(e.getActionCommand()); } }); JButton newentry = new JButton(Globals.lang("Add new entry and keep both old entries")); newentry.setActionCommand("newentry"); newentry.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buttonPressed(e.getActionCommand()); } }); JButton replaceentries = new JButton(Globals.lang("Replace old entries with new entry")); replaceentries.setActionCommand("replace"); replaceentries.addActionListener(new ActionListener() { @Override public void actionPerformed(ActionEvent e) { buttonPressed(e.getActionCommand()); } }); bb.addButton(new JButton[] { replaceentries, newentry, cancel }); this.add(bb.getPanel(), cc.xyw(1, row, 11)); // Add some margin around the layout layout.appendRow(RowSpec.decode("10px")); layout.appendColumn(ColumnSpec.decode("10px")); layout.insertRow(1, RowSpec.decode("10px")); layout.insertColumn(1, ColumnSpec.decode("10px")); pack(); if (getHeight() > DIM.height) { setSize(new Dimension(getWidth(), DIM.height)); } if (getWidth() > DIM.width) { setSize(new Dimension(DIM.width, getHeight())); } // Everything done, allow any action to actually update the merged entry doneBuilding = true; // Show what we've got setVisible(true); }
From source file:printplugin.dlgs.components.FontsDialog.java
License:Open Source License
public FontsDialog(Frame parent, Font titleFont, Font descriptionFont, Font dateFont) { super(parent, true); setTitle(mLocalizer.msg("dialog.title", "Fonts")); JPanel content = (JPanel) getContentPane(); UiUtilities.registerForClosing(this); CellConstraints cc = new CellConstraints(); FormLayout layout = new FormLayout("5dlu,pref:grow", "pref,5dlu,pref,2dlu,pref,5dlu,pref"); PanelBuilder pb = new PanelBuilder(layout, content); pb.setBorder(Borders.DLU4_BORDER);/*from ww w. j a va2 s. c o m*/ pb.addSeparator(mLocalizer.msg("fonts", "Fonts"), cc.xyw(1, 1, 2)); mTitleFontPanel = new FontChooserPanel(mLocalizer.msg("title", "Title"), titleFont); mDescriptionFontPanel = new FontChooserPanel(mLocalizer.msg("description", "Description"), descriptionFont); if (dateFont != null) { mDateFontPanel = new FontChooserPanel(mLocalizer.msg("date", "Date"), dateFont); } int y = 3; pb.add(mTitleFontPanel, cc.xy(2, y++)); pb.add(mDescriptionFontPanel, cc.xy(2, ++y)); if (dateFont != null) { layout.insertRow(++y, RowSpec.decode("2dlu")); layout.insertRow(++y, RowSpec.decode("pref")); content.add(mDateFontPanel, cc.xy(2, y)); } y++; JPanel btnPn = new JPanel(new FlowLayout()); JButton okBt = new JButton(Localizer.getLocalization(Localizer.I18N_OK)); JButton cancelBt = new JButton(Localizer.getLocalization(Localizer.I18N_CANCEL)); btnPn.add(okBt); btnPn.add(cancelBt); okBt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { mResult = OK; setVisible(false); } }); cancelBt.addActionListener(new ActionListener() { public void actionPerformed(ActionEvent e) { close(); } }); content.add(btnPn, cc.xyw(1, ++y, 2)); mResult = CANCEL; pack(); }