Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Inspector fixes #177

Merged
merged 2 commits into from
Mar 10, 2024
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
25 changes: 25 additions & 0 deletions src/main/java/org/gecko/view/GeckoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -49,6 +50,8 @@ public class GeckoView {
private final ArrayList<EditorView> openedViews;
private boolean darkMode = false;

private boolean hasBeenFocused = false;

public GeckoView(GeckoViewModel viewModel) {
this.viewModel = viewModel;
this.mainPane = new BorderPane();
Expand Down Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -16,13 +16,17 @@
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;

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<HBox> inputLabel =
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/gecko/view/views/EditorView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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);

Expand Down
3 changes: 2 additions & 1 deletion src/test/java/org/gecko/io/SaveAndLoadTest.java
Original file line number Diff line number Diff line change
Expand Up @@ -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\":[{";
Expand Down
Loading