-
-
Notifications
You must be signed in to change notification settings - Fork 2.6k
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
Bugfix for Multiscreen #5738
Changes from 4 commits
b02ce7b
7b2544a
8f5cd01
6792010
31a2c1a
031dbc5
e652b38
b26e243
File filter
Filter by extension
Conversations
Jump to
Diff view
Diff view
There are no files selected for viewing
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/ | ||
|
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; | ||
|
@@ -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); | ||
|
@@ -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) | ||
|
@@ -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(); | ||
|
@@ -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"); | ||
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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more.
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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)) { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe reason will be displayed to describe this comment to others. Learn more. I think the pure JavaFX version would be There was a problem hiding this comment. Choose a reason for hiding this commentThe 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() { | ||
|
Original file line number | Diff line number | Diff line change |
---|---|---|
|
@@ -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"; | ||
There was a problem hiding this comment. Choose a reason for hiding this commentThe 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 There was a problem hiding this comment. Choose a reason for hiding this commentThe 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"; | ||
|
@@ -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); | ||
|
There was a problem hiding this comment.
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 byMainStage
? (As this does not print the values stored in the preferences)There was a problem hiding this comment.
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