diff --git a/src/main/java/org/gecko/model/Variable.java b/src/main/java/org/gecko/model/Variable.java index 6660a43f..abed6fce 100644 --- a/src/main/java/org/gecko/model/Variable.java +++ b/src/main/java/org/gecko/model/Variable.java @@ -3,7 +3,7 @@ import com.fasterxml.jackson.annotation.JsonCreator; import com.fasterxml.jackson.annotation.JsonIgnore; import com.fasterxml.jackson.annotation.JsonProperty; -import java.util.Set; +import java.util.List; import lombok.Getter; import lombok.NonNull; import lombok.Setter; @@ -22,9 +22,9 @@ public class Variable extends Element implements Renamable { private Visibility visibility; private boolean hasIncomingConnection; - private static final Set BUILTIN_TYPES = - java.util.Set.of("int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", - "float", "double", "short", "long", "bool"); + public static final List BUILTIN_TYPES = + List.of("int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", "float", + "double", "short", "long", "bool"); @JsonCreator public Variable( @@ -52,7 +52,7 @@ public void setType(@NonNull String type) throws ModelException { } @JsonIgnore - public static Set getBuiltinTypes() { + public static List getBuiltinTypes() { return BUILTIN_TYPES; } diff --git a/src/main/java/org/gecko/tools/CursorTool.java b/src/main/java/org/gecko/tools/CursorTool.java index 4c821da4..1644e78d 100644 --- a/src/main/java/org/gecko/tools/CursorTool.java +++ b/src/main/java/org/gecko/tools/CursorTool.java @@ -34,6 +34,8 @@ */ public class CursorTool extends Tool { + private static final double DRAG_THRESHOLD = 4; + private boolean isDragging = false; private final SelectionManager selectionManager; private final EditorViewModel editorViewModel; @@ -219,10 +221,20 @@ private void setDragAndSelectHandlers(ViewElement element) { return; } startDraggingElementHandler(event, element.drawElement()); - selectElement(element, !event.isShiftDown()); + + if (!element.isSelected()) { + selectElement(element, !event.isShiftDown()); + } }); element.drawElement().setOnMouseDragged(this::dragElementsHandler); - element.drawElement().setOnMouseReleased(this::stopDraggingElementHandler); + element.drawElement().setOnMouseReleased(event -> { + stopDraggingElementHandler(event); + + if (event.getButton() == MouseButton.PRIMARY && element.isSelected() + && startDragPosition.distance(previousDragPosition) * editorViewModel.getZoomScale() < DRAG_THRESHOLD) { + selectElement(element, !event.isShiftDown()); + } + }); } private void startDraggingElementHandler(MouseEvent event, Node element) { @@ -295,7 +307,6 @@ private void cancelDrag(ElementScalerBlock scaler) { } private void cancelDrag() { - startDragPosition = null; draggedElement = null; isDragging = false; } diff --git a/src/main/java/org/gecko/tools/RegionCreatorTool.java b/src/main/java/org/gecko/tools/RegionCreatorTool.java index 643aac18..5d53af3d 100644 --- a/src/main/java/org/gecko/tools/RegionCreatorTool.java +++ b/src/main/java/org/gecko/tools/RegionCreatorTool.java @@ -7,7 +7,6 @@ import javafx.scene.shape.Rectangle; import org.gecko.actions.ActionManager; import org.gecko.viewmodel.BlockViewModelElement; -import org.gecko.viewmodel.PositionableViewModelElement; /** * A concrete representation of a region-creating-{@link AreaTool}, utilized for creating a diff --git a/src/main/java/org/gecko/view/GeckoView.java b/src/main/java/org/gecko/view/GeckoView.java index 6b12138d..b2299fb0 100644 --- a/src/main/java/org/gecko/view/GeckoView.java +++ b/src/main/java/org/gecko/view/GeckoView.java @@ -30,7 +30,6 @@ public class GeckoView { private static final String STYLE_SHEET_LIGHT = "/styles/gecko.css"; private static final String STYLE_SHEET_DARK = "/styles/gecko-dark.css"; - @Getter private final BorderPane mainPane; private final TabPane centerPane; diff --git a/src/main/java/org/gecko/view/ResourceHandler.java b/src/main/java/org/gecko/view/ResourceHandler.java index ca2c7df9..cf59192f 100644 --- a/src/main/java/org/gecko/view/ResourceHandler.java +++ b/src/main/java/org/gecko/view/ResourceHandler.java @@ -15,6 +15,11 @@ public class ResourceHandler { @Setter private static Locale currentLocale = Locale.getDefault(); + private static final String BUNDLE_PATH = "lang/"; + + private ResourceHandler() { + } + /** * Returns the localized string for the given key from the given bundle. * @@ -27,12 +32,11 @@ public static String getString(String bundle, String key) { } private static ResourceBundle getBundle(String bundleName) { - String bundlePath = "lang/"; ResourceBundle bundle; try { - bundle = ResourceBundle.getBundle(bundlePath + bundleName, currentLocale); + bundle = ResourceBundle.getBundle(BUNDLE_PATH + bundleName, currentLocale); } catch (MissingResourceException e) { - bundle = ResourceBundle.getBundle(bundlePath + bundleName, Locale.US); + bundle = ResourceBundle.getBundle(BUNDLE_PATH + bundleName, Locale.US); } return bundle; } diff --git a/src/main/java/org/gecko/view/inspector/Inspector.java b/src/main/java/org/gecko/view/inspector/Inspector.java index bfdd22ca..70a8b39d 100644 --- a/src/main/java/org/gecko/view/inspector/Inspector.java +++ b/src/main/java/org/gecko/view/inspector/Inspector.java @@ -41,7 +41,6 @@ public Inspector( inspectorDecorations.getChildren().addAll(selectionButtons); vBox.getChildren().add(inspectorDecorations); - setFitToHeight(true); for (InspectorElement element : elements) { vBox.getChildren().add(element.getControl()); 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 80e68222..e6aaebb2 100644 --- a/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java @@ -1,10 +1,14 @@ package org.gecko.view.inspector.builder; import javafx.geometry.Insets; +import javafx.scene.control.ListView; import javafx.scene.control.ScrollPane; +import javafx.scene.layout.HBox; import javafx.scene.layout.VBox; import org.gecko.actions.ActionManager; import org.gecko.model.Visibility; +import org.gecko.view.inspector.element.InspectorElement; +import org.gecko.view.inspector.element.container.InspectorVariableField; import org.gecko.view.inspector.element.container.InspectorVariableLabel; import org.gecko.view.inspector.element.list.InspectorVariableList; import org.gecko.viewmodel.SystemViewModel; @@ -12,7 +16,6 @@ public class AutomatonVariablePaneBuilder { private static final int VARIABLE_PANE_WIDTH = 320; - private static final int LIST_HEIGHT = 100; private static final int ELEMENT_SPACING = 10; private final ScrollPane scrollPane; @@ -22,14 +25,14 @@ public AutomatonVariablePaneBuilder(ActionManager actionManager, SystemViewModel scrollPane.setPrefWidth(VARIABLE_PANE_WIDTH); VBox content = new VBox(); - InspectorVariableLabel inputLabel = + InspectorElement inputLabel = new InspectorVariableLabel(actionManager, systemViewModel, Visibility.INPUT); - InspectorVariableList inputList = new InspectorVariableList(actionManager, systemViewModel, Visibility.INPUT); - InspectorVariableLabel outputLabel = + InspectorElement> inputList = + new InspectorVariableList(actionManager, systemViewModel, Visibility.INPUT); + InspectorElement outputLabel = new InspectorVariableLabel(actionManager, systemViewModel, Visibility.OUTPUT); - InspectorVariableList outputList = new InspectorVariableList(actionManager, systemViewModel, Visibility.OUTPUT); - inputList.getControl().setPrefHeight(LIST_HEIGHT); - outputList.getControl().setPrefHeight(LIST_HEIGHT); + InspectorElement> outputList = + new InspectorVariableList(actionManager, systemViewModel, Visibility.OUTPUT); content.getChildren() .addAll(inputLabel.getControl(), inputList.getControl(), outputLabel.getControl(), outputList.getControl()); diff --git a/src/main/java/org/gecko/view/inspector/element/button/InspectorAddContractButton.java b/src/main/java/org/gecko/view/inspector/element/button/InspectorAddContractButton.java index c0d5ab54..04639148 100644 --- a/src/main/java/org/gecko/view/inspector/element/button/InspectorAddContractButton.java +++ b/src/main/java/org/gecko/view/inspector/element/button/InspectorAddContractButton.java @@ -9,9 +9,11 @@ * {@link org.gecko.viewmodel.ContractViewModel ContractViewModel} to a given {@link StateViewModel}. */ public class InspectorAddContractButton extends AbstractInspectorButton { + private static final String STYLE = "inspector-add-button"; private static final int WIDTH = 70; public InspectorAddContractButton(ActionManager actionManager, StateViewModel stateViewModel) { + getStyleClass().add(STYLE); setText(ResourceHandler.getString("Buttons", "inspector_add_contract")); setPrefWidth(WIDTH); setOnAction(event -> { diff --git a/src/main/java/org/gecko/view/inspector/element/button/InspectorAddVariableButton.java b/src/main/java/org/gecko/view/inspector/element/button/InspectorAddVariableButton.java index 946bd71b..6760ecf8 100644 --- a/src/main/java/org/gecko/view/inspector/element/button/InspectorAddVariableButton.java +++ b/src/main/java/org/gecko/view/inspector/element/button/InspectorAddVariableButton.java @@ -11,11 +11,12 @@ * {@link SystemViewModel} with a given {@link Visibility}. */ public class InspectorAddVariableButton extends AbstractInspectorButton { - + private static final String STYLE = "inspector-add-button"; private static final int WIDTH = 70; public InspectorAddVariableButton( ActionManager actionManager, SystemViewModel systemViewModel, Visibility visibility) { + getStyleClass().add(STYLE); setText(ResourceHandler.getString("Buttons", "inspector_add_variable")); setPrefWidth(WIDTH); setOnAction(event -> { diff --git a/src/main/java/org/gecko/view/inspector/element/button/InspectorOpenSystemButton.java b/src/main/java/org/gecko/view/inspector/element/button/InspectorOpenSystemButton.java index c1b83b8a..5b898636 100644 --- a/src/main/java/org/gecko/view/inspector/element/button/InspectorOpenSystemButton.java +++ b/src/main/java/org/gecko/view/inspector/element/button/InspectorOpenSystemButton.java @@ -11,10 +11,11 @@ * system view corresponding to the given system. */ public class InspectorOpenSystemButton extends AbstractInspectorButton { - + private static final String STYLE = "inspector-open-system-button"; private static final int WIDTH = 300; public InspectorOpenSystemButton(ActionManager actionManager, SystemViewModel systemViewModel) { + getStyleClass().add(STYLE); setText(ResourceHandler.getString("Buttons", "inspector_open_system")); setPrefWidth(WIDTH); setOnAction(event -> actionManager.run( diff --git a/src/main/java/org/gecko/view/inspector/element/button/InspectorSetStartStateButton.java b/src/main/java/org/gecko/view/inspector/element/button/InspectorSetStartStateButton.java index e4b57ae7..762e793e 100644 --- a/src/main/java/org/gecko/view/inspector/element/button/InspectorSetStartStateButton.java +++ b/src/main/java/org/gecko/view/inspector/element/button/InspectorSetStartStateButton.java @@ -10,7 +10,10 @@ * Represents a type of {@link AbstractInspectorButton} used for setting a {@link StateViewModel} as start-state. */ public class InspectorSetStartStateButton extends ToggleButton implements InspectorElement { + private static final String START_STATE_STYLE = "inspector-start-state-button"; + public InspectorSetStartStateButton(ActionManager actionManager, StateViewModel stateViewModel) { + getStyleClass().add(START_STATE_STYLE); setMaxWidth(Double.MAX_VALUE); setText(ResourceHandler.getString("Buttons", "inspector_set_start_state")); update(stateViewModel.getIsStartState()); diff --git a/src/main/java/org/gecko/view/inspector/element/combobox/InspectorTypeComboBox.java b/src/main/java/org/gecko/view/inspector/element/combobox/InspectorTypeComboBox.java new file mode 100644 index 00000000..7ec61023 --- /dev/null +++ b/src/main/java/org/gecko/view/inspector/element/combobox/InspectorTypeComboBox.java @@ -0,0 +1,26 @@ +package org.gecko.view.inspector.element.combobox; + +import org.gecko.actions.Action; +import org.gecko.actions.ActionManager; +import org.gecko.model.Variable; +import org.gecko.viewmodel.PortViewModel; + +/** + * A concrete representation of an {@link InspectorComboBox} for a {@link PortViewModel}, through which the type of the + * port can be changed. + */ +public class InspectorTypeComboBox extends InspectorComboBox { + private final PortViewModel viewModel; + private final ActionManager actionManager; + + public InspectorTypeComboBox(ActionManager actionManager, PortViewModel viewModel) { + super(actionManager, Variable.BUILTIN_TYPES, viewModel.getTypeProperty()); + this.viewModel = viewModel; + this.actionManager = actionManager; + } + + @Override + protected Action getAction() { + return actionManager.getActionFactory().createChangeTypePortViewModelElementAction(viewModel, getValue()); + } +} diff --git a/src/main/java/org/gecko/view/inspector/element/container/InspectorCodeSystemContainer.java b/src/main/java/org/gecko/view/inspector/element/container/InspectorCodeSystemContainer.java index dbf98f3a..895e8a35 100644 --- a/src/main/java/org/gecko/view/inspector/element/container/InspectorCodeSystemContainer.java +++ b/src/main/java/org/gecko/view/inspector/element/container/InspectorCodeSystemContainer.java @@ -11,10 +11,13 @@ public class InspectorCodeSystemContainer extends VBox implements InspectorElement { public InspectorCodeSystemContainer(ActionManager actionManager, SystemViewModel viewModel) { + if (!viewModel.getTarget().getChildren().isEmpty()) { + return; + } + getChildren().add(new InspectorLabel("Code")); InspectorAreaField codeField = new InspectorCodeSystemField(actionManager, viewModel); codeField.prefWidthProperty().bind(widthProperty().subtract(50)); - codeField.setPrefHeight(100); getChildren().add(codeField); } diff --git a/src/main/java/org/gecko/view/inspector/element/container/InspectorTypeLabel.java b/src/main/java/org/gecko/view/inspector/element/container/InspectorTypeLabel.java index 4a1b3713..aac89f10 100644 --- a/src/main/java/org/gecko/view/inspector/element/container/InspectorTypeLabel.java +++ b/src/main/java/org/gecko/view/inspector/element/container/InspectorTypeLabel.java @@ -2,18 +2,18 @@ import org.gecko.actions.ActionManager; import org.gecko.view.ResourceHandler; +import org.gecko.view.inspector.element.combobox.InspectorTypeComboBox; import org.gecko.view.inspector.element.label.InspectorLabel; -import org.gecko.view.inspector.element.textfield.InspectorTypeField; import org.gecko.viewmodel.PortViewModel; /** * Represents a type of {@link LabeledInspectorElement}. Contains an {@link InspectorLabel} and an - * {@link InspectorTypeField}. + * {@link InspectorTypeComboBox}. */ public class InspectorTypeLabel extends LabeledInspectorElement { public InspectorTypeLabel(ActionManager actionManager, PortViewModel viewModel) { super(new InspectorLabel(ResourceHandler.getString("Inspector", "type")), - new InspectorTypeField(actionManager, viewModel)); + new InspectorTypeComboBox(actionManager, viewModel)); } } diff --git a/src/main/java/org/gecko/view/inspector/element/container/InspectorVariableField.java b/src/main/java/org/gecko/view/inspector/element/container/InspectorVariableField.java index 3a5d9be6..2bf841fd 100644 --- a/src/main/java/org/gecko/view/inspector/element/container/InspectorVariableField.java +++ b/src/main/java/org/gecko/view/inspector/element/container/InspectorVariableField.java @@ -8,9 +8,9 @@ import org.gecko.view.ResourceHandler; import org.gecko.view.inspector.element.InspectorElement; import org.gecko.view.inspector.element.button.InspectorRemoveVariableButton; +import org.gecko.view.inspector.element.combobox.InspectorTypeComboBox; import org.gecko.view.inspector.element.label.InspectorLabel; import org.gecko.view.inspector.element.textfield.InspectorRenameField; -import org.gecko.view.inspector.element.textfield.InspectorTypeField; import org.gecko.viewmodel.PortViewModel; /** @@ -32,7 +32,7 @@ public InspectorVariableField(ActionManager actionManager, PortViewModel portVie InspectorElement deleteButton = new InspectorRemoveVariableButton(actionManager, portViewModel); nameAndDeleteContainer.getChildren().addAll(variableNameField.getControl(), spacer, deleteButton.getControl()); InspectorElement typeLabel = new InspectorLabel(ResourceHandler.getString("Inspector", "type")); - InspectorElement typeField = new InspectorTypeField(actionManager, portViewModel); + InspectorElement typeField = new InspectorTypeComboBox(actionManager, portViewModel); HBox typeContainer = new HBox(); typeContainer.getChildren().addAll(typeLabel.getControl(), typeField.getControl()); getChildren().addAll(nameAndDeleteContainer, typeContainer); diff --git a/src/main/java/org/gecko/view/inspector/element/list/InspectorVariableList.java b/src/main/java/org/gecko/view/inspector/element/list/InspectorVariableList.java index 4c0193ad..9cc9eb6c 100644 --- a/src/main/java/org/gecko/view/inspector/element/list/InspectorVariableList.java +++ b/src/main/java/org/gecko/view/inspector/element/list/InspectorVariableList.java @@ -1,5 +1,6 @@ package org.gecko.view.inspector.element.list; +import javafx.beans.binding.Bindings; import javafx.beans.value.ObservableValue; import javafx.collections.ListChangeListener; import org.gecko.actions.ActionManager; @@ -13,6 +14,9 @@ */ public class InspectorVariableList extends AbstractInspectorList { + private static final double listCellHeight = 43; + private static final int MIN_HEIGHT = 60; + private final ActionManager actionManager; private final SystemViewModel viewModel; private final Visibility visibility; @@ -21,6 +25,10 @@ public InspectorVariableList(ActionManager actionManager, SystemViewModel viewMo this.actionManager = actionManager; this.viewModel = viewModel; this.visibility = visibility; + + setMinHeight(MIN_HEIGHT); + prefHeightProperty().bind(Bindings.size(getItems()).multiply(listCellHeight)); + viewModel.getPortsProperty().addListener(this::onPortsListChanged); viewModel.getPorts().stream().filter(port -> port.getVisibility() == visibility).forEach(this::addPortItem); viewModel.getPorts().forEach(port -> port.getVisibilityProperty().addListener(this::onVisibilityChanged)); diff --git a/src/main/java/org/gecko/view/inspector/element/textfield/InspectorAreaField.java b/src/main/java/org/gecko/view/inspector/element/textfield/InspectorAreaField.java index ca78a5f6..1f7bbe6f 100644 --- a/src/main/java/org/gecko/view/inspector/element/textfield/InspectorAreaField.java +++ b/src/main/java/org/gecko/view/inspector/element/textfield/InspectorAreaField.java @@ -7,7 +7,7 @@ import org.gecko.view.inspector.element.InspectorElement; public abstract class InspectorAreaField extends TextArea implements InspectorElement