diff --git a/NeoSuit/src/main/java/ui/shared/MainApp.java b/NeoSuit/src/main/java/ui/shared/MainApp.java index c29a9228099c7f7a73dde773274bacb260880983..82db54a3ca0417141cad5ef651f1fb67c3d587d0 100644 --- a/NeoSuit/src/main/java/ui/shared/MainApp.java +++ b/NeoSuit/src/main/java/ui/shared/MainApp.java @@ -1,8 +1,12 @@ package ui.shared; import java.io.IOException; +import java.util.Timer; +import java.util.TimerTask; import javafx.application.Application; +import javafx.beans.value.ChangeListener; +import javafx.beans.value.ObservableValue; import javafx.fxml.FXMLLoader; import javafx.scene.Scene; import javafx.scene.layout.AnchorPane; @@ -33,7 +37,7 @@ public class MainApp extends Application { * Show a screen in the center of the main window * * @param location - * path to fxml file + * path to fxml file (without screen) * @return */ public ConnectedControl showScreen(String location) { @@ -61,8 +65,8 @@ public class MainApp extends Application { loader.setLocation(MainApp.class.getResource("RootLayout.fxml")); rootLayout = (BorderPane) loader.load(); - // Show the scene containing the root layout. Scene scene = new Scene(rootLayout); + addResizeListener(); primaryStage.setScene(scene); primaryStage.show(); } catch (IOException e) { @@ -70,6 +74,36 @@ public class MainApp extends Application { } } + private void addResizeListener() { + ChangeListener<Number> listener = new ChangeListener<Number>() { + final Timer timer = new Timer(); // uses a timer to call your + // resize method + TimerTask task = null; // task to execute after defined delay + final long delayTime = 200; // delay that has to pass in order + // to consider an operation done + + public void changed(ObservableValue<? extends Number> observable, Number oldValue, Number newValue) { + if (task != null) { // there was already a task scheduled + // from the previous operation ... + task.cancel(); // cancel it, we have a new size to + // consider + } + + task = new TimerTask() { + @Override + public void run() { + // here you can place your resize code + System.out.println("resize to " + primaryStage.getWidth() + " " + primaryStage.getHeight()); + } + }; + // schedule new task + timer.schedule(task, delayTime); + } + }; + primaryStage.widthProperty().addListener(listener); + primaryStage.heightProperty().addListener(listener); + } + /** * Returns the main stage. * diff --git a/NeoSuit/src/main/java/ui/shared/ModeSelectScreen.fxml b/NeoSuit/src/main/java/ui/shared/ModeSelectScreen.fxml index 6408a0d0ef69c4f83a4eaf82c73df7fc138bced7..7c7a265ab61e5d29f220df41f3a959313181fd25 100644 --- a/NeoSuit/src/main/java/ui/shared/ModeSelectScreen.fxml +++ b/NeoSuit/src/main/java/ui/shared/ModeSelectScreen.fxml @@ -6,11 +6,9 @@ <?import javafx.scene.layout.*?> <?import javafx.scene.layout.AnchorPane?> -<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" - xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" - fx:controller="ui.shared.ModeSelectScreen"> +<AnchorPane maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="400.0" minWidth="600.0" xmlns="http://javafx.com/javafx/8.0.40" xmlns:fx="http://javafx.com/fxml/1" fx:controller="ui.shared.ModeSelectScreen"> <children> - <GridPane prefHeight="431.0" prefWidth="528.0"> + <GridPane gridLinesVisible="true" maxHeight="1.7976931348623157E308" maxWidth="1.7976931348623157E308" minHeight="400.0" minWidth="600.0"> <columnConstraints> <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" /> <ColumnConstraints hgrow="ALWAYS" minWidth="10.0" prefWidth="100.0" />