Skip to content

Commit f5334f0

Browse files
committed
1、更新xcore包版本为0.0.3;2、添加设置界面
1 parent 340b206 commit f5334f0

13 files changed

Lines changed: 294 additions & 55 deletions

File tree

pom.xml

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -60,7 +60,7 @@
6060
<dependency>
6161
<groupId>com.xwintop</groupId>
6262
<artifactId>xcore</artifactId>
63-
<version>0.0.2-SNAPSHOT</version>
63+
<version>0.0.3-SNAPSHOT</version>
6464
</dependency>
6565

6666
<!-- oshi获取系统信息工具 -->

src/main/java/com/xwintop/xJavaFxTool/Main.java

Lines changed: 18 additions & 48 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,10 @@
33
import com.jfoenix.controls.JFXDecorator;
44
import com.xwintop.xJavaFxTool.controller.IndexController;
55
import com.xwintop.xJavaFxTool.utils.Config;
6-
import com.xwintop.xJavaFxTool.utils.Config.Keys.MainWindow;
76
import com.xwintop.xJavaFxTool.utils.StageUtils;
87
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
98
import com.xwintop.xcore.util.javafx.AlertUtil;
109
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
11-
import java.util.ResourceBundle;
12-
import java.util.prefs.Preferences;
1310
import javafx.application.Application;
1411
import javafx.application.Platform;
1512
import javafx.event.Event;
@@ -20,6 +17,8 @@
2017
import javafx.stage.Stage;
2118
import 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+
}

src/main/java/com/xwintop/xJavaFxTool/controller/IndexController.java

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,7 @@
11
package com.xwintop.xJavaFxTool.controller;
22

33
import com.xwintop.xJavaFxTool.controller.index.PluginManageController;
4+
import com.xwintop.xJavaFxTool.controller.index.SystemSettingController;
45
import com.xwintop.xJavaFxTool.model.ToolFxmlLoaderConfiguration;
56
import com.xwintop.xJavaFxTool.services.IndexService;
67
import com.xwintop.xJavaFxTool.services.index.PluginManageService;
@@ -70,7 +71,9 @@ public void initialize(URL location, ResourceBundle resources) {
7071
initView();
7172
initEvent();
7273
initService();
73-
addNodepadAction(null);
74+
if (XJavaFxSystemUtil.getSystemConfigure().getBoolean("addNotepadCheckBox", true)) {
75+
addNodepadAction(null);
76+
}
7477
indexService.addWebView("欢迎吐槽", "https://support.qq.com/product/127577", null);
7578
tongjiWebView.getEngine().load("https://xwintop.gitee.io/maven/tongji/xJavaFxTool.html");
7679
}
@@ -265,6 +268,11 @@ private void pluginManageAction(ActionEvent event) throws Exception {
265268
JavaFxViewUtil.openNewWindow(bundle.getString("plugin_manage"), root);
266269
}
267270

271+
@FXML
272+
private void SettingAction(ActionEvent event) throws Exception {
273+
SystemSettingController.showSystemSetting(bundle.getString("Setting"));
274+
}
275+
268276
@FXML
269277
private void aboutAction(ActionEvent event) throws Exception {
270278
AlertUtil.showInfoAlert(bundle.getString("aboutText") + Config.xJavaFxToolVersions);
Lines changed: 94 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,94 @@
1+
package com.xwintop.xJavaFxTool.controller.index;
2+
3+
import com.xwintop.xJavaFxTool.controller.IndexController;
4+
import com.xwintop.xJavaFxTool.services.index.SystemSettingService;
5+
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
6+
import com.xwintop.xJavaFxTool.view.index.SystemSettingView;
7+
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
8+
import javafx.event.ActionEvent;
9+
import javafx.fxml.FXML;
10+
import javafx.fxml.FXMLLoader;
11+
import javafx.scene.Parent;
12+
import javafx.stage.Modality;
13+
import javafx.stage.Stage;
14+
import lombok.Getter;
15+
import lombok.Setter;
16+
import lombok.extern.slf4j.Slf4j;
17+
import org.apache.commons.configuration.PropertiesConfiguration;
18+
19+
import java.net.URL;
20+
import java.util.ResourceBundle;
21+
22+
/**
23+
* @ClassName: SystemSettingController
24+
* @Description: 设置页面
25+
* @author: xufeng
26+
* @date: 2020/2/25 0025 16:44
27+
*/
28+
29+
@Getter
30+
@Setter
31+
@Slf4j
32+
public class SystemSettingController extends SystemSettingView {
33+
private SystemSettingService systemSettingService = new SystemSettingService(this);
34+
private Stage newStage = null;
35+
36+
//显示设置界面
37+
public static void showSystemSetting(String title) throws Exception {
38+
FXMLLoader fXMLLoader = new FXMLLoader(IndexController.class.getResource("/com/xwintop/xJavaFxTool/fxmlView/index/SystemSetting.fxml"));
39+
Parent root = fXMLLoader.load();
40+
SystemSettingController systemSettingController = fXMLLoader.getController();
41+
Stage newStage = JavaFxViewUtil.getNewStageNull(title, null, root, -1, -1, false, false, false);
42+
newStage.initModality(Modality.APPLICATION_MODAL);
43+
systemSettingController.setNewStage(newStage);
44+
newStage.showAndWait();
45+
}
46+
47+
@Override
48+
public void initialize(URL location, ResourceBundle resources) {
49+
initView();
50+
initEvent();
51+
initService();
52+
}
53+
54+
private void initView() {
55+
try {
56+
PropertiesConfiguration xmlConfigure = XJavaFxSystemUtil.getSystemConfigure();
57+
exitShowAlertCheckBox.setSelected(xmlConfigure.getBoolean("exitShowAlertCheckBox", true));
58+
addNotepadCheckBox.setSelected(xmlConfigure.getBoolean("addNotepadCheckBox", true));
59+
saveStageBoundCheckBox.setSelected(xmlConfigure.getBoolean("saveStageBoundCheckBox", true));
60+
} catch (Exception e) {
61+
log.error("加载配置失败:", e);
62+
}
63+
64+
}
65+
66+
private void initEvent() {
67+
}
68+
69+
private void initService() {
70+
}
71+
72+
@FXML
73+
private void saveAction(ActionEvent event) {
74+
try {
75+
PropertiesConfiguration xmlConfigure = XJavaFxSystemUtil.getSystemConfigure();
76+
xmlConfigure.setProperty("exitShowAlertCheckBox", exitShowAlertCheckBox.isSelected());
77+
xmlConfigure.setProperty("addNotepadCheckBox", addNotepadCheckBox.isSelected());
78+
xmlConfigure.setProperty("saveStageBoundCheckBox", saveStageBoundCheckBox.isSelected());
79+
xmlConfigure.save();
80+
if (newStage != null) {
81+
newStage.close();
82+
}
83+
} catch (Exception e) {
84+
log.error("保存配置失败:", e);
85+
}
86+
}
87+
88+
@FXML
89+
private void cancelAction(ActionEvent event) {
90+
if (newStage != null) {
91+
newStage.close();
92+
}
93+
}
94+
}

src/main/java/com/xwintop/xJavaFxTool/services/IndexService.java

Lines changed: 2 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -4,6 +4,7 @@
44
import com.xwintop.xJavaFxTool.controller.IndexController;
55
import com.xwintop.xJavaFxTool.utils.Config;
66
import com.xwintop.xJavaFxTool.utils.FxmlUtils;
7+
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
78
import com.xwintop.xcore.util.ConfigureUtil;
89
import com.xwintop.xcore.util.javafx.AlertUtil;
910
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
@@ -38,9 +39,7 @@ public IndexService(IndexController indexController) {
3839
}
3940

4041
public void setLanguageAction(String languageType) throws Exception {
41-
File file = ConfigureUtil.getConfigureFile("systemConfigure.properties");
42-
FileUtils.touch(file);
43-
PropertiesConfiguration xmlConfigure = new PropertiesConfiguration(file);
42+
PropertiesConfiguration xmlConfigure = XJavaFxSystemUtil.getSystemConfigure();
4443
if ("简体中文".equals(languageType)) {
4544
xmlConfigure.setProperty("Locale", Locale.SIMPLIFIED_CHINESE);
4645
} else if ("English".equals(languageType)) {
Lines changed: 24 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,24 @@
1+
package com.xwintop.xJavaFxTool.services.index;
2+
3+
import com.xwintop.xJavaFxTool.controller.index.SystemSettingController;
4+
import lombok.Getter;
5+
import lombok.Setter;
6+
import lombok.extern.slf4j.Slf4j;
7+
8+
/**
9+
* @ClassName: SystemSettingService
10+
* @Description: 设置页面
11+
* @author: xufeng
12+
* @date: 2020/2/25 0025 16:44
13+
*/
14+
15+
@Getter
16+
@Setter
17+
@Slf4j
18+
public class SystemSettingService {
19+
private SystemSettingController systemSettingController;
20+
21+
public SystemSettingService(SystemSettingController systemSettingController) {
22+
this.systemSettingController = systemSettingController;
23+
}
24+
}

src/main/java/com/xwintop/xJavaFxTool/utils/StageUtils.java

Lines changed: 54 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -10,8 +10,12 @@
1010
import com.sun.jna.platform.win32.WinUser;
1111
import com.sun.jna.win32.StdCallLibrary;
1212
import com.sun.jna.win32.W32APIOptions;
13+
import com.xwintop.xcore.util.ConfigureUtil;
1314
import javafx.stage.Stage;
15+
import lombok.extern.slf4j.Slf4j;
16+
import org.apache.commons.configuration.PropertiesConfiguration;
1417

18+
import java.io.File;
1519
import java.lang.reflect.Method;
1620

1721
/**
@@ -21,6 +25,7 @@
2125
* @date: 2020/1/2 15:56
2226
*/
2327

28+
@Slf4j
2429
public class StageUtils {
2530

2631
static interface ExtUser32 extends StdCallLibrary, User32 {
@@ -59,5 +64,54 @@ private static Pointer getWindowPointer(Stage stage) {
5964
return null;
6065
}
6166
}
67+
68+
//加载Stage边框位置
69+
public static void loadPrimaryStageBound(Stage stage) {
70+
try {
71+
if (!XJavaFxSystemUtil.getSystemConfigure().getBoolean("saveStageBoundCheckBox", true)) {
72+
return;
73+
}
74+
PropertiesConfiguration xmlConfigure = XJavaFxSystemUtil.getSystemConfigure();
75+
double left = xmlConfigure.getDouble(Config.Keys.MainWindow.LEFT, -1);
76+
double top = xmlConfigure.getDouble(Config.Keys.MainWindow.TOP, -1);
77+
double width = xmlConfigure.getDouble(Config.Keys.MainWindow.WIDTH, -1);
78+
double height = xmlConfigure.getDouble(Config.Keys.MainWindow.HEIGHT, -1);
79+
80+
if (left > 0) {
81+
stage.setX(left);
82+
}
83+
if (top > 0) {
84+
stage.setY(top);
85+
}
86+
if (width > 0) {
87+
stage.setWidth(width);
88+
}
89+
if (height > 0) {
90+
stage.setHeight(height);
91+
}
92+
} catch (Exception e) {
93+
log.error("初始化界面位置失败:", e);
94+
}
95+
}
96+
97+
//保存Stage边框位置
98+
public static void savePrimaryStageBound(Stage stage) {
99+
if (!XJavaFxSystemUtil.getSystemConfigure().getBoolean("saveStageBoundCheckBox", true)) {
100+
return;
101+
}
102+
if (stage == null || stage.isIconified()) {
103+
return;
104+
}
105+
try {
106+
PropertiesConfiguration xmlConfigure = XJavaFxSystemUtil.getSystemConfigure();
107+
xmlConfigure.setProperty(Config.Keys.MainWindow.LEFT, stage.getX());
108+
xmlConfigure.setProperty(Config.Keys.MainWindow.TOP, stage.getY());
109+
xmlConfigure.setProperty(Config.Keys.MainWindow.WIDTH, stage.getWidth());
110+
xmlConfigure.setProperty(Config.Keys.MainWindow.HEIGHT, stage.getHeight());
111+
xmlConfigure.save();
112+
} catch (Exception e) {
113+
log.error("初始化界面位置失败:", e);
114+
}
115+
}
62116
}
63117

0 commit comments

Comments
 (0)