use of org.jabref.gui.FXDialogService 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();
}
use of org.jabref.gui.FXDialogService in project jabref by JabRef.
the class FileLinksUpgradeWarning method performAction.
/**
* This method presents a dialog box explaining and offering to make the
* changes. If the user confirms, the changes are performed.
* @param panel
* @param parserResult
*/
@Override
public void performAction(BasePanel panel, ParserResult parserResult) {
if (!isThereSomethingToBeDone()) {
// Nothing to do, just return.
return;
}
JCheckBox changeSettings = new JCheckBox(Localization.lang("Change table column and General fields settings to use the new feature"), offerChangeSettings);
JCheckBox changeDatabase = new JCheckBox(Localization.lang("Upgrade old external file links to use the new feature"), offerChangeDatabase);
JCheckBox setFileDir = new JCheckBox(Localization.lang("Set main external file directory") + ":", offerSetFileDir);
JTextField fileDir = new JTextField(30);
JCheckBox doNotShowDialog = new JCheckBox(Localization.lang("Do not show these options in the future"), false);
JPanel message = new JPanel();
FormBuilder formBuilder = FormBuilder.create().layout(new FormLayout("left:pref", "p"));
// Keep the formatting of these lines. Otherwise, strings have to be translated again.
// See updated JabRef_en.properties modifications by python syncLang.py -s -u
int row = 1;
formBuilder.add(new JLabel("<html>" + Localization.lang("This library uses outdated file links.") + "<br><br>" + Localization.lang("JabRef no longer supports 'ps' or 'pdf' fields.<br>File links are now stored in the 'file' field and files are stored in an external file directory.<br>To make use of this feature, JabRef needs to upgrade file links.<br><br>") + "<p>" + Localization.lang("Do you want JabRef to do the following operations?") + "</html>")).xy(1, row);
if (offerChangeSettings) {
formBuilder.appendRows("2dlu, p");
row += 2;
formBuilder.add(changeSettings).xy(1, row);
}
if (offerChangeDatabase) {
formBuilder.appendRows("2dlu, p");
row += 2;
formBuilder.add(changeDatabase).xy(1, row);
}
if (offerSetFileDir) {
if (Globals.prefs.hasKey(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX)) {
fileDir.setText(Globals.prefs.get(FieldName.PDF + FileDirectoryPreferences.DIR_SUFFIX));
} else {
fileDir.setText(Globals.prefs.get(FieldName.PS + FileDirectoryPreferences.DIR_SUFFIX));
}
JPanel builderPanel = new JPanel();
builderPanel.add(setFileDir);
builderPanel.add(fileDir);
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 -> fileDir.setText(f.toAbsolutePath().toString()))));
builderPanel.add(browse);
formBuilder.appendRows("2dlu, p");
row += 2;
formBuilder.add(builderPanel).xy(1, row);
}
formBuilder.appendRows("6dlu, p");
formBuilder.add(doNotShowDialog).xy(1, row + 2);
message.add(formBuilder.build());
int answer = JOptionPane.showConfirmDialog(panel.frame(), message, Localization.lang("Upgrade file"), JOptionPane.YES_NO_OPTION);
if (doNotShowDialog.isSelected()) {
Globals.prefs.putBoolean(JabRefPreferences.SHOW_FILE_LINKS_UPGRADE_WARNING, false);
}
if (answer == JOptionPane.YES_OPTION) {
makeChanges(panel, parserResult, changeSettings.isSelected(), changeDatabase.isSelected(), setFileDir.isSelected() ? fileDir.getText() : null);
}
}
use of org.jabref.gui.FXDialogService in project jabref by JabRef.
the class EntryEditorTab method setupPanel.
private Region setupPanel(JabRefFrame frame, BasePanel bPanel, boolean addKeyField, boolean compressed, String title) {
setupKeyBindings(panel.getInputMap(JComponent.WHEN_FOCUSED), panel.getActionMap());
panel.setName(title);
editors.clear();
List<Label> labels = new ArrayList<>();
for (String fieldName : fields) {
// TODO: Reenable/migrate this
// Store the editor for later reference:
/*
FieldEditor fieldEditor;
int defaultHeight;
int wHeight = (int) (50.0 * InternalBibtexFields.getFieldWeight(field));
if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.SINGLE_ENTRY_LINK)) {
fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
true);
defaultHeight = 0;
} else if (InternalBibtexFields.getFieldProperties(field).contains(FieldProperty.MULTIPLE_ENTRY_LINK)) {
fieldEditor = new EntryLinkListEditor(frame, bPanel.getBibDatabaseContext(), field, null, parent,
false);
defaultHeight = 0;
} else {
fieldEditor = new TextArea(field, null, getPrompt(field));
//parent.addSearchListener((TextArea) fieldEditor);
defaultHeight = fieldEditor.getPane().getPreferredSize().height;
}
Optional<JComponent> extra = parent.getExtra(fieldEditor);
// Add autocompleter listener, if required for this field:
/*
AutoCompleter<String> autoCompleter = bPanel.getAutoCompleters().get(field);
AutoCompleteListener autoCompleteListener = null;
if (autoCompleter != null) {
autoCompleteListener = new AutoCompleteListener(autoCompleter);
}
setupJTextComponent(fieldEditor.getTextComponent(), autoCompleteListener);
fieldEditor.setAutoCompleteListener(autoCompleteListener);
*/
FieldEditorFX fieldEditor = FieldEditors.getForField(fieldName, Globals.taskExecutor, new FXDialogService(), Globals.journalAbbreviationLoader, Globals.prefs.getJournalAbbreviationPreferences(), Globals.prefs, bPanel.getBibDatabaseContext(), entry.getType());
fieldEditor.bindToEntry(entry);
editors.put(fieldName, fieldEditor);
/*
// TODO: Reenable this
if (i == 0) {
activeField = fieldEditor;
}
*/
/*
// TODO: Reenable this
if (!compressed) {
fieldEditor.getPane().setPreferredSize(new Dimension(100, Math.max(defaultHeight, wHeight)));
}
*/
/*
// TODO: Reenable content selector
if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(editor.getFieldName()).isEmpty()) {
FieldContentSelector ws = new FieldContentSelector(frame, panel, frame, editor, storeFieldAction, false,
", ");
contentSelectors.add(ws);
controls.add(ws, BorderLayout.NORTH);
}
//} else if (!panel.getBibDatabaseContext().getMetaData().getContentSelectorValuesForField(fieldName).isEmpty()) {
//return FieldExtraComponents.getSelectorExtraComponent(frame, panel, editor, contentSelectors, storeFieldAction);
*/
labels.add(new FieldNameLabel(fieldName));
}
GridPane gridPane = new GridPane();
gridPane.setPrefSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
gridPane.setMaxSize(Double.POSITIVE_INFINITY, Double.POSITIVE_INFINITY);
gridPane.getStyleClass().add("editorPane");
ColumnConstraints columnExpand = new ColumnConstraints();
columnExpand.setHgrow(Priority.ALWAYS);
ColumnConstraints columnDoNotContract = new ColumnConstraints();
columnDoNotContract.setMinWidth(Region.USE_PREF_SIZE);
int rows;
if (compressed) {
rows = (int) Math.ceil((double) fields.size() / 2);
addColumn(gridPane, 0, labels.subList(0, rows));
addColumn(gridPane, 3, labels.subList(rows, labels.size()));
addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode).limit(rows));
addColumn(gridPane, 4, editors.values().stream().map(FieldEditorFX::getNode).skip(rows));
gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand, new ColumnConstraints(10), columnDoNotContract, columnExpand);
} else {
rows = fields.size();
addColumn(gridPane, 0, labels);
addColumn(gridPane, 1, editors.values().stream().map(FieldEditorFX::getNode));
gridPane.getColumnConstraints().addAll(columnDoNotContract, columnExpand);
}
RowConstraints rowExpand = new RowConstraints();
rowExpand.setVgrow(Priority.ALWAYS);
if (rows == 0) {
rowExpand.setPercentHeight(100);
} else {
rowExpand.setPercentHeight(100 / rows);
}
for (int i = 0; i < rows; i++) {
gridPane.getRowConstraints().add(rowExpand);
}
return gridPane;
}
use of org.jabref.gui.FXDialogService in project jabref by JabRef.
the class DatabasePropertiesDialog method init.
private void init() {
DirectoryDialogConfiguration directoryDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();
JButton browseFile = new JButton(Localization.lang("Browse"));
JButton browseFileIndv = new JButton(Localization.lang("Browse"));
browseFile.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showDirectorySelectionDialog(directoryDialogConfiguration)).ifPresent(f -> fileDir.setText(f.toAbsolutePath().toString())));
browseFileIndv.addActionListener(e -> DefaultTaskExecutor.runInJavaFXThread(() -> ds.showDirectorySelectionDialog(directoryDialogConfiguration)).ifPresent(f -> fileDirIndv.setText(f.toAbsolutePath().toString())));
setupSortOrderConfiguration();
FormLayout form = new FormLayout("left:pref, 4dlu, pref:grow, 4dlu, pref:grow, 4dlu, pref", "pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, pref, 2dlu, fill:pref:grow, 180dlu, fill:pref:grow,");
FormBuilder builder = FormBuilder.create().layout(form);
builder.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
builder.add(Localization.lang("Library encoding")).xy(1, 1);
builder.add(encoding).xy(3, 1);
builder.addSeparator(Localization.lang("Override default file directories")).xyw(1, 3, 5);
builder.add(Localization.lang("General file directory")).xy(1, 5);
builder.add(fileDir).xy(3, 5);
builder.add(browseFile).xy(5, 5);
builder.add(Localization.lang("User-specific file directory")).xy(1, 7);
builder.add(fileDirIndv).xy(3, 7);
builder.add(browseFileIndv).xy(5, 7);
builder.addSeparator(Localization.lang("Save sort order")).xyw(1, 13, 5);
builder.add(saveInOriginalOrder).xyw(1, 15, 5);
builder.add(saveInSpecifiedOrder).xyw(1, 17, 5);
saveOrderPanel = new SaveOrderConfigDisplay();
builder.add(saveOrderPanel.getPanel()).xyw(1, 21, 5);
builder.addSeparator(Localization.lang("Library protection")).xyw(1, 23, 5);
builder.add(protect).xyw(1, 25, 5);
fieldFormatterCleanupsPanel = new FieldFormatterCleanupsPanel(Localization.lang("Enable save actions"), Cleanups.DEFAULT_SAVE_ACTIONS);
builder.addSeparator(Localization.lang("Save actions")).xyw(1, 27, 5);
builder.add(fieldFormatterCleanupsPanel).xyw(1, 29, 5);
ButtonBarBuilder bb = new ButtonBarBuilder();
bb.addGlue();
bb.addButton(ok);
bb.addButton(cancel);
bb.addRelatedGap();
bb.addButton(new HelpAction(HelpFile.DATABASE_PROPERTIES).getHelpButton());
bb.addGlue();
bb.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
getContentPane().add(builder.getPanel(), BorderLayout.CENTER);
getContentPane().add(bb.getPanel(), BorderLayout.SOUTH);
pack();
AbstractAction closeAction = new AbstractAction() {
@Override
public void actionPerformed(ActionEvent e) {
dispose();
}
};
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", closeAction);
ok.addActionListener(e -> {
storeSettings();
dispose();
});
cancel.addActionListener(e -> dispose());
}
use of org.jabref.gui.FXDialogService in project jabref by JabRef.
the class SaveDatabaseAction method saveAs.
public void saveAs() throws Exception {
// configure file dialog
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.BIBTEX_DB).withDefaultExtension(FileExtensions.BIBTEX_DB).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();
Optional<Path> path = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileSaveDialog(fileDialogConfiguration));
if (path.isPresent()) {
saveAs(path.get().toFile());
} else {
canceled = true;
return;
}
}
Aggregations