use of org.jabref.gui.desktop.os.NativeDesktop 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.desktop.os.NativeDesktop in project jabref by JabRef.
the class DetectOpenOfficeInstallation method selectInstallationPath.
private Optional<Path> selectInstallationPath() {
final NativeDesktop nativeDesktop = JabRefDesktop.getNativeDesktop();
JOptionPane.showMessageDialog(parent, Localization.lang("Unable to autodetect OpenOffice/LibreOffice installation. Please choose the installation directory manually."), Localization.lang("Could not find OpenOffice/LibreOffice installation"), JOptionPane.INFORMATION_MESSAGE);
DialogService ds = new FXDialogService();
DirectoryDialogConfiguration dirDialogConfiguration = new DirectoryDialogConfiguration.Builder().withInitialDirectory(nativeDesktop.getApplicationDirectory()).build();
Optional<Path> path = DefaultTaskExecutor.runInJavaFXThread(() -> ds.showDirectorySelectionDialog(dirDialogConfiguration));
if (path.isPresent()) {
return path;
}
return Optional.empty();
}
Aggregations