From 810be46e17d1e664e62884f84da8be5906afaffb Mon Sep 17 00:00:00 2001 From: Asger Gitz-Johansen Date: Wed, 7 Dec 2022 10:06:42 +0100 Subject: [PATCH 1/3] feat: add a preloader to indicate that the project is loading --- src/main/java/dk/cs/aau/huppaal/HUPPAAL.java | 220 +++++++----------- .../dk/cs/aau/huppaal/HUPPAALPreloader.java | 56 +++++ .../controllers/HUPPAALController.java | 43 ++++ .../controllers/PreloaderController.java | 22 ++ .../presentations/PreloaderPresentation.java | 18 ++ .../presentations/PreloaderPresentation.fxml | 43 ++++ 6 files changed, 271 insertions(+), 131 deletions(-) create mode 100644 src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java create mode 100644 src/main/java/dk/cs/aau/huppaal/controllers/PreloaderController.java create mode 100644 src/main/java/dk/cs/aau/huppaal/presentations/PreloaderPresentation.java create mode 100644 src/main/resources/dk/cs/aau/huppaal/presentations/PreloaderPresentation.fxml diff --git a/src/main/java/dk/cs/aau/huppaal/HUPPAAL.java b/src/main/java/dk/cs/aau/huppaal/HUPPAAL.java index 7c8fcd1b..1e5b7205 100644 --- a/src/main/java/dk/cs/aau/huppaal/HUPPAAL.java +++ b/src/main/java/dk/cs/aau/huppaal/HUPPAAL.java @@ -1,5 +1,6 @@ package dk.cs.aau.huppaal; +import com.sun.javafx.application.LauncherImpl; import dk.cs.aau.huppaal.abstractions.Component; import dk.cs.aau.huppaal.abstractions.Project; import dk.cs.aau.huppaal.abstractions.Query; @@ -8,11 +9,8 @@ import dk.cs.aau.huppaal.controllers.CanvasController; import dk.cs.aau.huppaal.controllers.HUPPAALController; import dk.cs.aau.huppaal.logging.Log; -import dk.cs.aau.huppaal.presentations.BackgroundThreadPresentation; import dk.cs.aau.huppaal.presentations.HUPPAALPresentation; -import dk.cs.aau.huppaal.presentations.UndoRedoHistoryPresentation; import dk.cs.aau.huppaal.presentations.PresentationFxmlLoader; -import dk.cs.aau.huppaal.utility.keyboard.Keybind; import dk.cs.aau.huppaal.utility.keyboard.KeyboardTracker; import com.google.common.io.Files; import com.google.gson.*; @@ -24,10 +22,8 @@ import javafx.scene.Scene; import javafx.scene.image.Image; import javafx.scene.input.KeyCode; -import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.KeyEvent; import javafx.scene.layout.HBox; -import javafx.scene.layout.Priority; import javafx.scene.text.Font; import javafx.stage.Modality; import javafx.stage.Screen; @@ -57,21 +53,19 @@ public class HUPPAAL extends Application { private static Project project; private static HUPPAALPresentation presentation; public static SimpleStringProperty projectDirectory = new SimpleStringProperty(); - private Stage debugStage; + public static Stage debugStage; public Stage searchStage; public static Runnable toggleSearchModal; private HBox searchBox; + private Scene scene; - { + private static void initializeFileSystem() { try { preferences = Preferences.userRoot().node("HUPPAAL"); - final File dir = new File(System.getProperty("user.home") + File.separator + "H-UPPAAL"); - final String rootDirectory = dir.getPath() + File.separator; - if (!dir.exists()) { - if (!dir.mkdir()) { - throw new IOException("Could not create project directory "+dir); - } - } + var dir = new File(System.getProperty("user.home") + File.separator + "H-UPPAAL"); + var rootDirectory = dir.getPath() + File.separator; + if (!dir.exists() && !dir.mkdir()) + throw new IOException("Could not create project directory "+dir); projectDirectory.set(preferences.get("latestProject", rootDirectory + "projects" + File.separator + "project")); projectDirectory.addListener((observable, oldValue, newValue) -> preferences.put("latestProject", newValue)); temporaryProjectDirectory = rootDirectory + "projects" + File.separator + "temp"; @@ -80,14 +74,16 @@ public class HUPPAAL extends Application { forceCreateFolder(projectDirectory.getValue()); forceCreateFolder(serverDirectory); forceCreateFolder(debugDirectory); - } catch (final IOException e) { - System.out.println("Could not create project directory!"); + } catch (Exception e) { + System.out.println("Unable to initialize project files: " + e.getMessage()); + e.printStackTrace(); System.exit(2); } } public static void main(final String[] args) { - launch(HUPPAAL.class, args); + initializeFileSystem(); + LauncherImpl.launchApplication(HUPPAAL.class, HUPPAALPreloader.class, args); } public static Project getProject() { @@ -145,13 +141,36 @@ public static BooleanProperty toggleQueryPane() { return presentation.toggleQueryPane(); } - private void forceCreateFolder(final String directoryPath) throws IOException { - final File directory = new File(directoryPath); - FileUtils.forceMkdir(directory); + private static void forceCreateFolder(final String directoryPath) throws IOException { + FileUtils.forceMkdir(new File(directoryPath)); } @Override - public void init() { + public void init() throws Exception { + notifyPreloader(new HUPPAALPreloader.Notification(HUPPAALPreloader.LoadStage.LOADING_PROJECT)); + initDefaultExceptionHandler(); + project = new Project(); + loadPresentations(); + initializeProjectFolder(); + notifyPreloader(new HUPPAALPreloader.Notification(HUPPAALPreloader.LoadStage.INITALIZE_JFX)); + initializeProjectSearchModal(); + initScene(); + initFonts(); + initReachabilityService(); + notifyPreloader(new HUPPAALPreloader.Notification(HUPPAALPreloader.LoadStage.AFTER_INIT)); + } + + private void initFonts() { + // Load the fonts required for the project + IconFontFX.register(GoogleMaterialDesignIcons.getIconFont()); + loadFonts(); + } + + private void initReachabilityService() { + HUPPAALController.reachabilityServiceEnabled = true; + } + + private void initDefaultExceptionHandler() { Thread.setDefaultUncaughtExceptionHandler((t, e) -> { try { Log.addError(t.getName(), e.getMessage()); @@ -162,33 +181,16 @@ public void init() { }); } - @Override - public void start(final Stage stage) throws Exception { - // Load or create new project - project = new Project(); - - // Set the title and icon for the application - stage.setTitle("H-UPPAAL"); - stage.getIcons().add(new Image("uppaal.ico")); - - // Load the fonts required for the project - IconFontFX.register(GoogleMaterialDesignIcons.getIconFont()); - loadFonts(); - - // Remove the classic decoration - // kyrke - 2020-04-17: Disabled due to bug https://bugs.openjdk.java.net/browse/JDK-8154847 - //stage.initStyle(StageStyle.UNIFIED); - - // Make the view used for the application - final HUPPAALPresentation huppaal = new HUPPAALPresentation(); - presentation = huppaal; + private void loadPresentations() { + presentation = new HUPPAALPresentation(); + } + private void initScene() { // Make the scene that we will use, and set its size to 80% of the primary screen - final Screen screen = Screen.getPrimary(); - final Scene scene = new Scene(huppaal, screen.getVisualBounds().getWidth() * 0.8, screen.getVisualBounds().getHeight() * 0.8); - stage.setScene(scene); + var screenBounds = Screen.getPrimary().getVisualBounds(); + scene = new Scene(presentation, screenBounds.getWidth() * 0.8, screenBounds.getHeight() * 0.8); - // Load all .css files used todo: these should be loaded in the view classes (?) + // Load all .css files used scene.getStylesheets().add("main.css"); scene.getStylesheets().add("colors.css"); scene.getStylesheets().add("model_canvas.css"); @@ -201,72 +203,20 @@ public void start(final Stage stage) throws Exception { // Let our keyboard tracker handle all key presses scene.setOnKeyPressed(KeyboardTracker.handleKeyPress); + } - // Set the icon for the application - stage.getIcons().addAll( - new Image(getClass().getResource("ic_launcher/mipmap-hdpi/ic_launcher.png").toExternalForm()), - new Image(getClass().getResource("ic_launcher/mipmap-mdpi/ic_launcher.png").toExternalForm()), - new Image(getClass().getResource("ic_launcher/mipmap-xhdpi/ic_launcher.png").toExternalForm()), - new Image(getClass().getResource("ic_launcher/mipmap-xxhdpi/ic_launcher.png").toExternalForm()), - new Image(getClass().getResource("ic_launcher/mipmap-xxxhdpi/ic_launcher.png").toExternalForm()) - ); - - initializeProjectFolder(); - - // We're now ready! Let the curtains fall! - stage.show(); - - HUPPAALController.reachabilityServiceEnabled = true; - - // Register a key-bind for showing debug-information - KeyboardTracker.registerKeybind("DEBUG", new Keybind(new KeyCodeCombination(KeyCode.F12), () -> { - // Toggle the debug mode for the debug class (will update misc. debug variables which presentations bind to) - Debug.debugModeEnabled.set(!Debug.debugModeEnabled.get()); - - if (debugStage != null) { - debugStage.close(); - debugStage = null; - return; - } - - try { - final UndoRedoHistoryPresentation undoRedoHistoryPresentation = new UndoRedoHistoryPresentation(); - undoRedoHistoryPresentation.setMinWidth(100); - - final BackgroundThreadPresentation backgroundThreadPresentation = new BackgroundThreadPresentation(); - backgroundThreadPresentation.setMinWidth(100); - - final HBox root = new HBox(undoRedoHistoryPresentation, backgroundThreadPresentation); - root.setStyle("-fx-background-color: brown;"); - HBox.setHgrow(undoRedoHistoryPresentation, Priority.ALWAYS); - HBox.setHgrow(backgroundThreadPresentation, Priority.ALWAYS); - - - debugStage = new Stage(); - debugStage.setScene(new Scene(root)); - - debugStage.getScene().getStylesheets().add("main.css"); - debugStage.getScene().getStylesheets().add("colors.css"); - - debugStage.setWidth(screen.getVisualBounds().getWidth() * 0.2); - debugStage.setHeight(screen.getVisualBounds().getWidth() * 0.3); - - debugStage.show(); - //stage.requestFocus(); - } catch (final Exception e) { - e.printStackTrace(); - } - })); - + private void initializeProjectSearchModal() { toggleSearchModal = () -> { try { if(searchStage == null) { + var screenBounds = Screen.getPrimary().getBounds(); + searchStage = new Stage(); searchBox = new HBox(); searchStage.initStyle(StageStyle.UNDECORATED); searchStage.setScene(new Scene(PresentationFxmlLoader.loadSetRootGetElement("ProjectSearchPresentation.fxml", searchBox), - screen.getBounds().getWidth() * 0.4, - screen.getBounds().getHeight() * 0.6)); + screenBounds.getWidth() * 0.4, + screenBounds.getHeight() * 0.6)); searchStage.initModality(Modality.WINDOW_MODAL); searchStage.initOwner(scene.getWindow()); searchStage.addEventHandler(KeyEvent.KEY_PRESSED, (t) -> { @@ -286,13 +236,6 @@ public void start(final Stage stage) throws Exception { Log.addError(e.getMessage()); } }; - - stage.setOnCloseRequest(event -> { - UPPAALDriverManager.getInstance().stopEngines(); - - Platform.exit(); - System.exit(0); - }); } public static void initializeProjectFolder() throws IOException { @@ -318,33 +261,48 @@ public static void initializeProjectFolder() throws IOException { deserializeProject(directory); CodeAnalysis.enable(); - // Generate all component presentations by making them the active component in the view one by one - Component initialShownComponent = null; - for (final Component component : HUPPAAL.getProject().getComponents()) { - // The first component should be shown if there is no main - if (initialShownComponent == null) { - initialShownComponent = component; - } - - // If the component is the main show that one - if (component.isIsMain()) { - initialShownComponent = component; - } - - CanvasController.setActiveComponent(component); - } - - // If we found a component (preferably main) set that as active - if (initialShownComponent != null) { - CanvasController.setActiveComponent(initialShownComponent); - } - serializationDone = true; }catch (Exception e) { e.printStackTrace(); } } + @Override + public void start(final Stage stage) throws Exception { + notifyPreloader(new HUPPAALPreloader.Notification(HUPPAALPreloader.LoadStage.START_JFX)); + initializeStage(stage); + stage.show(); + notifyPreloader(new HUPPAALPreloader.Notification(HUPPAALPreloader.LoadStage.AFTER_SHOW)); + setMainAsActiveComponent(); + notifyPreloader(new HUPPAALPreloader.Notification(HUPPAALPreloader.LoadStage.FINISHED)); + } + + private void initializeStage(Stage stage) { + // kyrke - 2020-04-17: Disabled due to bug https://bugs.openjdk.java.net/browse/JDK-8154847 + //stage.initStyle(StageStyle.UNIFIED); + stage.setTitle("H-UPPAAL"); + stage.getIcons().add(new Image("uppaal.ico")); + stage.getIcons().addAll( + new Image(getClass().getResource("ic_launcher/mipmap-hdpi/ic_launcher.png").toExternalForm()), + new Image(getClass().getResource("ic_launcher/mipmap-mdpi/ic_launcher.png").toExternalForm()), + new Image(getClass().getResource("ic_launcher/mipmap-xhdpi/ic_launcher.png").toExternalForm()), + new Image(getClass().getResource("ic_launcher/mipmap-xxhdpi/ic_launcher.png").toExternalForm()), + new Image(getClass().getResource("ic_launcher/mipmap-xxxhdpi/ic_launcher.png").toExternalForm()) + ); + stage.setOnCloseRequest(event -> { + UPPAALDriverManager.getInstance().stopEngines(); + Platform.exit(); + System.exit(0); + }); + stage.setScene(scene); + } + + public static void setMainAsActiveComponent() { + for (var component : HUPPAAL.getProject().getComponents()) + if (component.isIsMain()) + CanvasController.setActiveComponent(component); + } + public static void uppaalDriverUpdated(){ //The UPPAALDriver has been updated, notify the presentation presentation.uppaalDriverUpdated(); diff --git a/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java b/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java new file mode 100644 index 00000000..34206080 --- /dev/null +++ b/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java @@ -0,0 +1,56 @@ +package dk.cs.aau.huppaal; + +import dk.cs.aau.huppaal.presentations.PreloaderPresentation; +import javafx.application.Platform; +import javafx.application.Preloader; +import javafx.scene.Scene; +import javafx.stage.Stage; +import javafx.stage.StageStyle; + +public class HUPPAALPreloader extends Preloader { + public enum LoadStage { + LOADING_PROJECT, + INITALIZE_JFX, + AFTER_INIT, + START_JFX, + AFTER_SHOW, + FINISHED + } + public static class Notification implements PreloaderNotification { + private final LoadStage stage; + public Notification(LoadStage stage) { + this.stage = stage; + } + public LoadStage getStage() { + return stage; + } + } + private Stage stage; + private PreloaderPresentation presentation; + + @Override + public void start(Stage primaryStage) throws Exception { + stage = new Stage(); + presentation = new PreloaderPresentation(); + presentation.getController().projectNameLabel.setText(HUPPAAL.projectDirectory.getValue()); + stage.setScene(new Scene(presentation)); + stage.initStyle(StageStyle.UNDECORATED); + stage.show(); + } + + @Override + public void handleApplicationNotification(PreloaderNotification info) { + if(info instanceof Notification ninfo) { + System.out.println(ninfo.getStage().name()); + switch (ninfo.getStage()) { + case LOADING_PROJECT -> presentation.getController().statusLabel.setText("Loading Project..."); + case INITALIZE_JFX -> presentation.getController().statusLabel.setText("Initializing JFX..."); + case AFTER_INIT -> presentation.getController().statusLabel.setText("Finished init..."); + case START_JFX -> presentation.getController().statusLabel.setText("Starting JFX..."); + case AFTER_SHOW -> stage.hide(); + case FINISHED -> Platform.runLater(() -> presentation.getController().statusLabel.setText("Finished")); + } + } + super.handleApplicationNotification(info); + } +} diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java index dcbc4cb6..72aab436 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java @@ -45,6 +45,7 @@ import javafx.scene.text.Text; import javafx.stage.DirectoryChooser; import javafx.stage.FileChooser; +import javafx.stage.Screen; import javafx.stage.Stage; import javafx.util.Duration; import javafx.util.Pair; @@ -216,6 +217,47 @@ public void initialize(final URL location, final ResourceBundle resources) { // Keybind for deleting the selected elements KeyboardTracker.registerKeybind(KeyboardTracker.DELETE_SELECTED, new Keybind(new KeyCodeCombination(KeyCode.DELETE), this::deleteSelectedClicked)); + // Register a key-bind for showing debug-information + KeyboardTracker.registerKeybind("DEBUG", new Keybind(new KeyCodeCombination(KeyCode.F12), () -> { + // Toggle the debug mode for the debug class (will update misc. debug variables which presentations bind to) + Debug.debugModeEnabled.set(!Debug.debugModeEnabled.get()); + + if (HUPPAAL.debugStage != null) { + HUPPAAL.debugStage.close(); + HUPPAAL.debugStage = null; + return; + } + + try { + final UndoRedoHistoryPresentation undoRedoHistoryPresentation = new UndoRedoHistoryPresentation(); + undoRedoHistoryPresentation.setMinWidth(100); + + final BackgroundThreadPresentation backgroundThreadPresentation = new BackgroundThreadPresentation(); + backgroundThreadPresentation.setMinWidth(100); + + final HBox root = new HBox(undoRedoHistoryPresentation, backgroundThreadPresentation); + root.setStyle("-fx-background-color: brown;"); + HBox.setHgrow(undoRedoHistoryPresentation, Priority.ALWAYS); + HBox.setHgrow(backgroundThreadPresentation, Priority.ALWAYS); + + + HUPPAAL.debugStage = new Stage(); + HUPPAAL.debugStage.setScene(new Scene(root)); + + HUPPAAL.debugStage.getScene().getStylesheets().add("main.css"); + HUPPAAL.debugStage.getScene().getStylesheets().add("colors.css"); + + var vb = Screen.getPrimary().getVisualBounds(); + HUPPAAL.debugStage.setWidth(vb.getWidth() * 0.2); + HUPPAAL.debugStage.setHeight(vb.getWidth() * 0.3); + + HUPPAAL.debugStage.show(); + //stage.requestFocus(); + } catch (final Exception e) { + e.printStackTrace(); + } + })); + // Keybinds for coloring the selected elements EnabledColor.enabledColors.forEach(enabledColor -> { KeyboardTracker.registerKeybind(KeyboardTracker.COLOR_SELECTED + "_" + enabledColor.keyCode.getName(), new Keybind(new KeyCodeCombination(enabledColor.keyCode), () -> { @@ -524,6 +566,7 @@ private void initializeMenuBar() { return; HUPPAAL.projectDirectory.set(file.getAbsolutePath()); HUPPAAL.initializeProjectFolder(); + HUPPAAL.setMainAsActiveComponent(); } catch (final IOException e) { e.printStackTrace(); } diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/PreloaderController.java b/src/main/java/dk/cs/aau/huppaal/controllers/PreloaderController.java new file mode 100644 index 00000000..c29c5c03 --- /dev/null +++ b/src/main/java/dk/cs/aau/huppaal/controllers/PreloaderController.java @@ -0,0 +1,22 @@ +package dk.cs.aau.huppaal.controllers; + +import javafx.fxml.Initializable; +import javafx.scene.control.Label; +import javafx.scene.image.ImageView; +import javafx.scene.layout.StackPane; + +import java.net.URL; +import java.util.ResourceBundle; + +public class PreloaderController implements Initializable { + + public StackPane root; + public ImageView logo; + public Label statusLabel; + public Label projectNameLabel; + + @Override + public void initialize(URL location, ResourceBundle resources) { + + } +} diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/PreloaderPresentation.java b/src/main/java/dk/cs/aau/huppaal/presentations/PreloaderPresentation.java new file mode 100644 index 00000000..496e75d9 --- /dev/null +++ b/src/main/java/dk/cs/aau/huppaal/presentations/PreloaderPresentation.java @@ -0,0 +1,18 @@ +package dk.cs.aau.huppaal.presentations; + +import dk.cs.aau.huppaal.HUPPAAL; +import dk.cs.aau.huppaal.controllers.PreloaderController; +import javafx.scene.image.Image; +import javafx.scene.layout.StackPane; + +public class PreloaderPresentation extends StackPane { + private final PreloaderController controller; + public PreloaderPresentation() { + controller = PresentationFxmlLoader.loadSetRoot("PreloaderPresentation.fxml", this); + controller.logo.setImage(new Image(HUPPAAL.class.getResource("ic_launcher/mipmap-xxxhdpi/ic_launcher.png").toExternalForm())); + } + + public PreloaderController getController() { + return controller; + } +} diff --git a/src/main/resources/dk/cs/aau/huppaal/presentations/PreloaderPresentation.fxml b/src/main/resources/dk/cs/aau/huppaal/presentations/PreloaderPresentation.fxml new file mode 100644 index 00000000..7dc864dd --- /dev/null +++ b/src/main/resources/dk/cs/aau/huppaal/presentations/PreloaderPresentation.fxml @@ -0,0 +1,43 @@ + + + + + + + + + + + +
+ +
+ + + + + + + + + + + + + + + + + + + + +
+
From 39413a4ac07ad909811fc4b27db8f143d0f58ee2 Mon Sep 17 00:00:00 2001 From: Asger Gitz-Johansen Date: Fri, 9 Dec 2022 20:46:31 +0100 Subject: [PATCH 2/3] nitpick: rename variable Also remove old console log --- src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java | 5 ++--- 1 file changed, 2 insertions(+), 3 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java b/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java index 34206080..989871e1 100644 --- a/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java +++ b/src/main/java/dk/cs/aau/huppaal/HUPPAALPreloader.java @@ -40,9 +40,8 @@ public void start(Stage primaryStage) throws Exception { @Override public void handleApplicationNotification(PreloaderNotification info) { - if(info instanceof Notification ninfo) { - System.out.println(ninfo.getStage().name()); - switch (ninfo.getStage()) { + if(info instanceof Notification notificationInfo) { + switch (notificationInfo.getStage()) { case LOADING_PROJECT -> presentation.getController().statusLabel.setText("Loading Project..."); case INITALIZE_JFX -> presentation.getController().statusLabel.setText("Initializing JFX..."); case AFTER_INIT -> presentation.getController().statusLabel.setText("Finished init..."); From a70e42e569fc52d79ef51da68e43b0319633810d Mon Sep 17 00:00:00 2001 From: Asger Gitz-Johansen Date: Fri, 9 Dec 2022 20:50:06 +0100 Subject: [PATCH 3/3] cleanup: move lambda into a function --- .../controllers/HUPPAALController.java | 80 ++++++++++--------- 1 file changed, 41 insertions(+), 39 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java index 72aab436..f26e11ba 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java @@ -218,45 +218,7 @@ public void initialize(final URL location, final ResourceBundle resources) { KeyboardTracker.registerKeybind(KeyboardTracker.DELETE_SELECTED, new Keybind(new KeyCodeCombination(KeyCode.DELETE), this::deleteSelectedClicked)); // Register a key-bind for showing debug-information - KeyboardTracker.registerKeybind("DEBUG", new Keybind(new KeyCodeCombination(KeyCode.F12), () -> { - // Toggle the debug mode for the debug class (will update misc. debug variables which presentations bind to) - Debug.debugModeEnabled.set(!Debug.debugModeEnabled.get()); - - if (HUPPAAL.debugStage != null) { - HUPPAAL.debugStage.close(); - HUPPAAL.debugStage = null; - return; - } - - try { - final UndoRedoHistoryPresentation undoRedoHistoryPresentation = new UndoRedoHistoryPresentation(); - undoRedoHistoryPresentation.setMinWidth(100); - - final BackgroundThreadPresentation backgroundThreadPresentation = new BackgroundThreadPresentation(); - backgroundThreadPresentation.setMinWidth(100); - - final HBox root = new HBox(undoRedoHistoryPresentation, backgroundThreadPresentation); - root.setStyle("-fx-background-color: brown;"); - HBox.setHgrow(undoRedoHistoryPresentation, Priority.ALWAYS); - HBox.setHgrow(backgroundThreadPresentation, Priority.ALWAYS); - - - HUPPAAL.debugStage = new Stage(); - HUPPAAL.debugStage.setScene(new Scene(root)); - - HUPPAAL.debugStage.getScene().getStylesheets().add("main.css"); - HUPPAAL.debugStage.getScene().getStylesheets().add("colors.css"); - - var vb = Screen.getPrimary().getVisualBounds(); - HUPPAAL.debugStage.setWidth(vb.getWidth() * 0.2); - HUPPAAL.debugStage.setHeight(vb.getWidth() * 0.3); - - HUPPAAL.debugStage.show(); - //stage.requestFocus(); - } catch (final Exception e) { - e.printStackTrace(); - } - })); + KeyboardTracker.registerKeybind("DEBUG", new Keybind(new KeyCodeCombination(KeyCode.F12), this::toggleDebugWindow)); // Keybinds for coloring the selected elements EnabledColor.enabledColors.forEach(enabledColor -> { @@ -999,6 +961,46 @@ private void executeRunConfiguration(RunConfiguration config) { } } + private void toggleDebugWindow() { + // Toggle the debug mode for the debug class (will update misc. debug variables which presentations bind to) + Debug.debugModeEnabled.set(!Debug.debugModeEnabled.get()); + + if (HUPPAAL.debugStage != null) { + HUPPAAL.debugStage.close(); + HUPPAAL.debugStage = null; + return; + } + + try { + final UndoRedoHistoryPresentation undoRedoHistoryPresentation = new UndoRedoHistoryPresentation(); + undoRedoHistoryPresentation.setMinWidth(100); + + final BackgroundThreadPresentation backgroundThreadPresentation = new BackgroundThreadPresentation(); + backgroundThreadPresentation.setMinWidth(100); + + final HBox root = new HBox(undoRedoHistoryPresentation, backgroundThreadPresentation); + root.setStyle("-fx-background-color: brown;"); + HBox.setHgrow(undoRedoHistoryPresentation, Priority.ALWAYS); + HBox.setHgrow(backgroundThreadPresentation, Priority.ALWAYS); + + + HUPPAAL.debugStage = new Stage(); + HUPPAAL.debugStage.setScene(new Scene(root)); + + HUPPAAL.debugStage.getScene().getStylesheets().add("main.css"); + HUPPAAL.debugStage.getScene().getStylesheets().add("colors.css"); + + var vb = Screen.getPrimary().getVisualBounds(); + HUPPAAL.debugStage.setWidth(vb.getWidth() * 0.2); + HUPPAAL.debugStage.setHeight(vb.getWidth() * 0.3); + + HUPPAAL.debugStage.show(); + //stage.requestFocus(); + } catch (final Exception e) { + e.printStackTrace(); + } + } + @FXML private void deleteSelectedClicked() { if (SelectHelper.getSelectedElements().size() == 0)