Skip to content

Commit 340b206

Browse files
authored
Merge pull request #5 from yiding-he/remember-window-position
Remember window position
2 parents 2cf7196 + 4bca16d commit 340b206

9 files changed

Lines changed: 336 additions & 200 deletions

File tree

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

Lines changed: 66 additions & 22 deletions
Original file line numberDiff line numberDiff line change
@@ -3,22 +3,23 @@
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;
67
import com.xwintop.xJavaFxTool.utils.StageUtils;
78
import com.xwintop.xJavaFxTool.utils.XJavaFxSystemUtil;
89
import com.xwintop.xcore.util.javafx.AlertUtil;
910
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
11+
import java.util.ResourceBundle;
12+
import java.util.prefs.Preferences;
1013
import javafx.application.Application;
11-
import javafx.event.EventHandler;
14+
import javafx.application.Platform;
15+
import javafx.event.Event;
1216
import javafx.fxml.FXMLLoader;
1317
import javafx.scene.Parent;
1418
import javafx.scene.Scene;
1519
import javafx.scene.image.Image;
1620
import javafx.stage.Stage;
17-
import javafx.stage.WindowEvent;
1821
import lombok.extern.slf4j.Slf4j;
1922

20-
import java.util.ResourceBundle;
21-
2223
/**
2324
* @ClassName: Main
2425
* @Description: 启动类
@@ -27,6 +28,9 @@
2728
*/
2829
@Slf4j
2930
public class Main extends Application {
31+
32+
public static final String PREFERENCE_ROOT = "com.xwintop.xJavaFxTool";
33+
3034
private static Stage stage;
3135

3236
public static void main(String[] args) {
@@ -46,35 +50,75 @@ public void start(Stage primaryStage) throws Exception {
4650
FXMLLoader fXMLLoader = IndexController.getFXMLLoader();
4751
ResourceBundle resourceBundle = fXMLLoader.getResources();
4852
Parent root = fXMLLoader.load();
49-
JFXDecorator decorator = JavaFxViewUtil.getJFXDecorator(primaryStage, resourceBundle.getString("Title") + Config.xJavaFxToolVersions, "/images/icon.jpg", root);
50-
decorator.setOnCloseButtonAction(() -> {
51-
if (AlertUtil.showConfirmAlert("确定要退出吗?")) {
52-
System.exit(0);
53-
}
54-
});
53+
54+
JFXDecorator decorator = JavaFxViewUtil.getJFXDecorator(
55+
primaryStage,
56+
resourceBundle.getString("Title") + Config.xJavaFxToolVersions,
57+
"/images/icon.jpg",
58+
root
59+
);
60+
decorator.setOnCloseButtonAction(() -> confirmExit(null));
61+
5562
Scene scene = JavaFxViewUtil.getJFXDecoratorScene(decorator);
56-
// Scene scene = new Scene(root);
63+
5764
primaryStage.setResizable(true);
5865
primaryStage.setTitle(resourceBundle.getString("Title"));//标题
5966
primaryStage.getIcons().add(new Image("/images/icon.jpg"));//图标
6067
primaryStage.setScene(scene);
61-
primaryStage.show();
68+
primaryStage.setOnCloseRequest(this::confirmExit);
6269

63-
primaryStage.setOnCloseRequest(new EventHandler<WindowEvent>() {
64-
@Override
65-
public void handle(WindowEvent event) {
66-
if (AlertUtil.showConfirmAlert("确定要退出吗?")) {
67-
System.exit(0);
68-
} else {
69-
event.consume();
70-
}
71-
}
72-
});
70+
loadPrimaryStageBound(primaryStage);
71+
primaryStage.show();
7372

7473
StageUtils.updateStageStyle(primaryStage);
7574
stage = primaryStage;
7675
}
7776

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+
101+
private void confirmExit(Event event) {
102+
if (AlertUtil.showConfirmAlert("确定要退出吗?")) {
103+
savePrimaryStageBound();
104+
Platform.exit();
105+
System.exit(0);
106+
} else if (event != null) {
107+
event.consume();
108+
}
109+
}
110+
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+
78122
public static Stage getStage() {
79123
return stage;
80124
}
Lines changed: 9 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -0,0 +1,9 @@
1+
package com.xwintop.xJavaFxTool.controller;
2+
3+
import com.xwintop.xJavaFxTool.view.NotepadView;
4+
5+
public class NotepadController extends NotepadView {
6+
7+
public void initialize() {
8+
}
9+
}

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

Lines changed: 12 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -5,22 +5,26 @@
55
import com.xwintop.xJavaFxTool.view.index.PluginManageView;
66
import com.xwintop.xcore.util.javafx.JavaFxViewUtil;
77
import com.xwintop.xcore.util.javafx.TooltipUtil;
8+
import java.net.URL;
9+
import java.util.Map;
10+
import java.util.ResourceBundle;
811
import javafx.collections.FXCollections;
912
import javafx.collections.ObservableList;
1013
import javafx.event.ActionEvent;
1114
import javafx.fxml.FXML;
1215
import javafx.fxml.FXMLLoader;
13-
import javafx.scene.control.*;
16+
import javafx.scene.control.Button;
17+
import javafx.scene.control.ContentDisplay;
18+
import javafx.scene.control.ContextMenu;
19+
import javafx.scene.control.MenuItem;
20+
import javafx.scene.control.TableCell;
21+
import javafx.scene.control.TableColumn;
1422
import javafx.scene.input.MouseButton;
1523
import javafx.util.Callback;
1624
import lombok.Getter;
1725
import lombok.Setter;
1826
import lombok.extern.slf4j.Slf4j;
1927

20-
import java.net.URL;
21-
import java.util.Map;
22-
import java.util.ResourceBundle;
23-
2428
/**
2529
* @ClassName: PluginManageController
2630
* @Description: 插件管理
@@ -114,6 +118,9 @@ private void initEvent() {
114118
pluginDataTableView.setContextMenu(new ContextMenu(menuSave));
115119
}
116120
});
121+
selectPluginTextField.textProperty().addListener((_ob, _old, _new) -> {
122+
pluginManageService.selectPluginAction();
123+
});
117124
}
118125

119126
private void initService() {

0 commit comments

Comments
 (0)