Skip to content

Commit 1b25147

Browse files
committed
添加新版 launcher 的配置,允许回到旧版主界面
1 parent f8f8e72 commit 1b25147

10 files changed

Lines changed: 171 additions & 127 deletions

File tree

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

Lines changed: 37 additions & 26 deletions
Original file line numberDiff line numberDiff line change
@@ -8,19 +8,19 @@
88
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
99
import com.xwintop.xcore.javafx.FxApp;
1010
import com.xwintop.xcore.javafx.dialog.FxAlerts;
11+
import com.xwintop.xcore.javafx.helper.FxmlHelper;
1112
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
13+
import java.io.IOException;
14+
import java.util.ResourceBundle;
1215
import javafx.application.Application;
1316
import javafx.application.Platform;
1417
import javafx.event.Event;
1518
import javafx.fxml.FXMLLoader;
1619
import javafx.scene.Parent;
1720
import javafx.scene.Scene;
18-
import javafx.scene.image.Image;
1921
import javafx.stage.Stage;
2022
import lombok.extern.slf4j.Slf4j;
2123

22-
import java.util.ResourceBundle;
23-
2424
/**
2525
* @ClassName: Main
2626
* @Description: 启动类
@@ -32,70 +32,81 @@ public class Main extends Application {
3232

3333
public static final String LOGO_PATH = "/images/icon.jpg";
3434

35+
public static final ResourceBundle RESOURCE_BUNDLE =
36+
ResourceBundle.getBundle("locale.Menu", Config.defaultLocale);
37+
3538
private static Stage stage;
3639

3740
public static void main(String[] args) {
38-
try {
39-
log.info("xJavaFxTool项目启动");
40-
launch(args);
41-
} catch (Exception e) {
42-
log.error("xJavaFxTool启动失败:", e);
43-
}
41+
launch(args);
4442
}
4543

4644
@Override
4745
public void start(Stage primaryStage) throws Exception {
46+
stage = primaryStage;
4847

4948
// 初始化 JavaFX 全局设置
5049
FxApp.init(primaryStage, LOGO_PATH);
50+
FxApp.setupIcon(primaryStage);
5151
FxApp.styleSheets.add(Main.class.getResource("/css/jfoenix-main.css").toExternalForm());
5252

5353
XJavaFxSystemUtil.initSystemLocal();//初始化本地语言
5454
XJavaFxSystemUtil.addJarByLibs();//添加外部jar包
5555

56+
primaryStage.setResizable(true);
57+
primaryStage.setTitle(RESOURCE_BUNDLE.getString("Title") + Config.xJavaFxToolVersions);
58+
primaryStage.setOnCloseRequest(this::confirmExit);
59+
60+
if (Config.getBoolean(Keys.NewLauncher, false)) {
61+
loadNewUI(primaryStage);
62+
} else {
63+
loadClassicUI(primaryStage);
64+
}
65+
66+
StageUtils.loadPrimaryStageBound(primaryStage);
67+
primaryStage.show();
68+
}
69+
70+
private void loadNewUI(Stage primaryStage) {
71+
FxmlHelper.loadIntoStage("/com/xwintop/xJavaFxTool/fxmlView/newui/main.fxml", primaryStage).show();
72+
}
73+
74+
private void loadClassicUI(Stage primaryStage) throws IOException {
5675
FXMLLoader fXMLLoader = IndexController.getFXMLLoader();
57-
ResourceBundle resourceBundle = fXMLLoader.getResources();
5876
Parent root = fXMLLoader.load();
5977

6078
JFXDecorator decorator = JavaFxViewUtil.getJFXDecorator(
6179
primaryStage,
62-
resourceBundle.getString("Title") + Config.xJavaFxToolVersions,
80+
RESOURCE_BUNDLE.getString("Title") + Config.xJavaFxToolVersions,
6381
LOGO_PATH,
6482
root
6583
);
6684
decorator.setOnCloseButtonAction(() -> confirmExit(null));
6785

6886
Scene scene = JavaFxViewUtil.getJFXDecoratorScene(decorator);
69-
70-
primaryStage.setResizable(true);
71-
primaryStage.setTitle(resourceBundle.getString("Title"));//标题
72-
primaryStage.getIcons().add(new Image(LOGO_PATH));//图标
7387
primaryStage.setScene(scene);
74-
primaryStage.setOnCloseRequest(this::confirmExit);
75-
76-
StageUtils.loadPrimaryStageBound(primaryStage);
77-
primaryStage.show();
7888

7989
StageUtils.updateStageStyle(primaryStage);
80-
stage = primaryStage;
8190
}
8291

8392
private void confirmExit(Event event) {
8493
if (Config.getBoolean(Keys.ConfirmExit, true)) {
8594
if (FxAlerts.confirmYesNo("退出应用", "确定要退出吗?")) {
86-
StageUtils.savePrimaryStageBound(stage);
87-
Platform.exit();
88-
System.exit(0);
95+
doExit();
8996
} else if (event != null) {
9097
event.consume();
9198
}
9299
} else {
93-
StageUtils.savePrimaryStageBound(stage);
94-
Platform.exit();
95-
System.exit(0);
100+
doExit();
96101
}
97102
}
98103

104+
private void doExit() {
105+
StageUtils.savePrimaryStageBound(stage);
106+
Platform.exit();
107+
System.exit(0);
108+
}
109+
99110
public static Stage getStage() {
100111
return stage;
101112
}

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

Lines changed: 29 additions & 42 deletions
Original file line numberDiff line numberDiff line change
@@ -1,26 +1,37 @@
11
package com.xwintop.xJavaFxTool.controller;
22

3+
import static com.xwintop.xJavaFxTool.Main.RESOURCE_BUNDLE;
4+
import static com.xwintop.xJavaFxTool.utils.Config.Keys.NotepadEnabled;
5+
36
import com.xwintop.xJavaFxTool.controller.index.PluginManageController;
4-
import com.xwintop.xJavaFxTool.controller.index.SystemSettingController;
57
import com.xwintop.xJavaFxTool.model.ToolFxmlLoaderConfiguration;
68
import com.xwintop.xJavaFxTool.services.IndexService;
79
import com.xwintop.xJavaFxTool.services.index.PluginManageService;
10+
import com.xwintop.xJavaFxTool.services.index.SystemSettingService;
811
import com.xwintop.xJavaFxTool.utils.Config;
912
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
1013
import com.xwintop.xJavaFxTool.view.IndexView;
11-
import com.xwintop.xcore.javafx.FxApp;
12-
import com.xwintop.xcore.javafx.dialog.FxDialog;
1314
import com.xwintop.xcore.util.ConfigureUtil;
1415
import com.xwintop.xcore.util.HttpClientUtil;
1516
import com.xwintop.xcore.util.javafx.AlertUtil;
1617
import com.xwintop.xcore.util.javafx.JavaFxSystemUtil;
1718
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
19+
import java.io.File;
20+
import java.io.InputStream;
21+
import java.net.URL;
22+
import java.util.ArrayList;
23+
import java.util.Date;
24+
import java.util.HashMap;
25+
import java.util.List;
26+
import java.util.Map;
27+
import java.util.ResourceBundle;
28+
import java.util.jar.JarEntry;
29+
import java.util.jar.JarFile;
1830
import javafx.application.Platform;
1931
import javafx.event.ActionEvent;
2032
import javafx.fxml.FXML;
2133
import javafx.fxml.FXMLLoader;
2234
import javafx.scene.Parent;
23-
import javafx.scene.control.ButtonType;
2435
import javafx.scene.control.ContextMenu;
2536
import javafx.scene.control.Menu;
2637
import javafx.scene.control.MenuItem;
@@ -38,15 +49,6 @@
3849
import org.dom4j.tree.DefaultAttribute;
3950
import org.dom4j.tree.DefaultElement;
4051

41-
import java.io.File;
42-
import java.io.InputStream;
43-
import java.net.URL;
44-
import java.util.*;
45-
import java.util.jar.JarEntry;
46-
import java.util.jar.JarFile;
47-
48-
import static com.xwintop.xJavaFxTool.utils.Config.Keys.NotepadEnabled;
49-
5052
/**
5153
* @ClassName: IndexController
5254
* @Description: 主页
@@ -71,9 +73,8 @@ public class IndexController extends IndexView {
7173
private ContextMenu contextMenu = new ContextMenu();
7274

7375
public static FXMLLoader getFXMLLoader() {
74-
ResourceBundle resourceBundle = ResourceBundle.getBundle("locale.Menu", Config.defaultLocale);
7576
URL url = Object.class.getResource("/com/xwintop/xJavaFxTool/fxmlView/Index.fxml");
76-
return new FXMLLoader(url, resourceBundle);
77+
return new FXMLLoader(url, RESOURCE_BUNDLE);
7778
}
7879

7980
@Override
@@ -240,18 +241,18 @@ public void selectAction(String selectText) {
240241
}
241242

242243
@FXML
243-
private void exitAction(ActionEvent event) {
244+
private void exitAction() {
244245
Platform.exit();
245246
System.exit(0);
246247
}
247248

248249
@FXML
249-
private void closeAllTabAction(ActionEvent event) {
250+
private void closeAllTabAction() {
250251
tabPaneMain.getTabs().clear();
251252
}
252253

253254
@FXML
254-
private void openAllTabAction(ActionEvent event) {
255+
private void openAllTabAction() {
255256
for (MenuItem value : menuItemMap.values()) {
256257
value.fire();
257258
}
@@ -268,7 +269,7 @@ private void addLogConsoleAction(ActionEvent event) {
268269
}
269270

270271
@FXML
271-
private void pluginManageAction(ActionEvent event) throws Exception {
272+
private void pluginManageAction() throws Exception {
272273
FXMLLoader fXMLLoader = PluginManageController.getFXMLLoader();
273274
Parent root = fXMLLoader.load();
274275
PluginManageController pluginManageController = fXMLLoader.getController();
@@ -277,26 +278,12 @@ private void pluginManageAction(ActionEvent event) throws Exception {
277278
}
278279

279280
@FXML
280-
private void SettingAction(ActionEvent event) throws Exception {
281-
282-
FxDialog<SystemSettingController> dialog = new FxDialog<SystemSettingController>()
283-
.setTitle(bundle.getString("Setting"))
284-
.setBodyFxml("/com/xwintop/xJavaFxTool/fxmlView/index/SystemSetting.fxml")
285-
.setOwner(FxApp.primaryStage)
286-
.setButtonTypes(ButtonType.OK, ButtonType.CANCEL);
287-
288-
SystemSettingController controller = dialog.show();
289-
290-
dialog
291-
.setButtonHandler(ButtonType.OK, (actionEvent, stage) -> {
292-
controller.applySettings();
293-
stage.close();
294-
})
295-
.setButtonHandler(ButtonType.CANCEL, (actionEvent, stage) -> stage.close());
281+
private void SettingAction() {
282+
SystemSettingService.openSystemSettings(bundle.getString("Setting"));
296283
}
297284

298285
@FXML
299-
private void aboutAction(ActionEvent event) throws Exception {
286+
private void aboutAction() {
300287
AlertUtil.showInfoAlert(bundle.getString("aboutText") + Config.xJavaFxToolVersions);
301288
}
302289

@@ -307,33 +294,33 @@ private void setLanguageAction(ActionEvent event) throws Exception {
307294
}
308295

309296
@FXML
310-
private void openLogFileAction(ActionEvent event) throws Exception {
297+
private void openLogFileAction() {
311298
String filePath = "logs/logFile." + DateFormatUtils.format(new Date(), "yyyy-MM-dd") + ".log";
312299
JavaFxSystemUtil.openDirectory(filePath);
313300
}
314301

315302
@FXML
316-
private void openLogFolderAction(ActionEvent event) throws Exception {
303+
private void openLogFolderAction() {
317304
JavaFxSystemUtil.openDirectory("logs/");
318305
}
319306

320307
@FXML
321-
private void openConfigFolderAction(ActionEvent event) throws Exception {
308+
private void openConfigFolderAction() {
322309
JavaFxSystemUtil.openDirectory(ConfigureUtil.getConfigurePath());
323310
}
324311

325312
@FXML
326-
private void openPluginFolderAction(ActionEvent event) throws Exception {
313+
private void openPluginFolderAction() {
327314
JavaFxSystemUtil.openDirectory("libs/");
328315
}
329316

330317
@FXML
331-
private void xwintopLinkOnAction(ActionEvent event) throws Exception {
318+
private void xwintopLinkOnAction() throws Exception {
332319
HttpClientUtil.openBrowseURLThrowsException("https://gitee.com/xwintop/xJavaFxTool");
333320
}
334321

335322
@FXML
336-
private void userSupportAction(ActionEvent event) throws Exception {
323+
private void userSupportAction() throws Exception {
337324
HttpClientUtil.openBrowseURLThrowsException("https://support.qq.com/product/127577");
338325
}
339326
}

src/main/java/com/xwintop/xJavaFxTool/controller/index/SystemSettingController.java

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1,17 +1,15 @@
11
package com.xwintop.xJavaFxTool.controller.index;
22

3-
import com.xwintop.xJavaFxTool.services.index.SystemSettingService;
43
import com.xwintop.xJavaFxTool.utils.Config;
54
import com.xwintop.xJavaFxTool.utils.Config.Keys;
65
import com.xwintop.xJavaFxTool.view.index.SystemSettingView;
6+
import java.net.URL;
7+
import java.util.ResourceBundle;
78
import javafx.stage.Stage;
89
import lombok.Getter;
910
import lombok.Setter;
1011
import lombok.extern.slf4j.Slf4j;
1112

12-
import java.net.URL;
13-
import java.util.ResourceBundle;
14-
1513
/**
1614
* @ClassName: SystemSettingController
1715
* @Description: 设置页面
@@ -24,8 +22,6 @@
2422
@Slf4j
2523
public class SystemSettingController extends SystemSettingView {
2624

27-
private SystemSettingService systemSettingService = new SystemSettingService(this);
28-
2925
private Stage newStage = null;
3026

3127
@Override
@@ -38,6 +34,7 @@ private void initView() {
3834
exitShowAlertCheckBox.setSelected(Config.getBoolean(Keys.ConfirmExit, true));
3935
addNotepadCheckBox.setSelected(Config.getBoolean(Keys.NotepadEnabled, true));
4036
saveStageBoundCheckBox.setSelected(Config.getBoolean(Keys.RememberWindowLocation, true));
37+
chkNewLauncher.setSelected(Config.getBoolean(Keys.NewLauncher, false));
4138
} catch (Exception e) {
4239
log.error("加载配置失败:", e);
4340
}
@@ -48,6 +45,7 @@ public void applySettings() {
4845
Config.set(Keys.ConfirmExit, exitShowAlertCheckBox.isSelected());
4946
Config.set(Keys.NotepadEnabled, addNotepadCheckBox.isSelected());
5047
Config.set(Keys.RememberWindowLocation, saveStageBoundCheckBox.isSelected());
48+
Config.set(Keys.NewLauncher, chkNewLauncher.isSelected());
5149

5250
if (newStage != null) {
5351
newStage.close();
Lines changed: 10 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,10 @@
1+
package com.xwintop.xJavaFxTool.newui;
2+
3+
import com.xwintop.xJavaFxTool.services.index.SystemSettingService;
4+
5+
public class NewLauncherController {
6+
7+
public void openConfigDialog() {
8+
SystemSettingService.openSystemSettings("设置");
9+
}
10+
}

src/main/java/com/xwintop/xJavaFxTool/services/index/SystemSettingService.java

Lines changed: 19 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -1,6 +1,9 @@
11
package com.xwintop.xJavaFxTool.services.index;
22

33
import com.xwintop.xJavaFxTool.controller.index.SystemSettingController;
4+
import com.xwintop.xcore.javafx.FxApp;
5+
import com.xwintop.xcore.javafx.dialog.FxDialog;
6+
import javafx.scene.control.ButtonType;
47
import lombok.Getter;
58
import lombok.Setter;
69
import lombok.extern.slf4j.Slf4j;
@@ -16,9 +19,22 @@
1619
@Setter
1720
@Slf4j
1821
public class SystemSettingService {
19-
private SystemSettingController systemSettingController;
2022

21-
public SystemSettingService(SystemSettingController systemSettingController) {
22-
this.systemSettingController = systemSettingController;
23+
public static void openSystemSettings(String title) {
24+
25+
FxDialog<SystemSettingController> dialog = new FxDialog<SystemSettingController>()
26+
.setTitle(title)
27+
.setBodyFxml("/com/xwintop/xJavaFxTool/fxmlView/index/SystemSetting.fxml")
28+
.setOwner(FxApp.primaryStage)
29+
.setButtonTypes(ButtonType.OK, ButtonType.CANCEL);
30+
31+
SystemSettingController controller = dialog.show();
32+
33+
dialog
34+
.setButtonHandler(ButtonType.OK, (actionEvent, stage) -> {
35+
controller.applySettings();
36+
stage.close();
37+
})
38+
.setButtonHandler(ButtonType.CANCEL, (actionEvent, stage) -> stage.close());
2339
}
2440
}

0 commit comments

Comments
 (0)