Search in sources :

Example 6 with ButtonBarBuilder

use of com.jgoodies.forms.builder.ButtonBarBuilder in project jabref by JabRef.

the class ExternalFileTypeEntryEditor method init.

private void init(ExternalFileType inEntry) {
    entry = inEntry;
    icon.setText(null);
    ButtonGroup bg = new ButtonGroup();
    bg.add(useDefault);
    bg.add(other);
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:150dlu, 4dlu, fill:pref", "p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p, 2dlu, p"));
    builder.add(Localization.lang("Icon")).xy(1, 1);
    builder.add(icon).xy(3, 1);
    builder.add(Localization.lang("Name")).xy(1, 3);
    builder.add(name).xy(3, 3);
    builder.add(Localization.lang("Extension")).xy(1, 5);
    builder.add(extension).xy(3, 5);
    builder.add(Localization.lang("MIME type")).xy(1, 7);
    builder.add(mimeType).xy(3, 7);
    builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    builder.add(Localization.lang("Application")).xy(1, 9);
    JButton browseBut = new JButton(Localization.lang("Browse"));
    if (OS.WINDOWS) {
        builder.add(useDefault).xy(3, 9);
        builder.appendRows("2dlu, p");
        JPanel p1 = new JPanel();
        builder.add(p1).xy(1, 11);
        JPanel p2 = new JPanel();
        application.setPreferredSize(new Dimension(300, application.getPreferredSize().height));
        BorderLayout bl = new BorderLayout();
        bl.setHgap(4);
        p2.setLayout(bl);
        p2.add(other, BorderLayout.WEST);
        p2.add(application, BorderLayout.CENTER);
        builder.add(p2).xy(3, 11);
        builder.add(browseBut).xy(5, 11);
    } else {
        builder.add(application).xy(3, 9);
        builder.add(browseBut).xy(5, 9);
    }
    ButtonBarBuilder bb = new ButtonBarBuilder();
    bb.addGlue();
    bb.addButton(ok);
    bb.addButton(cancel);
    bb.addGlue();
    ok.addActionListener(e -> {
        okPressed = true;
        storeSettings(ExternalFileTypeEntryEditor.this.entry);
        diag.dispose();
    });
    cancel.addActionListener(e -> diag.dispose());
    if (OS.WINDOWS) {
        application.getDocument().addDocumentListener(new DocumentListener() {

            private void handle() {
                if (application.getText().isEmpty()) {
                    useDefault.setSelected(true);
                } else {
                    other.setSelected(true);
                }
            }

            @Override
            public void insertUpdate(DocumentEvent documentEvent) {
                handle();
            }

            @Override
            public void removeUpdate(DocumentEvent documentEvent) {
                handle();
            }

            @Override
            public void changedUpdate(DocumentEvent documentEvent) {
                handle();
            }
        });
    }
    String title = editFileTitle;
    if (entry.getName().isEmpty()) {
        title = newFileTitle;
    }
    if (dParent == null) {
        diag = new JDialog(fParent, title, true);
    } else {
        diag = new JDialog(dParent, title, true);
    }
    diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
    diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    diag.pack();
    browseBut.addActionListener(browsePressed);
    if (dParent == null) {
        diag.setLocationRelativeTo(fParent);
    } else {
        diag.setLocationRelativeTo(dParent);
    }
    setValues(entry);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JPanel(javax.swing.JPanel) DocumentListener(javax.swing.event.DocumentListener) JButton(javax.swing.JButton) Dimension(java.awt.Dimension) DocumentEvent(javax.swing.event.DocumentEvent) BorderLayout(java.awt.BorderLayout) ButtonGroup(javax.swing.ButtonGroup) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JDialog(javax.swing.JDialog)

Example 7 with ButtonBarBuilder

use of com.jgoodies.forms.builder.ButtonBarBuilder in project jabref by JabRef.

the class MergeEntriesDialog method init.

/**
     * Sets up the dialog
     *
     * @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("Canceled merging entries"));
        dispose();
    });
    JButton replaceentries = new JButton(MERGE_ENTRIES);
    replaceentries.setActionCommand("replace");
    replaceentries.addActionListener(e -> {
        BibEntry mergedEntry = mergeEntries.getMergeEntry();
        panel.insertEntry(mergedEntry);
        ce.addEdit(new UndoableInsertEntry(panel.getDatabase(), mergedEntry, panel));
        ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), one, panel));
        panel.getDatabase().removeEntry(one);
        ce.addEdit(new UndoableRemoveEntry(panel.getDatabase(), two, panel));
        panel.getDatabase().removeEntry(two);
        ce.end();
        panel.getUndoManager().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));
    WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
    pw.displayWindowAtStoredLocation();
    // Show what we've got
    setVisible(true);
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) BibEntry(org.jabref.model.entry.BibEntry) NamedCompound(org.jabref.gui.undo.NamedCompound) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JButton(javax.swing.JButton) UndoableRemoveEntry(org.jabref.gui.undo.UndoableRemoveEntry) WindowLocation(org.jabref.gui.util.WindowLocation) JSeparator(javax.swing.JSeparator) UndoableInsertEntry(org.jabref.gui.undo.UndoableInsertEntry)

Example 8 with ButtonBarBuilder

use of com.jgoodies.forms.builder.ButtonBarBuilder in project jabref by JabRef.

the class MergeFetchedEntryDialog method init.

/**
     * Sets up the dialog
     */
private void init() {
    mergeEntries = new MergeEntries(this.originalEntry, this.fetchedEntry, Localization.lang("Original entry"), Localization.lang("Entry from %0", type), panel.getBibDatabaseContext().getMode());
    // Create undo-compound
    ce = new NamedCompound(Localization.lang("Merge entry with %0 information", type));
    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(new CancelAction());
    JButton replaceEntry = new JButton(new ReplaceAction());
    bb.addButton(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));
    WindowLocation pw = new WindowLocation(this, JabRefPreferences.MERGEENTRIES_POS_X, JabRefPreferences.MERGEENTRIES_POS_Y, JabRefPreferences.MERGEENTRIES_SIZE_X, JabRefPreferences.MERGEENTRIES_SIZE_Y);
    pw.displayWindowAtStoredLocation();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) NamedCompound(org.jabref.gui.undo.NamedCompound) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) JButton(javax.swing.JButton) WindowLocation(org.jabref.gui.util.WindowLocation) JSeparator(javax.swing.JSeparator)

Example 9 with ButtonBarBuilder

use of com.jgoodies.forms.builder.ButtonBarBuilder in project jabref by JabRef.

the class NewProtectedTermsFileDialog method setupDialog.

private void setupDialog() {
    JButton browse = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.TERMS).withDefaultExtension(FileExtensions.TERMS).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browse.addActionListener(e -> {
        Optional<Path> file = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
        file.ifPresent(f -> newFile.setText(f.toAbsolutePath().toString()));
    });
    // Build content panel
    FormBuilder builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:100dlu:grow, 4dlu, pref", "p, 4dlu, p, 4dlu, p"));
    builder.add(Localization.lang("Description")).xy(1, 1);
    builder.add(newDescription).xyw(3, 1, 3);
    builder.add(Localization.lang("File")).xy(1, 3);
    builder.add(newFile).xy(3, 3);
    builder.add(browse).xy(5, 3);
    builder.add(enabled).xyw(1, 5, 5);
    enabled.setSelected(true);
    builder.padding("10dlu, 10dlu, 10dlu, 10dlu");
    getContentPane().add(builder.build(), BorderLayout.CENTER);
    // Buttons
    ButtonBarBuilder bb = new ButtonBarBuilder();
    JButton addOKButton = new JButton(Localization.lang("OK"));
    JButton addCancelButton = new JButton(Localization.lang("Cancel"));
    bb.addGlue();
    bb.addButton(addOKButton);
    bb.addButton(addCancelButton);
    bb.addGlue();
    bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
    getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
    addOKButton.addActionListener(e -> {
        addOKPressed = true;
        loader.addNewProtectedTermsList(newDescription.getText(), newFile.getText(), enabled.isSelected());
        dispose();
    });
    Action cancelAction = new AbstractAction() {

        @Override
        public void actionPerformed(ActionEvent e) {
            addOKPressed = false;
            dispose();
        }
    };
    addCancelButton.addActionListener(cancelAction);
    // Key bindings:
    bb.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW).put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
    bb.getPanel().getActionMap().put("close", cancelAction);
    pack();
}
Also used : Path(java.nio.file.Path) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) Action(javax.swing.Action) AbstractAction(javax.swing.AbstractAction) ActionEvent(java.awt.event.ActionEvent) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) FXDialogService(org.jabref.gui.FXDialogService) ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder) AbstractAction(javax.swing.AbstractAction)

Example 10 with ButtonBarBuilder

use of com.jgoodies.forms.builder.ButtonBarBuilder in project jgnash by ccavanaugh.

the class StaticUIMethods method buildHelpBar.

/**
     * Builds and returns a right aligned bar with help and other buttons.
     *
     * @param help    the help button to add on the left side
     * @param buttons an array of buttons to add
     * @return a right aligned button bar with the given buttons
     */
@SuppressWarnings("ConfusingArgumentToVarargsMethod")
public static JPanel buildHelpBar(final JButton help, final AbstractButton... buttons) {
    ButtonBarBuilder builder = new ButtonBarBuilder();
    builder.addButton(help);
    builder.addUnrelatedGap();
    builder.addGlue();
    builder.addButton(buttons);
    return builder.getPanel();
}
Also used : ButtonBarBuilder(com.jgoodies.forms.builder.ButtonBarBuilder)

Aggregations

ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)34 FormLayout (com.jgoodies.forms.layout.FormLayout)17 JButton (javax.swing.JButton)17 ActionEvent (java.awt.event.ActionEvent)14 AbstractAction (javax.swing.AbstractAction)14 JScrollPane (javax.swing.JScrollPane)13 ActionMap (javax.swing.ActionMap)11 InputMap (javax.swing.InputMap)11 JDialog (javax.swing.JDialog)11 JPanel (javax.swing.JPanel)9 FormBuilder (com.jgoodies.forms.builder.FormBuilder)8 BorderLayout (java.awt.BorderLayout)8 Action (javax.swing.Action)8 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)6 Dimension (java.awt.Dimension)6 ButtonGroup (javax.swing.ButtonGroup)5 JTextField (javax.swing.JTextField)4 NamedCompound (org.jabref.gui.undo.NamedCompound)4 WindowLocation (org.jabref.gui.util.WindowLocation)4 Insets (java.awt.Insets)3