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 4 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
76 changes: 76 additions & 0 deletions .travis.yml
Original file line number Diff line number Diff line change
@@ -0,0 +1,76 @@
language: java
jdk:
- openjdk13

# we test at Ubuntu Trusty (Ubuntu 14.04 LTS)
# see https://docs.travis-ci.com/user/trusty-ci-environment/
# This environment is continuously updated as described in https://docs.travis-ci.com/user/build-environment-updates/
dist: trusty
sudo: required

git:
depth: 1

services:
- postgresql
- mysql

env:
global:
- GRADLE_OPTS=-Dorg.gradle.daemon=false
matrix:
- TEST_SUITE=check
- TEST_SUITE=checkstyle
- TEST_SUITE=fetcherTest
- TEST_SUITE=databaseTest
- TEST_SUITE=guiTest
- TEST_SUITE=codecov
- DEPENDENCY_UPDATES=check

matrix:
fast_finish: true
allow_failures:
- env: TEST_SUITE=fetcherTest
- env: TEST_SUITE=guiTest
- env: TEST_SUITE=codecov
- env: DEPENDENCY_UPDATES=check

# JavaFX localization tests need a running X environment
before_install:
- "export DISPLAY=:99.0"
- "sh -e /etc/init.d/xvfb start"
- sleep 3 # give xvfb some time to start

install: true

before_script:
- psql -c 'create database jabref;' -U postgres
- mysql -u root -e 'create database jabref'

script:
# --scan enables the Gradle build scan, which can be used to investigate the time each action consumes
# For more information see https://gradle.com/scans/get-started
- if [ "$TEST_SUITE" != "guiTest" ] && [ "$TEST_SUITE" != "checkstyle" ] && [ "$TEST_SUITE" != "codecov" ]; then ./gradlew $TEST_SUITE $OPTIONS -x checkstyleJmh -x checkstyleMain -x checkstyleTest --scan; fi
- if [ "$TEST_SUITE" == "checkstyle" ]; then ./gradlew checkstyleMain checkstyleTest checkstyleJmh; fi
- if [ "$TEST_SUITE" == "guiTest" ]; then ./buildres/gui-tests.sh; fi
- if [ "$TEST_SUITE" == "codecov" ]; then ./gradlew jacocoTestReport; bash <(curl -s https://codecov.io/bash); fi
- if [ "$DEPENDENCY_UPDATES" == "check" ]; then ./gradlew -q checkOutdatedDependencies; fi

after_failure:
# show test results if build fails
- $TRAVIS_BUILD_DIR/scripts/after-failure.sh

branches:
only:
- /.*/

# cache gradle dependencies
# https://docs.travis-ci.com/user/languages/java#Caching
before_cache:
- rm -f $HOME/.gradle/caches/modules-2/modules-2.lock
- rm -fr $HOME/.gradle/caches/*/plugin-resolution/
cache:
directories:
- $HOME/.gradle/caches/
- $HOME/.gradle/wrapper/

1 change: 1 addition & 0 deletions CHANGELOG.md
Original file line number Diff line number Diff line change
Expand Up @@ -72,6 +72,7 @@ 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 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)

### Removed

Expand Down
73 changes: 72 additions & 1 deletion src/main/java/org/jabref/JabRefGUI.java
Original file line number Diff line number Diff line change
@@ -1,5 +1,7 @@
package org.jabref;

import java.awt.GraphicsDevice;
import java.awt.GraphicsEnvironment;
import java.io.File;
import java.sql.SQLException;
import java.util.ArrayList;
Expand Down Expand Up @@ -40,12 +42,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 +66,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 (numberOfMonitors() == 1 && testExternalCoordinates()) {
//corrects the Window, if its outside of the mainscreen
LOGGER.debug("The Jabref Window is outside the Main Monitor\n");
mainStage.setX(Globals.prefs.getDouble(JabRefPreferences.POS_X_CORE));
mainStage.setY(Globals.prefs.getDouble(JabRefPreferences.POS_Y_CORE));
mainStage.setWidth(Globals.prefs.getDouble(JabRefPreferences.SIZE_X_CORE));
mainStage.setHeight(Globals.prefs.getDouble(JabRefPreferences.SIZE_Y_CORE));
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 +95,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 +205,60 @@ 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("JabRefPreferences.WINDOW_MAXIMISED: " + mainStage.isMaximized() + "\n");
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Shouldn't JabRefPreferences be replaced by MainStage ? (As this does not print the values stored in the preferences)

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

yes it should, I think I had it wrong in because of earlier tries, were I also printed the preferences 😅 it'll be changed at the next commit

bob.append("JabRefPreferences.POS_X: " + mainStage.getX() + "\n");
bob.append("JabRefPreferences.POS_Y: " + mainStage.getY() + "\n");
bob.append("JabRefPreferences.SIZE_X: " + mainStage.getWidth() + "\n");
bob.append("JabRefPreferences.SIZE_Y: " + mainStage.getHeight() + "\n");
LOGGER.debug(bob.toString());
}

/**
* Tests if the window coordinates are out of the mainscreen
* @return outbounds
*/
private boolean testExternalCoordinates() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

test is a bit vague, what about storedWindowPositionIsOutOfBounds (or maybe something a bit shorter).

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

renamed it with isWindowPositionOutOfBounds()

boolean outbounds = false;
if (Globals.prefs.getDouble(JabRefPreferences.POS_X) > Globals.prefs.getDouble(JabRefPreferences.SIZE_X)) {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think it would be slightly better to test against the actual dimensions of the screen, which you can get via Screen.getPrimary().getBounds()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integrated with newest commit

outbounds = true;
}
if (Globals.prefs.getDouble(JabRefPreferences.POS_Y) > Globals.prefs.getDouble(JabRefPreferences.SIZE_Y)) {
outbounds = true;
}
if (Globals.prefs.getDouble(JabRefPreferences.POS_X) < 0) {
outbounds = true;
}
if (Globals.prefs.getDouble(JabRefPreferences.POS_Y) < 0) {
outbounds = true;
}
return outbounds;
}

/**
* returns the number of Monitors connected to the Computer
* @return numberOfmonitors
*/
private int numberOfMonitors() {
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I think the pure JavaFX version would be Screen.getScreens().size()

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

integrated with newest commit

//this following part (this method) is from the Internet:
//https://stackoverflow.com/questions/20966385/in-java-is-it-possible-to-listen-for-the-connection-disconnection-of-an-externa (from 17.11.2019)
int numberOfmonitors = 0;
GraphicsEnvironment ge = GraphicsEnvironment.getLocalGraphicsEnvironment();
GraphicsDevice[] gs = ge.getScreenDevices();
for (int j = 0; j < gs.length; j++) {
numberOfmonitors++;
}
return numberOfmonitors;
}

private void openLastEditedDatabases() {
Expand Down
8 changes: 8 additions & 0 deletions src/main/java/org/jabref/preferences/JabRefPreferences.java
Original file line number Diff line number Diff line change
Expand Up @@ -172,6 +172,10 @@ public class JabRefPreferences implements PreferencesService {
public static final String SIZE_X = "mainWindowSizeX";
public static final String POS_Y = "mainWindowPosY";
public static final String POS_X = "mainWindowPosX";
public static final String SIZE_Y_CORE = "mainWindowSizeYCore";
Copy link
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

As the user can never configure these values, there is no need to add them as preferences. Please convert them to static fields in JabRefGUI.

Copy link
Contributor Author

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I will try to set the Numbers right in at the method openWindow(), not sure if that works, but if it do I can delete all variables I made up..

public static final String SIZE_X_CORE = "mainWindowSizeXCore";
public static final String POS_Y_CORE = "mainWindowPosYCore";
public static final String POS_X_CORE = "mainWindowPosXCore";
public static final String STRINGS_SIZE_Y = "stringsSizeY";
public static final String STRINGS_SIZE_X = "stringsSizeX";
public static final String STRINGS_POS_Y = "stringsPosY";
Expand Down Expand Up @@ -491,6 +495,10 @@ private JabRefPreferences() {
defaults.put(POS_Y, 0);
defaults.put(SIZE_X, 1024);
defaults.put(SIZE_Y, 768);
defaults.put(POS_X_CORE, 0);
defaults.put(POS_Y_CORE, 0);
defaults.put(SIZE_X_CORE, 1024);
defaults.put(SIZE_Y_CORE, 768);
defaults.put(WINDOW_MAXIMISED, Boolean.TRUE);
defaults.put(AUTO_RESIZE_MODE, Boolean.TRUE);
defaults.put(ENTRY_EDITOR_HEIGHT, 0.65);
Expand Down