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.
This commit is contained in:
0xboobface 2018-09-05 14:24:22 +02:00
parent 7d36586b04
commit 9ba0fd624f
3 changed files with 18 additions and 2 deletions

View File

@ -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
========================

View File

@ -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;
}

View File

@ -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<Tab>() {
@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();