Search in sources :

Example 26 with FormLayout

use of com.jgoodies.forms.layout.FormLayout 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 27 with FormLayout

use of com.jgoodies.forms.layout.FormLayout 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 28 with FormLayout

use of com.jgoodies.forms.layout.FormLayout in project jabref by JabRef.

the class DetectOpenOfficeInstallation method chooseAmongInstallations.

private Optional<Path> chooseAmongInstallations(List<Path> installDirs) {
    if (installDirs.isEmpty()) {
        return Optional.empty();
    }
    if (installDirs.size() == 1) {
        return Optional.of(installDirs.get(0).toAbsolutePath());
    }
    // Otherwise more than one installation was found, select among them
    DefaultListModel<File> mod = new DefaultListModel<>();
    for (Path tmpfile : installDirs) {
        mod.addElement(tmpfile.toFile());
    }
    JList<File> fileList = new JList<>(mod);
    fileList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    fileList.setSelectedIndex(0);
    FormBuilder builder = FormBuilder.create().layout(new FormLayout("pref:grow", "pref, 2dlu, pref, 4dlu, pref"));
    builder.add(Localization.lang("Found more than one OpenOffice/LibreOffice executable.")).xy(1, 1);
    builder.add(Localization.lang("Please choose which one to connect to:")).xy(1, 3);
    builder.add(fileList).xy(1, 5);
    int answer = JOptionPane.showConfirmDialog(null, builder.getPanel(), Localization.lang("Choose OpenOffice/LibreOffice executable"), JOptionPane.OK_CANCEL_OPTION);
    if (answer == JOptionPane.CANCEL_OPTION) {
        return Optional.empty();
    } else {
        return Optional.of(fileList.getSelectedValue().toPath());
    }
}
Also used : Path(java.nio.file.Path) FormLayout(com.jgoodies.forms.layout.FormLayout) FormBuilder(com.jgoodies.forms.builder.FormBuilder) DefaultListModel(javax.swing.DefaultListModel) File(java.io.File) JList(javax.swing.JList)

Example 29 with FormLayout

use of com.jgoodies.forms.layout.FormLayout 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 30 with FormLayout

use of com.jgoodies.forms.layout.FormLayout in project jabref by JabRef.

the class AbstractPushToApplication method initSettingsPanel.

/**
     * Create a FormBuilder, fill it with a textbox for the path and store the JPanel in settings
     */
protected void initSettingsPanel() {
    builder = FormBuilder.create();
    builder.layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "p"));
    StringBuilder label = new StringBuilder(Localization.lang("Path to %0", getApplicationName()));
    // In case the application name and the actual command is not the same, add the command in brackets
    if (getCommandName() == null) {
        label.append(':');
    } else {
        label.append(" (").append(getCommandName()).append("):");
    }
    builder.add(label.toString()).xy(1, 1);
    builder.add(path).xy(3, 1);
    JButton browse = new JButton(Localization.lang("Browse"));
    FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
    DialogService ds = new FXDialogService();
    browse.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration)).ifPresent(f -> path.setText(f.toAbsolutePath().toString())));
    builder.add(browse).xy(5, 1);
    settings = builder.build();
}
Also used : FormLayout(com.jgoodies.forms.layout.FormLayout) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration) JTextField(javax.swing.JTextField) BibDatabase(org.jabref.model.database.BibDatabase) BibEntry(org.jabref.model.entry.BibEntry) DialogService(org.jabref.gui.DialogService) IOException(java.io.IOException) FXDialogService(org.jabref.gui.FXDialogService) JabRefPreferences(org.jabref.preferences.JabRefPreferences) BasePanel(org.jabref.gui.BasePanel) Globals(org.jabref.Globals) DefaultTaskExecutor(org.jabref.gui.util.DefaultTaskExecutor) List(java.util.List) FormLayout(com.jgoodies.forms.layout.FormLayout) OS(org.jabref.logic.util.OS) MetaData(org.jabref.model.metadata.MetaData) Localization(org.jabref.logic.l10n.Localization) Log(org.apache.commons.logging.Log) LogFactory(org.apache.commons.logging.LogFactory) JPanel(javax.swing.JPanel) DialogService(org.jabref.gui.DialogService) FXDialogService(org.jabref.gui.FXDialogService) FormBuilder(com.jgoodies.forms.builder.FormBuilder) JButton(javax.swing.JButton) FileDialogConfiguration(org.jabref.gui.util.FileDialogConfiguration)

Aggregations

FormLayout (com.jgoodies.forms.layout.FormLayout)224 DefaultFormBuilder (com.jgoodies.forms.builder.DefaultFormBuilder)112 JPanel (javax.swing.JPanel)82 CellConstraints (com.jgoodies.forms.layout.CellConstraints)81 JScrollPane (javax.swing.JScrollPane)57 JLabel (javax.swing.JLabel)40 JButton (javax.swing.JButton)28 FormBuilder (com.jgoodies.forms.builder.FormBuilder)19 ButtonBarBuilder (com.jgoodies.forms.builder.ButtonBarBuilder)18 JCheckBox (javax.swing.JCheckBox)13 DatePanel (jgnash.ui.components.DatePanel)11 ActionEvent (java.awt.event.ActionEvent)8 AbstractAction (javax.swing.AbstractAction)8 JDialog (javax.swing.JDialog)8 JRadioButton (javax.swing.JRadioButton)8 RowSpec (com.jgoodies.forms.layout.RowSpec)7 BorderLayout (java.awt.BorderLayout)7 LocalDate (java.time.LocalDate)7 List (java.util.List)7 Action (javax.swing.Action)7