use of org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class FromAuxDialog method initPanels.
private void initPanels() {
// collect the names of all open databases
int len = parentTabbedPane.getTabCount();
int toSelect = -1;
for (int i = 0; i < len; i++) {
dbChooser.addItem(parentTabbedPane.getTitleAt(i));
if (parentFrame.getBasePanelAt(i) == parentFrame.getCurrentBasePanel()) {
toSelect = i;
}
}
if (toSelect >= 0) {
dbChooser.setSelectedIndex(toSelect);
}
auxFileField = new JTextField("", 25);
JButton browseAuxFileButton = new JButton(Localization.lang("Browse"));
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilter(FileExtensions.AUX).withDefaultExtension(FileExtensions.AUX).withInitialDirectory(Globals.prefs.get(JabRefPreferences.WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();
browseAuxFileButton.addActionListener(e -> {
Optional<Path> file = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showFileOpenDialog(fileDialogConfiguration));
file.ifPresent(f -> auxFileField.setText(f.toAbsolutePath().toString()));
});
notFoundList = new JList<>();
JScrollPane listScrollPane = new JScrollPane(notFoundList);
statusInfos = new JTextArea("", 5, 20);
JScrollPane statusScrollPane = new JScrollPane(statusInfos);
statusInfos.setEditable(false);
DefaultFormBuilder b = new DefaultFormBuilder(new FormLayout("left:pref, 4dlu, fill:pref:grow, 4dlu, left:pref", ""), buttons);
b.appendSeparator(Localization.lang("Options"));
b.append(Localization.lang("Reference library") + ":");
b.append(dbChooser, 3);
b.nextLine();
b.append(Localization.lang("LaTeX AUX file") + ":");
b.append(auxFileField);
b.append(browseAuxFileButton);
b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
b = new DefaultFormBuilder(new FormLayout("fill:pref:grow, 4dlu, fill:pref:grow", "pref, pref, fill:pref:grow"), statusPanel);
b.appendSeparator(Localization.lang("Result"));
b.append(Localization.lang("Unknown BibTeX entries") + ":");
b.append(Localization.lang("Messages") + ":");
b.nextLine();
b.append(listScrollPane);
b.append(statusScrollPane);
b.getPanel().setBorder(BorderFactory.createEmptyBorder(5, 5, 5, 5));
}
use of org.jabref.gui.util.FileDialogConfiguration 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 org.jabref.gui.util.FileDialogConfiguration in project jabref by JabRef.
the class ImportFormats method getImportAction.
/**
* Create an AbstractAction for performing an Import operation.
* @param frame The JabRefFrame of this JabRef instance.
* @param openInNew Indicate whether the action should open into a new database or
* into the currently open one.
* @return The action.
*/
public static AbstractAction getImportAction(JabRefFrame frame, boolean openInNew) {
class ImportAction extends MnemonicAwareAction {
private final boolean newDatabase;
public ImportAction(boolean newDatabase) {
this.newDatabase = newDatabase;
if (newDatabase) {
putValue(Action.NAME, Localization.menuTitle("Import into new library"));
putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_NEW_DATABASE));
} else {
putValue(Action.NAME, Localization.menuTitle("Import into current library"));
putValue(Action.ACCELERATOR_KEY, Globals.getKeyPrefs().getKey(KeyBinding.IMPORT_INTO_CURRENT_DATABASE));
}
}
@Override
public void actionPerformed(ActionEvent e) {
SortedSet<Importer> importers = Globals.IMPORT_FORMAT_READER.getImportFormats();
List<FileExtensions> extensions = importers.stream().map(Importer::getExtensions).collect(Collectors.toList());
FileChooser.ExtensionFilter allImports = ImportFileFilter.convert(Localization.lang("Available import formats"), importers);
FileDialogConfiguration fileDialogConfiguration = new FileDialogConfiguration.Builder().addExtensionFilters(extensions).withInitialDirectory(Globals.prefs.get(JabRefPreferences.IMPORT_WORKING_DIRECTORY)).build();
DialogService ds = new FXDialogService();
FileChooser fs = ds.getConfiguredFileChooser(fileDialogConfiguration);
fs.setSelectedExtensionFilter(allImports);
File f = DefaultTaskExecutor.runInJavaFXThread(() -> fs.showOpenDialog(null));
Optional<Path> selectedFile = Optional.ofNullable(f).map(File::toPath);
FileChooser.ExtensionFilter selectedExtension = fs.getSelectedExtensionFilter();
// Add file filter for all supported types
selectedFile.ifPresent(file -> {
try {
if (!Files.exists(file)) {
JOptionPane.showMessageDialog(frame, Localization.lang("File not found") + ": '" + file.getFileName() + "'.", Localization.lang("Import"), JOptionPane.ERROR_MESSAGE);
return;
}
Optional<Importer> format = ImportFileFilter.convert(selectedExtension, importers);
ImportMenuItem importMenu = new ImportMenuItem(frame, newDatabase, format.orElse(null));
importMenu.automatedImport(Collections.singletonList(file.toString()));
Globals.prefs.put(JabRefPreferences.IMPORT_WORKING_DIRECTORY, file.getParent().toString());
} catch (Exception ex) {
LOGGER.warn("Cannot import file", ex);
}
});
}
}
return new ImportAction(openInNew);
}
use of org.jabref.gui.util.FileDialogConfiguration 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 org.jabref.gui.util.FileDialogConfiguration 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