33import com .jfoenix .controls .JFXDecorator ;
44import com .xwintop .xJavaFxTool .controller .IndexController ;
55import com .xwintop .xJavaFxTool .utils .Config ;
6- import com .xwintop .xJavaFxTool .utils .Config .Keys .MainWindow ;
76import com .xwintop .xJavaFxTool .utils .StageUtils ;
87import com .xwintop .xJavaFxTool .utils .XJavaFxSystemUtil ;
98import com .xwintop .xcore .util .javafx .AlertUtil ;
109import com .xwintop .xcore .util .javafx .JavaFxViewUtil ;
11- import java .util .ResourceBundle ;
12- import java .util .prefs .Preferences ;
1310import javafx .application .Application ;
1411import javafx .application .Platform ;
1512import javafx .event .Event ;
2017import javafx .stage .Stage ;
2118import lombok .extern .slf4j .Slf4j ;
2219
20+ import java .util .ResourceBundle ;
21+
2322/**
2423 * @ClassName: Main
2524 * @Description: 启动类
@@ -52,10 +51,10 @@ public void start(Stage primaryStage) throws Exception {
5251 Parent root = fXMLLoader .load ();
5352
5453 JFXDecorator decorator = JavaFxViewUtil .getJFXDecorator (
55- primaryStage ,
56- resourceBundle .getString ("Title" ) + Config .xJavaFxToolVersions ,
57- "/images/icon.jpg" ,
58- root
54+ primaryStage ,
55+ resourceBundle .getString ("Title" ) + Config .xJavaFxToolVersions ,
56+ "/images/icon.jpg" ,
57+ root
5958 );
6059 decorator .setOnCloseButtonAction (() -> confirmExit (null ));
6160
@@ -67,63 +66,34 @@ public void start(Stage primaryStage) throws Exception {
6766 primaryStage .setScene (scene );
6867 primaryStage .setOnCloseRequest (this ::confirmExit );
6968
70- loadPrimaryStageBound (primaryStage );
69+ StageUtils . loadPrimaryStageBound (primaryStage );
7170 primaryStage .show ();
7271
7372 StageUtils .updateStageStyle (primaryStage );
7473 stage = primaryStage ;
7574 }
7675
77- private void loadPrimaryStageBound (Stage stage ) {
78- double left = getPreferences ().getDouble (MainWindow .LEFT , -1 );
79- double top = getPreferences ().getDouble (MainWindow .TOP , -1 );
80- double width = getPreferences ().getDouble (MainWindow .WIDTH , -1 );
81- double height = getPreferences ().getDouble (MainWindow .HEIGHT , -1 );
82-
83- if (left > 0 ) {
84- stage .setX (left );
85- }
86- if (top > 0 ) {
87- stage .setY (top );
88- }
89- if (width > 0 ) {
90- stage .setWidth (width );
91- }
92- if (height > 0 ) {
93- stage .setHeight (height );
94- }
95- }
96-
97- private Preferences getPreferences () {
98- return Preferences .userRoot ().node (PREFERENCE_ROOT );
99- }
100-
10176 private void confirmExit (Event event ) {
102- if (AlertUtil .showConfirmAlert ("确定要退出吗?" )) {
103- savePrimaryStageBound ();
77+ if (XJavaFxSystemUtil .getSystemConfigure ().getBoolean ("exitShowAlertCheckBox" , true )) {
78+ if (AlertUtil .showConfirmAlert ("确定要退出吗?" )) {
79+ StageUtils .savePrimaryStageBound (stage );
80+ Platform .exit ();
81+ System .exit (0 );
82+ } else if (event != null ) {
83+ event .consume ();
84+ }
85+ } else {
86+ StageUtils .savePrimaryStageBound (stage );
10487 Platform .exit ();
10588 System .exit (0 );
106- } else if (event != null ) {
107- event .consume ();
10889 }
10990 }
11091
111- private void savePrimaryStageBound () {
112- if (stage == null || stage .isIconified ()) {
113- return ;
114- }
115-
116- getPreferences ().putDouble (MainWindow .LEFT , stage .getX ());
117- getPreferences ().putDouble (MainWindow .TOP , stage .getY ());
118- getPreferences ().putDouble (MainWindow .WIDTH , stage .getWidth ());
119- getPreferences ().putDouble (MainWindow .HEIGHT , stage .getHeight ());
120- }
121-
12292 public static Stage getStage () {
12393 return stage ;
12494 }
12595
12696 public static void setStage (Stage stage ) {
12797 Main .stage = stage ;
12898 }
129- }
99+ }
0 commit comments