6
6
import java .util .Iterator ;
7
7
import java .util .List ;
8
8
9
+ import javafx .application .Platform ;
9
10
import javafx .scene .Scene ;
10
11
import javafx .stage .Stage ;
11
12
@@ -42,20 +43,11 @@ public class JabRefGUI {
42
43
private final List <ParserResult > failed = new ArrayList <>();
43
44
private final List <ParserResult > toOpenTab = new ArrayList <>();
44
45
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 ;
49
48
this .isBlank = isBlank ;
50
49
mainFrame = new JabRefFrame (mainStage );
51
50
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
-
59
51
openWindow (mainStage );
60
52
new VersionWorker (Globals .BUILD_INFO .getVersion (), Globals .prefs .getVersionPreferences ().getIgnoredVersion (), mainFrame .getDialogService (), Globals .TASK_EXECUTOR )
61
53
.checkForNewVersionDelayed ();
@@ -64,15 +56,56 @@ public JabRefGUI(Stage mainStage, List<ParserResult> argsDatabases, boolean isBl
64
56
private void openWindow (Stage mainStage ) {
65
57
applyFontRenderingTweak ();
66
58
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 () {
67
98
// If the option is enabled, open the last edited libraries, if any.
68
99
if (!isBlank && Globals .prefs .getBoolean (JabRefPreferences .OPEN_LAST_EDITED )) {
69
100
openLastEditedDatabases ();
70
101
}
71
102
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 ));
76
109
77
110
// Add all bibDatabases databases to the frame:
78
111
boolean first = false ;
@@ -119,44 +152,11 @@ private void openWindow(Stage mainStage) {
119
152
first = false ;
120
153
}
121
154
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
-
154
155
for (ParserResult pr : failed ) {
155
156
String message = Localization .lang ("Error opening file '%0'." , pr .getFile ().get ().getName ()) + "\n "
156
157
+ pr .getErrorMessage ();
157
158
158
159
mainFrame .getDialogService ().showErrorDialogAndWait (Localization .lang ("Error opening file" ), message );
159
-
160
160
}
161
161
162
162
// Display warnings, if any
0 commit comments