Skip to content

Commit

Permalink
Merge pull request #107 from DecwLK/test_ui_fixes
Browse files Browse the repository at this point in the history
Test UI fixes
  • Loading branch information
DecwLK authored Mar 6, 2024
2 parents b9854e0 + 8b27ca0 commit 541521c
Show file tree
Hide file tree
Showing 44 changed files with 189 additions and 109 deletions.
10 changes: 5 additions & 5 deletions src/main/java/org/gecko/model/Variable.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand All @@ -22,9 +22,9 @@ public class Variable extends Element implements Renamable {
private Visibility visibility;
private boolean hasIncomingConnection;

private static final Set<String> 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<String> BUILTIN_TYPES =
List.of("int", "int8", "int16", "int32", "int64", "uint", "uint8", "uint16", "uint32", "uint64", "float",
"double", "short", "long", "bool");

@JsonCreator
public Variable(
Expand Down Expand Up @@ -52,7 +52,7 @@ public void setType(@NonNull String type) throws ModelException {
}

@JsonIgnore
public static Set<String> getBuiltinTypes() {
public static List<String> getBuiltinTypes() {
return BUILTIN_TYPES;
}

Expand Down
17 changes: 14 additions & 3 deletions src/main/java/org/gecko/tools/CursorTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down Expand Up @@ -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) {
Expand Down Expand Up @@ -295,7 +307,6 @@ private void cancelDrag(ElementScalerBlock scaler) {
}

private void cancelDrag() {
startDragPosition = null;
draggedElement = null;
isDragging = false;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/gecko/tools/RegionCreatorTool.java
Original file line number Diff line number Diff line change
Expand Up @@ -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
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/gecko/view/GeckoView.java
Original file line number Diff line number Diff line change
Expand Up @@ -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;
Expand Down
10 changes: 7 additions & 3 deletions src/main/java/org/gecko/view/ResourceHandler.java
Original file line number Diff line number Diff line change
Expand Up @@ -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.
*
Expand All @@ -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;
}
Expand Down
1 change: 0 additions & 1 deletion src/main/java/org/gecko/view/inspector/Inspector.java
Original file line number Diff line number Diff line change
Expand Up @@ -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());
Expand Down
Original file line number Diff line number Diff line change
@@ -1,18 +1,21 @@
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;

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;
Expand All @@ -22,14 +25,14 @@ public AutomatonVariablePaneBuilder(ActionManager actionManager, SystemViewModel
scrollPane.setPrefWidth(VARIABLE_PANE_WIDTH);

VBox content = new VBox();
InspectorVariableLabel inputLabel =
InspectorElement<HBox> inputLabel =
new InspectorVariableLabel(actionManager, systemViewModel, Visibility.INPUT);
InspectorVariableList inputList = new InspectorVariableList(actionManager, systemViewModel, Visibility.INPUT);
InspectorVariableLabel outputLabel =
InspectorElement<ListView<InspectorVariableField>> inputList =
new InspectorVariableList(actionManager, systemViewModel, Visibility.INPUT);
InspectorElement<HBox> 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<ListView<InspectorVariableField>> outputList =
new InspectorVariableList(actionManager, systemViewModel, Visibility.OUTPUT);

content.getChildren()
.addAll(inputLabel.getControl(), inputList.getControl(), outputLabel.getControl(), outputList.getControl());
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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 -> {
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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(
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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<ToggleButton> {
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());
Expand Down
Original file line number Diff line number Diff line change
@@ -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<String> {
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());
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -11,10 +11,13 @@
public class InspectorCodeSystemContainer extends VBox implements InspectorElement<VBox> {

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);
}

Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -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));
}
}
Original file line number Diff line number Diff line change
Expand Up @@ -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;

/**
Expand All @@ -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);
Expand Down
Original file line number Diff line number Diff line change
@@ -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;
Expand All @@ -13,6 +14,9 @@
*/
public class InspectorVariableList extends AbstractInspectorList<InspectorVariableField> {

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;
Expand All @@ -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));
Expand Down
Original file line number Diff line number Diff line change
Expand Up @@ -7,7 +7,7 @@
import org.gecko.view.inspector.element.InspectorElement;

public abstract class InspectorAreaField extends TextArea implements InspectorElement<TextArea> {
private static final int MAX_HEIGHT = 30;
private static final int MAX_HEIGHT = 40;
private static final int EXPANDED_MAX_HEIGHT = 90;

protected InspectorAreaField(ActionManager actionManager, StringProperty stringProperty, boolean isEmptyAllowed) {
Expand All @@ -16,7 +16,7 @@ protected InspectorAreaField(ActionManager actionManager, StringProperty stringP
setPrefHeight(MAX_HEIGHT);
setWrapText(true);

setOnMouseExited(event -> {
focusedProperty().addListener(event -> {
if ((getText() == null && stringProperty.get() == null) || (getText() != null && getText().equals(
stringProperty.get())) || (stringProperty.get() != null && stringProperty.get().equals(getText()))) {
return;
Expand Down
Original file line number Diff line number Diff line change
@@ -1,17 +1,23 @@
package org.gecko.view.inspector.element.textfield;

import javafx.beans.binding.Bindings;
import org.gecko.actions.Action;
import org.gecko.actions.ActionManager;
import org.gecko.viewmodel.SystemViewModel;

public class InspectorCodeSystemField extends InspectorAreaField {
private static final int HEIGHT_THRESHOLD = 90;
private final ActionManager actionManager;
private final SystemViewModel systemViewModel;

public InspectorCodeSystemField(ActionManager actionManager, SystemViewModel systemViewModel) {
super(actionManager, systemViewModel.getCodeProperty(), true);
this.actionManager = actionManager;
this.systemViewModel = systemViewModel;

prefHeightProperty().bind(
Bindings.createDoubleBinding(() -> getFont().getSize() * getParagraphs().size() + HEIGHT_THRESHOLD,
fontProperty(), textProperty()));
}

@Override
Expand Down

This file was deleted.

Loading

0 comments on commit 541521c

Please sign in to comment.