parserResultIterator = bibDatabases.iterator(); parserResultIterator.hasNext();) {
ParserResult pr = parserResultIterator.next();
// Define focused tab
- if (pr.getFile().get().getAbsolutePath().equals(focusedFile)) {
+ if (pr.getFile().filter(path -> path.getAbsolutePath().equals(focusedFile)).isPresent()) {
first = true;
}
@@ -118,9 +109,10 @@ private void openWindow() {
pr.getDatabase().clearSharedDatabaseID();
LOGGER.error("Connection error", e);
- JOptionPane.showMessageDialog(mainFrame,
- e.getMessage() + "\n\n" + Localization.lang("A local copy will be opened."),
- Localization.lang("Connection error"), JOptionPane.WARNING_MESSAGE);
+ dialogService.showErrorDialogAndWait(
+ Localization.lang("Connection error"),
+ Localization.lang("A local copy will be opened."),
+ e);
}
toOpenTab.add(pr);
} else if (pr.toOpenTab()) {
@@ -144,18 +136,40 @@ private void openWindow() {
// state. This needs to be set after the window has been made visible, so we
// do it here:
if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) {
- JabRefGUI.getMainFrame().setExtendedState(Frame.MAXIMIZED_BOTH);
+ mainStage.setMaximized(true);
+ } else {
+ mainStage.setX(Globals.prefs.getDouble(JabRefPreferences.POS_X));
+ mainStage.setY(Globals.prefs.getDouble(JabRefPreferences.POS_Y));
+ mainStage.setWidth(Globals.prefs.getDouble(JabRefPreferences.SIZE_X));
+ mainStage.setHeight(Globals.prefs.getDouble(JabRefPreferences.SIZE_Y));
}
- JabRefGUI.getMainFrame().setVisible(true);
+ // We create a decoration pane ourselves for performance reasons
+ // (otherwise it has to be injected later, leading to a complete redraw/relayout of the complete scene)
+ DecorationPane root = new DecorationPane();
+ root.getChildren().add(JabRefGUI.mainFrame);
+
+ Scene scene = new Scene(root, 800, 800);
+ Globals.getThemeLoader().installCss(scene, Globals.prefs);
+ mainStage.setTitle(JabRefFrame.FRAME_TITLE);
+ mainStage.getIcons().addAll(IconTheme.getLogoSetFX());
+ mainStage.setScene(scene);
+ mainStage.show();
+
+ mainStage.setOnCloseRequest(event -> {
+ saveWindowState(mainStage);
+ boolean reallyQuit = mainFrame.quit();
+ if (!reallyQuit) {
+ event.consume();
+ }
+ });
for (ParserResult pr : failed) {
- String message = "" + Localization.lang("Error opening file '%0'.", pr.getFile().get().getName())
- + ""
- + pr.getErrorMessage() + "";
+ String message = Localization.lang("Error opening file '%0'.", pr.getFile().get().getName()) + "\n"
+ + pr.getErrorMessage();
+
+ dialogService.showErrorDialogAndWait(Localization.lang("Error opening file"), message);
- JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(), message, Localization.lang("Error opening file"),
- JOptionPane.ERROR_MESSAGE);
}
// Display warnings, if any
@@ -180,10 +194,14 @@ private void openWindow() {
}
LOGGER.debug("Finished adding panels");
+ }
- if (!bibDatabases.isEmpty()) {
- JabRefGUI.getMainFrame().getCurrentBasePanel().getMainTable().requestFocus();
- }
+ private void saveWindowState(Stage mainStage) {
+ Globals.prefs.putBoolean(JabRefPreferences.WINDOW_MAXIMISED, mainStage.isMaximized());
+ Globals.prefs.putDouble(JabRefPreferences.POS_X, mainStage.getX());
+ Globals.prefs.putDouble(JabRefPreferences.POS_Y, mainStage.getY());
+ Globals.prefs.putDouble(JabRefPreferences.SIZE_X, mainStage.getWidth());
+ Globals.prefs.putDouble(JabRefPreferences.SIZE_Y, mainStage.getHeight());
}
private void openLastEditedDatabases() {
@@ -201,7 +219,7 @@ private void openLastEditedDatabases() {
}
if (BackupManager.checkForBackupFile(dbFile.toPath())) {
- BackupUIManager.showRestoreBackupDialog(mainFrame, dbFile.toPath());
+ BackupUIManager.showRestoreBackupDialog(dialogService, dbFile.toPath());
}
ParserResult parsedDatabase = OpenDatabase.loadDatabase(fileName,
@@ -225,71 +243,11 @@ private boolean isLoaded(File fileToOpen) {
}
private void setLookAndFeel() {
- try {
- String lookFeel;
- String systemLookFeel = UIManager.getSystemLookAndFeelClassName();
-
- if (Globals.prefs.getBoolean(JabRefPreferences.USE_DEFAULT_LOOK_AND_FEEL)) {
- // FIXME: Problems with OpenJDK and GTK L&F
- // See https://github.com/JabRef/jabref/issues/393, https://github.com/JabRef/jabref/issues/638
- if (System.getProperty("java.runtime.name").contains("OpenJDK")) {
- // Metal L&F
- lookFeel = UIManager.getCrossPlatformLookAndFeelClassName();
- LOGGER.warn(
- "There seem to be problems with OpenJDK and the default GTK Look&Feel. Using Metal L&F instead. Change to another L&F with caution.");
- } else {
- lookFeel = systemLookFeel;
- }
- } else {
- lookFeel = Globals.prefs.get(JabRefPreferences.WIN_LOOK_AND_FEEL);
- }
-
- // FIXME: Open JDK problem
- if (UIManager.getCrossPlatformLookAndFeelClassName().equals(lookFeel)
- && !System.getProperty("java.runtime.name").contains("OpenJDK")) {
- // try to avoid ending up with the ugly Metal L&F
- UIManager.setLookAndFeel("javax.swing.plaf.nimbus.NimbusLookAndFeel");
- } else {
- try {
- UIManager.setLookAndFeel(lookFeel);
- } catch (ClassNotFoundException | InstantiationException | IllegalAccessException |
- UnsupportedLookAndFeelException e) {
- // specified look and feel does not exist on the classpath, so use system l&f
- UIManager.setLookAndFeel(systemLookFeel);
- // also set system l&f as default
- Globals.prefs.put(JabRefPreferences.WIN_LOOK_AND_FEEL, systemLookFeel);
- // notify the user
- JOptionPane.showMessageDialog(JabRefGUI.getMainFrame(),
- Localization
- .lang("Unable to find the requested look and feel and thus the default one is used."),
- Localization.lang("Warning"), JOptionPane.WARNING_MESSAGE);
- LOGGER.warn("Unable to find requested look and feel", e);
- }
- }
-
- // On Linux, Java FX fonts look blurry per default. This can be improved by using a non-default rendering
- // setting. See https://github.com/woky/javafx-hates-linux
- if (Globals.prefs.getBoolean(JabRefPreferences.FX_FONT_RENDERING_TWEAK)) {
- System.setProperty("prism.text", "t2k");
- System.setProperty("prism.lcdtext", "true");
- }
- } catch (Exception e) {
- LOGGER.warn("Look and feel could not be set", e);
- }
-
- // In JabRef v2.8, we did it only on NON-Mac. Now, we try on all platforms
- boolean overrideDefaultFonts = Globals.prefs.getBoolean(JabRefPreferences.OVERRIDE_DEFAULT_FONTS);
- if (overrideDefaultFonts) {
- int fontSize = Globals.prefs.getInt(JabRefPreferences.MENU_FONT_SIZE);
- UIDefaults defaults = UIManager.getDefaults();
- Enumeration