66import java .util .Iterator ;
77import java .util .List ;
88
9+ import javafx .application .Platform ;
910import javafx .scene .Scene ;
1011import javafx .stage .Stage ;
1112
@@ -42,20 +43,11 @@ public class JabRefGUI {
4243 private final List <ParserResult > failed = new ArrayList <>();
4344 private final List <ParserResult > toOpenTab = new ArrayList <>();
4445
45- private final String focusedFile ;
46-
47- public JabRefGUI (Stage mainStage , List <ParserResult > argsDatabases , boolean isBlank ) {
48- this .bibDatabases = argsDatabases ;
46+ public JabRefGUI (Stage mainStage , List <ParserResult > databases , boolean isBlank ) {
47+ this .bibDatabases = databases ;
4948 this .isBlank = isBlank ;
5049 mainFrame = new JabRefFrame (mainStage );
5150
52- // passed file (we take the first one) should be focused
53- focusedFile = argsDatabases .stream ()
54- .findFirst ()
55- .flatMap (ParserResult ::getFile )
56- .map (File ::getAbsolutePath )
57- .orElse (Globals .prefs .get (JabRefPreferences .LAST_FOCUSED ));
58-
5951 openWindow (mainStage );
6052 new VersionWorker (Globals .BUILD_INFO .getVersion (), Globals .prefs .getVersionPreferences ().getIgnoredVersion (), mainFrame .getDialogService (), Globals .TASK_EXECUTOR )
6153 .checkForNewVersionDelayed ();
@@ -64,15 +56,56 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
6456 private void openWindow (Stage mainStage ) {
6557 applyFontRenderingTweak ();
6658
59+ GUIGlobals .init ();
60+
61+ LOGGER .debug ("Initializing frame" );
62+ mainFrame .init ();
63+
64+ // Restore window location and/or maximised state
65+ if (Globals .prefs .getBoolean (JabRefPreferences .WINDOW_MAXIMISED )) {
66+ mainStage .setMaximized (true );
67+ } else {
68+ mainStage .setX (Globals .prefs .getDouble (JabRefPreferences .POS_X ));
69+ mainStage .setY (Globals .prefs .getDouble (JabRefPreferences .POS_Y ));
70+ mainStage .setWidth (Globals .prefs .getDouble (JabRefPreferences .SIZE_X ));
71+ mainStage .setHeight (Globals .prefs .getDouble (JabRefPreferences .SIZE_Y ));
72+ }
73+
74+ // We create a decoration pane ourselves for performance reasons
75+ // (otherwise it has to be injected later, leading to a complete redraw/relayout of the complete scene)
76+ DecorationPane root = new DecorationPane ();
77+ root .getChildren ().add (JabRefGUI .mainFrame );
78+
79+ Scene scene = new Scene (root , 800 , 800 );
80+ Globals .getThemeLoader ().installCss (scene , Globals .prefs );
81+ mainStage .setTitle (JabRefFrame .FRAME_TITLE );
82+ mainStage .getIcons ().addAll (IconTheme .getLogoSetFX ());
83+ mainStage .setScene (scene );
84+ mainStage .show ();
85+
86+ mainStage .setOnCloseRequest (event -> {
87+ saveWindowState (mainStage );
88+ boolean reallyQuit = mainFrame .quit ();
89+ if (!reallyQuit ) {
90+ event .consume ();
91+ }
92+ });
93+
94+ Platform .runLater (this ::openDatabases );
95+ }
96+
97+ private void openDatabases () {
6798 // If the option is enabled, open the last edited libraries, if any.
6899 if (!isBlank && Globals .prefs .getBoolean (JabRefPreferences .OPEN_LAST_EDITED )) {
69100 openLastEditedDatabases ();
70101 }
71102
72- GUIGlobals .init ();
73-
74- LOGGER .debug ("Initializing frame" );
75- mainFrame .init ();
103+ // passed file (we take the first one) should be focused
104+ String focusedFile = bibDatabases .stream ()
105+ .findFirst ()
106+ .flatMap (ParserResult ::getFile )
107+ .map (File ::getAbsolutePath )
108+ .orElse (Globals .prefs .get (JabRefPreferences .LAST_FOCUSED ));
76109
77110 // Add all bibDatabases databases to the frame:
78111 boolean first = false ;
@@ -119,44 +152,11 @@ private void openWindow(Stage mainStage) {
119152 first = false ;
120153 }
121154
122- // If we are set to remember the window location, we also remember the maximised
123- // state. This needs to be set after the window has been made visible, so we
124- // do it here:
125- if (Globals .prefs .getBoolean (JabRefPreferences .WINDOW_MAXIMISED )) {
126- mainStage .setMaximized (true );
127- } else {
128- mainStage .setX (Globals .prefs .getDouble (JabRefPreferences .POS_X ));
129- mainStage .setY (Globals .prefs .getDouble (JabRefPreferences .POS_Y ));
130- mainStage .setWidth (Globals .prefs .getDouble (JabRefPreferences .SIZE_X ));
131- mainStage .setHeight (Globals .prefs .getDouble (JabRefPreferences .SIZE_Y ));
132- }
133-
134- // We create a decoration pane ourselves for performance reasons
135- // (otherwise it has to be injected later, leading to a complete redraw/relayout of the complete scene)
136- DecorationPane root = new DecorationPane ();
137- root .getChildren ().add (JabRefGUI .mainFrame );
138-
139- Scene scene = new Scene (root , 800 , 800 );
140- Globals .getThemeLoader ().installCss (scene , Globals .prefs );
141- mainStage .setTitle (JabRefFrame .FRAME_TITLE );
142- mainStage .getIcons ().addAll (IconTheme .getLogoSetFX ());
143- mainStage .setScene (scene );
144- mainStage .show ();
145-
146- mainStage .setOnCloseRequest (event -> {
147- saveWindowState (mainStage );
148- boolean reallyQuit = mainFrame .quit ();
149- if (!reallyQuit ) {
150- event .consume ();
151- }
152- });
153-
154155 for (ParserResult pr : failed ) {
155156 String message = Localization .lang ("Error opening file '%0'." , pr .getFile ().get ().getName ()) + "\n "
156157 + pr .getErrorMessage ();
157158
158159 mainFrame .getDialogService ().showErrorDialogAndWait (Localization .lang ("Error opening file" ), message );
159-
160160 }
161161
162162 // Display warnings, if any
0 commit comments