use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.
the class ManageKeywordsAction method createDialog.
private void createDialog() {
if (diag != null) {
return;
}
// keyword to add
JTextField keyword = new JTextField();
keywordListModel = new DefaultListModel<>();
JList<Keyword> keywordList = new JList<>(keywordListModel);
keywordList.setVisibleRowCount(8);
JScrollPane kPane = new JScrollPane(keywordList);
diag = new JDialog(frame, Localization.lang("Manage keywords"), true);
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
JButton add = new JButton(Localization.lang("Add"));
JButton remove = new JButton(Localization.lang("Remove"));
keywordList.setVisibleRowCount(10);
intersectKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ALL entries"));
mergeKeywords = new JRadioButton(Localization.lang("Display keywords appearing in ANY entry"));
ButtonGroup group = new ButtonGroup();
group.add(intersectKeywords);
group.add(mergeKeywords);
ActionListener stateChanged = e -> fillKeyWordList();
intersectKeywords.addActionListener(stateChanged);
mergeKeywords.addActionListener(stateChanged);
intersectKeywords.setSelected(true);
FormBuilder builder = FormBuilder.create().layout(new FormLayout("fill:200dlu:grow, 4dlu, fill:pref", "pref, 2dlu, pref, 1dlu, pref, 2dlu, fill:100dlu:grow, 4dlu, pref, 4dlu, pref, "));
builder.addSeparator(Localization.lang("Keywords of selected entries")).xyw(1, 1, 3);
builder.add(intersectKeywords).xyw(1, 3, 3);
builder.add(mergeKeywords).xyw(1, 5, 3);
builder.add(kPane).xywh(1, 7, 1, 3);
builder.add(remove).xy(3, 9);
builder.add(keyword).xy(1, 11);
builder.add(add).xy(3, 11);
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
ok.addActionListener(e -> {
canceled = false;
diag.dispose();
});
Action cancelAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
canceled = true;
diag.dispose();
}
};
cancel.addActionListener(cancelAction);
final ActionListener addActionListener = arg0 -> addButtonActionListener(keyword);
add.addActionListener(addActionListener);
final ActionListener removeActionListenter = arg0 -> {
List<Keyword> values = keywordList.getSelectedValuesList();
for (Keyword val : values) {
keywordListModel.removeElement(val);
}
};
remove.addActionListener(removeActionListenter);
keywordList.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent arg0) {
// Do nothing
}
@Override
public void keyReleased(KeyEvent arg0) {
// Do nothing
}
@Override
public void keyPressed(KeyEvent arg0) {
if (arg0.getKeyCode() == KeyEvent.VK_DELETE) {
removeActionListenter.actionPerformed(null);
}
}
});
AutoCompleter<String> autoComp = JabRefGUI.getMainFrame().getCurrentBasePanel().getAutoCompleters().get(FieldName.KEYWORDS);
AutoCompleteListener acl = new AutoCompleteListener(autoComp);
keyword.addKeyListener(acl);
keyword.addFocusListener(acl);
keyword.addKeyListener(new KeyListener() {
@Override
public void keyTyped(KeyEvent e) {
// Do nothing
}
@Override
public void keyReleased(KeyEvent e) {
// Do nothing
}
@Override
public void keyPressed(KeyEvent e) {
if (e.getKeyCode() == KeyEvent.VK_ENTER) {
addActionListener.actionPerformed(null);
}
}
});
// Key bindings:
ActionMap am = builder.getPanel().getActionMap();
InputMap im = builder.getPanel().getInputMap(JComponent.WHEN_IN_FOCUSED_WINDOW);
im.put(Globals.getKeyPrefs().getKey(KeyBinding.CLOSE_DIALOG), "close");
am.put("close", cancelAction);
diag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
diag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
}
use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.
the class SaveDatabaseAction method saveDatabase.
private boolean saveDatabase(File file, boolean selectedOnly, Charset encoding) throws SaveException {
SaveSession session;
// block user input
frame.block();
try {
SavePreferences prefs = SavePreferences.loadForSaveFromPreferences(Globals.prefs).withEncoding(encoding);
BibtexDatabaseWriter<SaveSession> databaseWriter = new BibtexDatabaseWriter<>(FileSaveSession::new);
if (selectedOnly) {
session = databaseWriter.savePartOfDatabase(panel.getBibDatabaseContext(), panel.getSelectedEntries(), prefs);
} else {
session = databaseWriter.saveDatabase(panel.getBibDatabaseContext(), prefs);
}
panel.registerUndoableChanges(session);
} catch (UnsupportedCharsetException ex) {
JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + Localization.lang("Character encoding '%0' is not supported.", encoding.displayName()), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
// FIXME: rethrow anti-pattern
throw new SaveException("rt");
} catch (SaveException ex) {
if (ex == SaveException.FILE_LOCKED) {
throw ex;
}
if (ex.specificEntry()) {
BibEntry entry = ex.getEntry();
// Error occured during processing of an entry. Highlight it!
panel.highlightEntry(entry);
} else {
LOGGER.error("A problem occured when trying to save the file", ex);
}
JOptionPane.showMessageDialog(frame, Localization.lang("Could not save file.") + ".\n" + ex.getMessage(), Localization.lang("Save library"), JOptionPane.ERROR_MESSAGE);
// FIXME: rethrow anti-pattern
throw new SaveException("rt");
} finally {
// re-enable user input
frame.unblock();
}
// handle encoding problems
boolean success = true;
if (!session.getWriter().couldEncodeAll()) {
FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref", "pref, 4dlu, pref"));
JTextArea ta = new JTextArea(session.getWriter().getProblemCharacters());
ta.setEditable(false);
builder.add(Localization.lang("The chosen encoding '%0' could not encode the following characters:", session.getEncoding().displayName())).xy(1, 1);
builder.add(ta).xy(3, 1);
builder.add(Localization.lang("What do you want to do?")).xy(1, 3);
String tryDiff = Localization.lang("Try different encoding");
int answer = JOptionPane.showOptionDialog(frame, builder.getPanel(), Localization.lang("Save library"), JOptionPane.YES_NO_CANCEL_OPTION, JOptionPane.WARNING_MESSAGE, null, new String[] { Localization.lang("Save"), tryDiff, Localization.lang("Cancel") }, tryDiff);
if (answer == JOptionPane.NO_OPTION) {
// The user wants to use another encoding.
Object choice = JOptionPane.showInputDialog(frame, Localization.lang("Select encoding"), Localization.lang("Save library"), JOptionPane.QUESTION_MESSAGE, null, Encodings.ENCODINGS_DISPLAYNAMES, encoding);
if (choice == null) {
success = false;
} else {
Charset newEncoding = Charset.forName((String) choice);
return saveDatabase(file, selectedOnly, newEncoding);
}
} else if (answer == JOptionPane.CANCEL_OPTION) {
success = false;
}
}
// backup file?
try {
if (success) {
session.commit(file.toPath());
// Make sure to remember which encoding we used.
panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
} else {
session.cancel();
}
} catch (SaveException e) {
int ans = JOptionPane.showConfirmDialog(null, Localization.lang("Save failed during backup creation") + ". " + Localization.lang("Save without backup?"), Localization.lang("Unable to create backup"), JOptionPane.YES_NO_OPTION);
if (ans == JOptionPane.YES_OPTION) {
session.setUseBackup(false);
session.commit(file.toPath());
panel.getBibDatabaseContext().getMetaData().setEncoding(encoding, ChangePropagation.DO_NOT_POST_EVENT);
} else {
success = false;
}
}
return success;
}
use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.
the class OpenOfficePanel method showManualConnectionDialog.
private void showManualConnectionDialog() {
dialogOkPressed = false;
final JDialog cDiag = new JDialog(frame, Localization.lang("Set connection parameters"), true);
final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
final DialogService dirDialog = new FXDialogService();
DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
DialogService fileDialog = new FXDialogService();
// Path fields
final JTextField ooPath = new JTextField(30);
JButton browseOOPath = new JButton(Localization.lang("Browse"));
ooPath.setText(preferences.getInstallationPath());
browseOOPath.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooPath.setText(f.toAbsolutePath().toString())));
final JTextField ooExec = new JTextField(30);
JButton browseOOExec = new JButton(Localization.lang("Browse"));
ooExec.setText(preferences.getExecutablePath());
browseOOExec.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> fileDialog.showFileOpenDialog(fileDialogConfiguration)).ifPresent(f -> ooExec.setText(f.toAbsolutePath().toString())));
final JTextField ooJars = new JTextField(30);
ooJars.setText(preferences.getJarsPath());
JButton browseOOJars = new JButton(Localization.lang("Browse"));
browseOOJars.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> dirDialog.showDirectorySelectionDialog(dirDialogConfiguration)).ifPresent(f -> ooJars.setText(f.toAbsolutePath().toString())));
FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, fill:pref", "pref"));
if (OS.WINDOWS || OS.OS_X) {
builder.add(Localization.lang("Path to OpenOffice/LibreOffice directory")).xy(1, 1);
builder.add(ooPath).xy(3, 1);
builder.add(browseOOPath).xy(5, 1);
} else {
builder.add(Localization.lang("Path to OpenOffice/LibreOffice executable")).xy(1, 1);
builder.add(ooExec).xy(3, 1);
builder.add(browseOOExec).xy(5, 1);
builder.appendRows("4dlu, pref");
builder.add(Localization.lang("Path to OpenOffice/LibreOffice library dir")).xy(1, 3);
builder.add(ooJars).xy(3, 3);
builder.add(browseOOJars).xy(5, 3);
}
builder.padding("5dlu, 5dlu, 5dlu, 5dlu");
cDiag.getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
// Buttons
JButton ok = new JButton(Localization.lang("OK"));
JButton cancel = new JButton(Localization.lang("Cancel"));
ok.addActionListener(e -> {
if (OS.WINDOWS || OS.OS_X) {
preferences.updateConnectionParams(ooPath.getText(), ooPath.getText(), ooPath.getText());
} else {
preferences.updateConnectionParams(ooPath.getText(), ooExec.getText(), ooJars.getText());
}
dialogOkPressed = true;
cDiag.dispose();
});
cancel.addActionListener(e -> cDiag.dispose());
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addRelatedGap();
bb.addButton(ok);
bb.addButton(cancel);
bb.addGlue();
bb.padding("5dlu, 5dlu, 5dlu, 5dlu");
cDiag.getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
// Finish and show dirDialog
cDiag.pack();
cDiag.setLocationRelativeTo(frame);
cDiag.setVisible(true);
}
use of com.jgoodies.forms.builder.FormBuilder in project jabref by JabRef.
the class FieldFormatterCleanupsPanel method buildLayout.
private void buildLayout(List<FieldFormatterCleanup> actionsToDisplay) {
FormBuilder builder = FormBuilder.create().layout(new FormLayout("left:pref, 13dlu, left:pref:grow, 4dlu, pref, 4dlu, pref", "pref, 2dlu, pref, 2dlu, pref, 4dlu, pref, 2dlu, fill:pref:grow, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu"));
builder.add(cleanupEnabled).xyw(1, 1, 7);
actionsList = new JList<>(new CleanupActionsListModel(actionsToDisplay));
actionsList.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
actionsList.addMouseMotionListener(new MouseMotionAdapter() {
@Override
public void mouseMoved(MouseEvent e) {
super.mouseMoved(e);
CleanupActionsListModel m = (CleanupActionsListModel) actionsList.getModel();
int index = actionsList.locationToIndex(e.getPoint());
if (index > -1) {
actionsList.setToolTipText(m.getElementAt(index).getFormatter().getDescription());
}
}
});
actionsList.getModel().addListDataListener(new ListDataListener() {
@Override
public void intervalRemoved(ListDataEvent e) {
//index0 is sufficient, because of SingleSelection
if (e.getIndex0() == 0) {
//when an item gets deleted, the next one becomes the new 0
actionsList.setSelectedIndex(e.getIndex0());
}
if (e.getIndex0() > 0) {
actionsList.setSelectedIndex(e.getIndex0() - 1);
}
}
@Override
public void intervalAdded(ListDataEvent e) {
//empty, not needed
}
@Override
public void contentsChanged(ListDataEvent e) {
//empty, not needed
}
});
builder.add(actionsList).xyw(3, 5, 5);
resetButton = new JButton(Localization.lang("Reset"));
resetButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).reset(defaultFormatters));
BibDatabaseContext databaseContext = JabRefGUI.getMainFrame().getCurrentBasePanel().getDatabaseContext();
recommendButton = new JButton(Localization.lang("Recommended for %0", databaseContext.getMode().getFormattedName()));
boolean isBiblatex = databaseContext.isBiblatexMode();
recommendButton.addActionListener(e -> {
if (isBiblatex) {
((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBLATEX_ACTIONS);
} else {
((CleanupActionsListModel) actionsList.getModel()).reset(Cleanups.RECOMMEND_BIBTEX_ACTIONS);
}
});
removeButton = new JButton(Localization.lang("Remove selected"));
removeButton.addActionListener(e -> ((CleanupActionsListModel) actionsList.getModel()).removeAtIndex(actionsList.getSelectedIndex()));
builder.add(removeButton).xy(7, 11);
builder.add(resetButton).xy(3, 11);
builder.add(recommendButton).xy(5, 11);
builder.add(getSelectorPanel()).xyw(3, 15, 5);
makeDescriptionTextAreaLikeJLabel();
builder.add(descriptionAreaText).xyw(3, 17, 5);
this.setLayout(new BorderLayout());
this.add(builder.getPanel(), BorderLayout.WEST);
updateDescription();
// make sure the layout is set according to the checkbox
cleanupEnabled.addActionListener(new EnablementStatusListener(fieldFormatterCleanups.isEnabled()));
cleanupEnabled.setSelected(fieldFormatterCleanups.isEnabled());
}
use of com.jgoodies.forms.builder.FormBuilder 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);
}
Aggregations