From 810ea9ace961fc1e09bc61841b6170929b3422e5 Mon Sep 17 00:00:00 2001 From: huanghongxun Date: Fri, 24 Apr 2020 23:12:58 +0800 Subject: [PATCH] add: remember window size --- .../java/org/jackhuang/hmcl/Launcher.java | 6 ++++ .../org/jackhuang/hmcl/setting/Config.java | 30 +++++++++++++++++++ .../org/jackhuang/hmcl/ui/Controllers.java | 13 ++++++++ 3 files changed, 49 insertions(+) diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java index 8762f610d..1158b2e1b 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/Launcher.java @@ -74,6 +74,12 @@ public final class Launcher extends Application { } } + @Override + public void stop() throws Exception { + super.stop(); + Controllers.onApplicationStop(); + } + public static void main(String[] args) { Thread.setDefaultUncaughtExceptionHandler(CRASH_REPORTER); AsyncTaskExecutor.setUncaughtExceptionHandler(new CrashReporter(false)); diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java index c41786138..aa18ee3f7 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/setting/Config.java @@ -110,6 +110,12 @@ public final class Config implements Cloneable, Observable { @SerializedName("proxyPassword") private StringProperty proxyPass = new SimpleStringProperty(); + @SerializedName("width") + private DoubleProperty width = new SimpleDoubleProperty(); + + @SerializedName("height") + private DoubleProperty height = new SimpleDoubleProperty(); + @SerializedName("theme") private ObjectProperty theme = new SimpleObjectProperty<>(Theme.BLUE); @@ -329,6 +335,30 @@ public final class Config implements Cloneable, Observable { return proxyPass; } + public double getWidth() { + return width.get(); + } + + public DoubleProperty widthProperty() { + return width; + } + + public void setWidth(double width) { + this.width.set(width); + } + + public double getHeight() { + return height.get(); + } + + public DoubleProperty heightProperty() { + return height; + } + + public void setHeight(double height) { + this.height.set(height); + } + public Theme getTheme() { return theme.get(); } diff --git a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java index eda9e3bbb..92c92ef2e 100644 --- a/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java +++ b/HMCL/src/main/java/org/jackhuang/hmcl/ui/Controllers.java @@ -17,6 +17,8 @@ */ package org.jackhuang.hmcl.ui; +import javafx.beans.property.DoubleProperty; +import javafx.beans.property.SimpleDoubleProperty; import javafx.scene.Node; import javafx.scene.Scene; import javafx.scene.layout.Region; @@ -50,6 +52,8 @@ import static org.jackhuang.hmcl.ui.FXUtils.newImage; import static org.jackhuang.hmcl.util.i18n.I18n.i18n; public final class Controllers { + private static DoubleProperty stageWidth = new SimpleDoubleProperty(); + private static DoubleProperty stageHeight = new SimpleDoubleProperty(); private static Scene scene; private static Stage stage; @@ -92,12 +96,21 @@ public final class Controllers { return decorator; } + public static void onApplicationStop() { + config().setHeight(stageHeight.get()); + config().setWidth(stageWidth.get()); + } public static void initialize(Stage stage) { Logging.LOG.info("Start initializing application"); Controllers.stage = stage; + stage.setHeight(config().getHeight()); + stageHeight.bind(stage.heightProperty()); + stage.setWidth(config().getWidth()); + stageWidth.bind(stage.widthProperty()); + stage.setOnCloseRequest(e -> Launcher.stopApplication()); decorator = new DecoratorController(stage, getRootPage());