Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Bugfix for Multiscreen #5738

Merged
merged 8 commits into from
Dec 12, 2019
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
3 changes: 2 additions & 1 deletion CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -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

Expand Down
45 changes: 44 additions & 1 deletion src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -40,12 +41,14 @@ public class JabRefGUI {

private final List<ParserResult> bibDatabases;
private final boolean isBlank;
private boolean correctedWindowPos;
private final List<ParserResult> failed = new ArrayList<>();
private final List<ParserResult> toOpenTab = new ArrayList<>();

public JabRefGUI(Stage mainStage, List<ParserResult> databases, boolean isBlank) {
this.bibDatabases = databases;
this.isBlank = isBlank;
this.correctedWindowPos = false;
mainFrame = new JabRefFrame(mainStage);

openWindow(mainStage);
Expand All @@ -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)
Expand All @@ -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();
Expand Down Expand Up @@ -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() {
Expand Down