diff --git a/src/main/java/org/gecko/view/GeckoView.java b/src/main/java/org/gecko/view/GeckoView.java index fde28df9..950f6388 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,28 @@ 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 / currentViewModel.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\":[{";