From 9537e5226a88d7dd624ef609aa78881f5e304814 Mon Sep 17 00:00:00 2001 From: crissnb Date: Sun, 10 Mar 2024 12:27:35 +0100 Subject: [PATCH 1/2] merge --- src/main/java/org/gecko/view/GeckoView.java | 28 +++++++++++++++++++ .../builder/AutomatonVariablePaneBuilder.java | 4 +++ .../java/org/gecko/view/views/EditorView.java | 1 - .../java/org/gecko/io/SaveAndLoadTest.java | 3 +- 4 files changed, 34 insertions(+), 2 deletions(-) diff --git a/src/main/java/org/gecko/view/GeckoView.java b/src/main/java/org/gecko/view/GeckoView.java index fde28df9..638ccd09 100644 --- a/src/main/java/org/gecko/view/GeckoView.java +++ b/src/main/java/org/gecko/view/GeckoView.java @@ -9,6 +9,7 @@ import javafx.beans.property.SimpleObjectProperty; import javafx.beans.value.ObservableValue; import javafx.collections.ObservableSet; +import javafx.geometry.Point2D; import javafx.scene.Node; import javafx.scene.control.MenuBar; import javafx.scene.control.Tab; @@ -49,6 +50,8 @@ public class GeckoView { private final ArrayList openedViews; private boolean darkMode = false; + private boolean hasBeenFocused = false; + public GeckoView(GeckoViewModel viewModel) { this.viewModel = viewModel; this.mainPane = new BorderPane(); @@ -79,6 +82,31 @@ public GeckoView(GeckoViewModel viewModel) { centerPane.setPickOnBounds(false); refreshView(); + + centerPane.sceneProperty().addListener((observable, oldValue, newValue) -> { + if (newValue == null) { + return; + } + newValue.focusOwnerProperty().addListener((observable1, oldValue1, newValue1) -> { + if (!currentViewProperty.getValue().getViewModel().getPositionableViewModelElements().isEmpty() + && !hasBeenFocused) { + EditorViewModel currentViewModel = currentViewProperty.getValue().getViewModel(); + + // Evaluate the center of all elements by calculating the average position + Point2D center = currentViewModel.getPositionableViewModelElements() + .stream() + .map(PositionableViewModelElement::getCenter) + .reduce(new Point2D(0, 0), Point2D::add) + .multiply(1.0 / currentViewProperty.getValue() + .getViewModel() + .getPositionableViewModelElements() + .size()); + + currentViewModel.setPivot(center); + } + hasBeenFocused = true; + }); + }); } private void onUpdateCurrentEditorFromViewModel( diff --git a/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java b/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java index b70f2016..39fb1bf0 100644 --- a/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java @@ -16,6 +16,7 @@ public class AutomatonVariablePaneBuilder { private static final int VARIABLE_PANE_WIDTH = 320; + private static final int VARIABLE_PANE_HEIGHT = 240; private static final int ELEMENT_SPACING = 10; private final ScrollPane scrollPane; @@ -23,6 +24,9 @@ public class AutomatonVariablePaneBuilder { public AutomatonVariablePaneBuilder(ActionManager actionManager, SystemViewModel systemViewModel) { scrollPane = new ScrollPane(); scrollPane.setPrefWidth(VARIABLE_PANE_WIDTH); + scrollPane.setPrefHeight(VARIABLE_PANE_HEIGHT); + scrollPane.setMinHeight(VARIABLE_PANE_HEIGHT); + scrollPane.setMaxHeight(VARIABLE_PANE_HEIGHT); VBox content = new VBox(); InspectorElement inputLabel = diff --git a/src/main/java/org/gecko/view/views/EditorView.java b/src/main/java/org/gecko/view/views/EditorView.java index a8848cb4..236850c9 100644 --- a/src/main/java/org/gecko/view/views/EditorView.java +++ b/src/main/java/org/gecko/view/views/EditorView.java @@ -179,7 +179,6 @@ public Node drawInspector() { VBox vbox = new VBox(); vbox.addEventHandler(KeyEvent.ANY, shortcutHandler); Inspector currentInspectorNode = currentInspector.get(); - currentInspectorNode.setPrefHeight(AUTOMATON_INSPECTOR_HEIGHT); VBox inspectorBox = new VBox(currentInspectorNode); VBox.setVgrow(inspectorBox, Priority.ALWAYS); diff --git a/src/test/java/org/gecko/io/SaveAndLoadTest.java b/src/test/java/org/gecko/io/SaveAndLoadTest.java index d825674f..8436280f 100644 --- a/src/test/java/org/gecko/io/SaveAndLoadTest.java +++ b/src/test/java/org/gecko/io/SaveAndLoadTest.java @@ -41,7 +41,8 @@ public class ProjectFileSerializerTest { private static GeckoViewModel oneLevelGeckoViewModel; private static GeckoViewModel treeGeckoViewModel; private static ObjectMapper mapper; - static String EMPTY_GECKO_JSON = "{\"model\":{\"id\":0,\"name\":\"Element_0\",\"code\":null,\"automaton\":{\"startState\":null,\"regions\":[],\"states\":[],\"edges\":[]},\"children\":[],\"connections\":[],\"variables\":[]},\"startStates\":[],\"viewModelProperties\":[]}"; + static String EMPTY_GECKO_JSON = + "{\"model\":{\"id\":0,\"name\":\"Element_0\",\"code\":null,\"automaton\":{\"startState\":null,\"regions\":[],\"states\":[],\"edges\":[]},\"children\":[],\"connections\":[],\"variables\":[]},\"startStates\":[],\"viewModelProperties\":[]}"; static String NON_NULL_AUTOMATON_JSON = "\"automaton\":{"; static String NON_NULL_START_STATE_JSON = "\"startState\":{"; static String NON_NULL_REGIONS_JSON = "\"regions\":[{"; From 29d539dcf5d91755cdef1ffa25338c2a678bcf9c Mon Sep 17 00:00:00 2001 From: crissnb Date: Sun, 10 Mar 2024 12:21:04 +0100 Subject: [PATCH 2/2] small refactoring --- src/main/java/org/gecko/view/GeckoView.java | 5 +---- 1 file changed, 1 insertion(+), 4 deletions(-) diff --git a/src/main/java/org/gecko/view/GeckoView.java b/src/main/java/org/gecko/view/GeckoView.java index 638ccd09..950f6388 100644 --- a/src/main/java/org/gecko/view/GeckoView.java +++ b/src/main/java/org/gecko/view/GeckoView.java @@ -97,10 +97,7 @@ public GeckoView(GeckoViewModel viewModel) { .stream() .map(PositionableViewModelElement::getCenter) .reduce(new Point2D(0, 0), Point2D::add) - .multiply(1.0 / currentViewProperty.getValue() - .getViewModel() - .getPositionableViewModelElements() - .size()); + .multiply(1.0 / currentViewModel.getPositionableViewModelElements().size()); currentViewModel.setPivot(center); }