From 9ba0fd624ff475a9feeb0892908716fe414dd897 Mon Sep 17 00:00:00 2001 From: 0xboobface <0xboobface@gmail.com> Date: Wed, 5 Sep 2018 14:24:22 +0200 Subject: [PATCH] Save and restore window size, location and maximized state Save and restore window size, location and maximized state so that the window opens in the exact same state as when it has been closed. --- CHANGELOG.md | 1 + src/main/java/ctbrec/Settings.java | 6 +++++- src/main/java/ctbrec/ui/Launcher.java | 13 ++++++++++++- 3 files changed, 18 insertions(+), 2 deletions(-) diff --git a/CHANGELOG.md b/CHANGELOG.md index 98feba2f..f16e3bfc 100644 --- a/CHANGELOG.md +++ b/CHANGELOG.md @@ -2,6 +2,7 @@ ======================== * Added possibility to switch the video resolution for a recording * Added selection box below the overview pages to change the thumbnail size +* Save and restore window size, location and maximized state 1.4.2 ======================== diff --git a/src/main/java/ctbrec/Settings.java b/src/main/java/ctbrec/Settings.java index cf96ce5e..a552ffab 100644 --- a/src/main/java/ctbrec/Settings.java +++ b/src/main/java/ctbrec/Settings.java @@ -38,5 +38,9 @@ public class Settings { public String proxyUser; public String proxyPassword; public int thumbWidth = 180; - + public int windowWidth = 1340; + public int windowHeight = 800; + public boolean windowMaximized = false; + public int windowX; + public int windowY; } diff --git a/src/main/java/ctbrec/ui/Launcher.java b/src/main/java/ctbrec/ui/Launcher.java index 718f496a..506818ce 100644 --- a/src/main/java/ctbrec/ui/Launcher.java +++ b/src/main/java/ctbrec/ui/Launcher.java @@ -64,6 +64,7 @@ public class Launcher extends Application { primaryStage.setTitle("CTB Recorder " + getVersion()); InputStream icon = getClass().getResourceAsStream("/icon.png"); primaryStage.getIcons().add(new Image(icon)); + tabPane = new TabPane(); tabPane.getSelectionModel().selectedItemProperty().addListener(new ChangeListener() { @Override @@ -93,7 +94,17 @@ public class Launcher extends Application { tabPane.getTabs().add(settingsTab); tabPane.getTabs().add(new DonateTabFx()); - primaryStage.setScene(new Scene(tabPane, 1340, 800)); + int windowWidth = Config.getInstance().getSettings().windowWidth; + int windowHeight = Config.getInstance().getSettings().windowHeight; + primaryStage.setScene(new Scene(tabPane, windowWidth, windowHeight)); + primaryStage.getScene().widthProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowWidth = newVal.intValue()); + primaryStage.getScene().heightProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowHeight = newVal.intValue()); + primaryStage.setMaximized(Config.getInstance().getSettings().windowMaximized); + primaryStage.maximizedProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowMaximized = newVal.booleanValue()); + primaryStage.setX(Config.getInstance().getSettings().windowX); + primaryStage.setY(Config.getInstance().getSettings().windowY); + primaryStage.xProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowX = newVal.intValue()); + primaryStage.yProperty().addListener((observable, oldVal, newVal) -> Config.getInstance().getSettings().windowY = newVal.intValue()); primaryStage.show(); primaryStage.setOnCloseRequest((e) -> { e.consume();