diff --git a/CHANGELOG.md b/CHANGELOG.md index 7696612d0e4..97ec8d2d2ed 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -72,7 +72,8 @@ We refer to [GitHub issues](https://github.com/JabRef/jabref/issues) by using `# - We fixed an issue where JabRef could not interact with [Oracle XE](https://www.oracle.com/de/database/technologies/appdev/xe.html) in the [shared SQL database setup](https://docs.jabref.org/collaborative-work/sqldatabase). - We fixed an issue where the toolbar icons were hidden on smaller screens. - We fixed an issue where renaming referenced files for bib entries with long titles was not possible. [#5603](https://github.com/JabRef/jabref/issues/5603) -- We fixed a bug where the selection of groups was lost after drag and drop.[#2868](https://github.com/JabRef/jabref/issues/2868) +- We fixed an issue where a window which is on an external screen gets unreachable when external screen is removed. [#5037](https://github.com/JabRef/jabref/issues/5037) +- We fixed a bug where the selection of groups was lost after drag and drop. [#2868](https://github.com/JabRef/jabref/issues/2868) ### Removed diff --git a/src/main/java/org/jabref/JabRefGUI.java b/src/main/java/org/jabref/JabRefGUI.java index 4ddd788eff9..76684d8e1ed 100644 --- a/src/main/java/org/jabref/JabRefGUI.java +++ b/src/main/java/org/jabref/JabRefGUI.java @@ -8,6 +8,7 @@ import javafx.application.Platform; import javafx.scene.Scene; +import javafx.stage.Screen; import javafx.stage.Stage; import org.jabref.gui.BasePanel; @@ -40,12 +41,14 @@ public class JabRefGUI { private final List bibDatabases; private final boolean isBlank; + private boolean correctedWindowPos; private final List failed = new ArrayList<>(); private final List toOpenTab = new ArrayList<>(); public JabRefGUI(Stage mainStage, List databases, boolean isBlank) { this.bibDatabases = databases; this.isBlank = isBlank; + this.correctedWindowPos = false; mainFrame = new JabRefFrame(mainStage); openWindow(mainStage); @@ -62,12 +65,21 @@ private void openWindow(Stage mainStage) { // Restore window location and/or maximised state if (Globals.prefs.getBoolean(JabRefPreferences.WINDOW_MAXIMISED)) { mainStage.setMaximized(true); + } else if (Screen.getScreens().size() == 1 && isWindowPositionOutOfBounds()) { + //corrects the Window, if its outside of the mainscreen + LOGGER.debug("The Jabref Window is outside the Main Monitor\n"); + mainStage.setX(0); + mainStage.setY(0); + mainStage.setWidth(1024); + mainStage.setHeight(768); + correctedWindowPos = 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)); } + printWindowState(mainStage); // 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) @@ -82,7 +94,11 @@ private void openWindow(Stage mainStage) { mainStage.show(); mainStage.setOnCloseRequest(event -> { - saveWindowState(mainStage); + if (!correctedWindowPos) { + //saves the window position only if its not corrected -> the window will rest at the old Position, + //if the external Screen is connected again. + saveWindowState(mainStage); + } boolean reallyQuit = mainFrame.quit(); if (!reallyQuit) { event.consume(); @@ -188,6 +204,33 @@ private void saveWindowState(Stage mainStage) { Globals.prefs.putDouble(JabRefPreferences.POS_Y, mainStage.getY()); Globals.prefs.putDouble(JabRefPreferences.SIZE_X, mainStage.getWidth()); Globals.prefs.putDouble(JabRefPreferences.SIZE_Y, mainStage.getHeight()); + printWindowState(mainStage); + } + + /** + * outprints the Data from the Screen + * (only in debug mode) + * @param mainStage + */ + private void printWindowState(Stage mainStage) { + StringBuilder bob = new StringBuilder(); + bob.append("SCREEN DATA:"); + bob.append("mainStage.WINDOW_MAXIMISED: " + mainStage.isMaximized() + "\n"); + bob.append("mainStage.POS_X: " + mainStage.getX() + "\n"); + bob.append("mainStage.POS_Y: " + mainStage.getY() + "\n"); + bob.append("mainStage.SIZE_X: " + mainStage.getWidth() + "\n"); + bob.append("mainStages.SIZE_Y: " + mainStage.getHeight() + "\n"); + LOGGER.debug(bob.toString()); + } + + /** + * Tests if the window coordinates are out of the mainscreen + * @return outbounds + */ + private boolean isWindowPositionOutOfBounds() { + + return !Screen.getPrimary().getBounds().contains(Globals.prefs.getDouble(JabRefPreferences.POS_X) , Globals.prefs.getDouble(JabRefPreferences.POS_Y)); + } private void openLastEditedDatabases() {