|
1 | | -package com.xwintop.xJavaFxTool; |
2 | | - |
3 | | -import com.jfoenix.controls.JFXDecorator; |
4 | | -import com.xwintop.xJavaFxTool.controller.IndexController; |
5 | | -import com.xwintop.xJavaFxTool.utils.Config; |
6 | | -import com.xwintop.xJavaFxTool.utils.StageUtils; |
7 | | -import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil; |
8 | | -import com.xwintop.xcore.FxApp; |
9 | | -import com.xwintop.xcore.util.javafx.AlertUtil; |
10 | | -import com.xwintop.xcore.util.javafx.JavaFxViewUtil; |
11 | | -import java.util.ResourceBundle; |
12 | | -import javafx.application.Application; |
13 | | -import javafx.application.Platform; |
14 | | -import javafx.event.Event; |
15 | | -import javafx.fxml.FXMLLoader; |
16 | | -import javafx.scene.Parent; |
17 | | -import javafx.scene.Scene; |
18 | | -import javafx.scene.image.Image; |
19 | | -import javafx.stage.Stage; |
20 | | -import lombok.extern.slf4j.Slf4j; |
21 | | - |
22 | | -/** |
23 | | - * @ClassName: Main |
24 | | - * @Description: 启动类 |
25 | | - * @author: xufeng |
26 | | - * @date: 2017年11月10日 下午4:34:11 |
27 | | - */ |
28 | | -@Slf4j |
29 | | -public class Main extends Application { |
30 | | - |
31 | | - public static final String LOGO_PATH = "/images/icon.jpg"; |
32 | | - |
33 | | - private static Stage stage; |
34 | | - |
35 | | - public static void main(String[] args) { |
36 | | - try { |
37 | | - log.info("xJavaFxTool项目启动"); |
38 | | - launch(args); |
39 | | - } catch (Exception e) { |
40 | | - log.error("xJavaFxTool启动失败:", e); |
41 | | - } |
42 | | - } |
43 | | - |
44 | | - @Override |
45 | | - public void start(Stage primaryStage) throws Exception { |
46 | | - |
47 | | - // 初始化 JavaFX 全局设置 |
48 | | - FxApp.init(primaryStage, LOGO_PATH); |
49 | | - FxApp.styleSheets.add(Main.class.getResource("/css/jfoenix-main.css").toExternalForm()); |
50 | | - |
51 | | - XJavaFxSystemUtil.initSystemLocal();//初始化本地语言 |
52 | | - XJavaFxSystemUtil.addJarByLibs();//添加外部jar包 |
53 | | - |
54 | | - FXMLLoader fXMLLoader = IndexController.getFXMLLoader(); |
55 | | - ResourceBundle resourceBundle = fXMLLoader.getResources(); |
56 | | - Parent root = fXMLLoader.load(); |
57 | | - |
58 | | - JFXDecorator decorator = JavaFxViewUtil.getJFXDecorator( |
59 | | - primaryStage, |
60 | | - resourceBundle.getString("Title") + Config.xJavaFxToolVersions, |
61 | | - LOGO_PATH, |
62 | | - root |
63 | | - ); |
64 | | - decorator.setOnCloseButtonAction(() -> confirmExit(null)); |
65 | | - |
66 | | - Scene scene = JavaFxViewUtil.getJFXDecoratorScene(decorator); |
67 | | - |
68 | | - primaryStage.setResizable(true); |
69 | | - primaryStage.setTitle(resourceBundle.getString("Title"));//标题 |
70 | | - primaryStage.getIcons().add(new Image(LOGO_PATH));//图标 |
71 | | - primaryStage.setScene(scene); |
72 | | - primaryStage.setOnCloseRequest(this::confirmExit); |
73 | | - |
74 | | - StageUtils.loadPrimaryStageBound(primaryStage); |
75 | | - primaryStage.show(); |
76 | | - |
77 | | - StageUtils.updateStageStyle(primaryStage); |
78 | | - stage = primaryStage; |
79 | | - } |
80 | | - |
81 | | - private void confirmExit(Event event) { |
82 | | - if (XJavaFxSystemUtil.getSystemConfigure().getBoolean("exitShowAlertCheckBox", true)) { |
83 | | - if (AlertUtil.confirmOkCancel("退出应用", "确定要退出吗?")) { |
84 | | - StageUtils.savePrimaryStageBound(stage); |
85 | | - Platform.exit(); |
86 | | - System.exit(0); |
87 | | - } else if (event != null) { |
88 | | - event.consume(); |
89 | | - } |
90 | | - } else { |
91 | | - StageUtils.savePrimaryStageBound(stage); |
92 | | - Platform.exit(); |
93 | | - System.exit(0); |
94 | | - } |
95 | | - } |
96 | | - |
97 | | - public static Stage getStage() { |
98 | | - return stage; |
99 | | - } |
100 | | - |
101 | | - public static void setStage(Stage stage) { |
102 | | - Main.stage = stage; |
103 | | - } |
104 | | -} |
| 1 | +package com.xwintop.xJavaFxTool; |
| 2 | + |
| 3 | +import com.jfoenix.controls.JFXDecorator; |
| 4 | +import com.xwintop.xJavaFxTool.controller.IndexController; |
| 5 | +import com.xwintop.xJavaFxTool.utils.Config; |
| 6 | +import com.xwintop.xJavaFxTool.utils.StageUtils; |
| 7 | +import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil; |
| 8 | +import com.xwintop.xcore.javafx.FxApp; |
| 9 | +import com.xwintop.xcore.util.javafx.AlertUtil; |
| 10 | +import com.xwintop.xcore.util.javafx.JavaFxViewUtil; |
| 11 | +import javafx.application.Application; |
| 12 | +import javafx.application.Platform; |
| 13 | +import javafx.event.Event; |
| 14 | +import javafx.fxml.FXMLLoader; |
| 15 | +import javafx.scene.Parent; |
| 16 | +import javafx.scene.Scene; |
| 17 | +import javafx.scene.image.Image; |
| 18 | +import javafx.stage.Stage; |
| 19 | +import lombok.extern.slf4j.Slf4j; |
| 20 | + |
| 21 | +import java.util.ResourceBundle; |
| 22 | + |
| 23 | +/** |
| 24 | + * @ClassName: Main |
| 25 | + * @Description: 启动类 |
| 26 | + * @author: xufeng |
| 27 | + * @date: 2017年11月10日 下午4:34:11 |
| 28 | + */ |
| 29 | +@Slf4j |
| 30 | +public class Main extends Application { |
| 31 | + |
| 32 | + public static final String LOGO_PATH = "/images/icon.jpg"; |
| 33 | + |
| 34 | + private static Stage stage; |
| 35 | + |
| 36 | + public static void main(String[] args) { |
| 37 | + try { |
| 38 | + log.info("xJavaFxTool项目启动"); |
| 39 | + launch(args); |
| 40 | + } catch (Exception e) { |
| 41 | + log.error("xJavaFxTool启动失败:", e); |
| 42 | + } |
| 43 | + } |
| 44 | + |
| 45 | + @Override |
| 46 | + public void start(Stage primaryStage) throws Exception { |
| 47 | + |
| 48 | + // 初始化 JavaFX 全局设置 |
| 49 | + FxApp.init(primaryStage, LOGO_PATH); |
| 50 | + FxApp.styleSheets.add(Main.class.getResource("/css/jfoenix-main.css").toExternalForm()); |
| 51 | + |
| 52 | + XJavaFxSystemUtil.initSystemLocal();//初始化本地语言 |
| 53 | + XJavaFxSystemUtil.addJarByLibs();//添加外部jar包 |
| 54 | + |
| 55 | + FXMLLoader fXMLLoader = IndexController.getFXMLLoader(); |
| 56 | + ResourceBundle resourceBundle = fXMLLoader.getResources(); |
| 57 | + Parent root = fXMLLoader.load(); |
| 58 | + |
| 59 | + JFXDecorator decorator = JavaFxViewUtil.getJFXDecorator( |
| 60 | + primaryStage, |
| 61 | + resourceBundle.getString("Title") + Config.xJavaFxToolVersions, |
| 62 | + LOGO_PATH, |
| 63 | + root |
| 64 | + ); |
| 65 | + decorator.setOnCloseButtonAction(() -> confirmExit(null)); |
| 66 | + |
| 67 | + Scene scene = JavaFxViewUtil.getJFXDecoratorScene(decorator); |
| 68 | + |
| 69 | + primaryStage.setResizable(true); |
| 70 | + primaryStage.setTitle(resourceBundle.getString("Title"));//标题 |
| 71 | + primaryStage.getIcons().add(new Image(LOGO_PATH));//图标 |
| 72 | + primaryStage.setScene(scene); |
| 73 | + primaryStage.setOnCloseRequest(this::confirmExit); |
| 74 | + |
| 75 | + StageUtils.loadPrimaryStageBound(primaryStage); |
| 76 | + primaryStage.show(); |
| 77 | + |
| 78 | + StageUtils.updateStageStyle(primaryStage); |
| 79 | + stage = primaryStage; |
| 80 | + } |
| 81 | + |
| 82 | + private void confirmExit(Event event) { |
| 83 | + if (XJavaFxSystemUtil.getSystemConfigure().getBoolean("exitShowAlertCheckBox", true)) { |
| 84 | + if (AlertUtil.confirmOkCancel("退出应用", "确定要退出吗?")) { |
| 85 | + StageUtils.savePrimaryStageBound(stage); |
| 86 | + Platform.exit(); |
| 87 | + System.exit(0); |
| 88 | + } else if (event != null) { |
| 89 | + event.consume(); |
| 90 | + } |
| 91 | + } else { |
| 92 | + StageUtils.savePrimaryStageBound(stage); |
| 93 | + Platform.exit(); |
| 94 | + System.exit(0); |
| 95 | + } |
| 96 | + } |
| 97 | + |
| 98 | + public static Stage getStage() { |
| 99 | + return stage; |
| 100 | + } |
| 101 | + |
| 102 | + public static void setStage(Stage stage) { |
| 103 | + Main.stage = stage; |
| 104 | + } |
| 105 | +} |
0 commit comments