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);
}
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();
}
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());
}
}
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();
}
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();
}
Aggregations