diff --git a/src/main/java/org/gecko/actions/CreatePortViewModelElementAction.java b/src/main/java/org/gecko/actions/CreatePortViewModelElementAction.java index 21a48d28..454784e4 100644 --- a/src/main/java/org/gecko/actions/CreatePortViewModelElementAction.java +++ b/src/main/java/org/gecko/actions/CreatePortViewModelElementAction.java @@ -16,6 +16,7 @@ public class CreatePortViewModelElementAction extends Action { private final GeckoViewModel geckoViewModel; private final SystemViewModel systemViewModel; private PortViewModel createdPortViewModel; + private static final int MARGIN = 2; CreatePortViewModelElementAction(GeckoViewModel geckoViewModel, SystemViewModel parentSystem) { this.geckoViewModel = geckoViewModel; @@ -26,7 +27,7 @@ public class CreatePortViewModelElementAction extends Action { boolean run() throws GeckoException { createdPortViewModel = geckoViewModel.getViewModelFactory().createPortViewModelIn(systemViewModel); double offset = createdPortViewModel.getSize().getY() * (systemViewModel.getPorts().size() - 1); - createdPortViewModel.setPosition(new Point2D(2, 2 + offset)); + createdPortViewModel.setPosition(new Point2D(MARGIN, MARGIN + offset)); return true; } diff --git a/src/main/java/org/gecko/actions/MoveSystemConnectionViewModelElementAction.java b/src/main/java/org/gecko/actions/MoveSystemConnectionViewModelElementAction.java index 57eef044..0d930491 100644 --- a/src/main/java/org/gecko/actions/MoveSystemConnectionViewModelElementAction.java +++ b/src/main/java/org/gecko/actions/MoveSystemConnectionViewModelElementAction.java @@ -30,6 +30,10 @@ public class MoveSystemConnectionViewModelElementAction extends Action { private boolean isVariableBlock = false; private boolean wasVariableBlock = false; + private static final int PLUS = 1; + private static final int MINUS = -1; + private static final double HALF = 0.5; + MoveSystemConnectionViewModelElementAction( GeckoViewModel geckoViewModel, SystemConnectionViewModel systemConnectionViewModel, ElementScalerBlock elementScalerBlock, Point2D delta) { @@ -172,9 +176,9 @@ private PortViewModel getPortViewModelAt(Point2D point) { } private Point2D calculateEndPortPosition(Point2D position, Point2D size, Visibility visibility, boolean isPort) { - int sign = isPort ? 1 : -1; - return position.add(size.multiply(0.5)) - .subtract((visibility == Visibility.INPUT ? 1 : -1) * sign * size.getX() / 2, 0); + int sign = isPort ? PLUS : MINUS; + return position.add(size.multiply(HALF)) + .subtract((visibility == Visibility.INPUT ? PLUS : MINUS) * sign * size.getX() / 2, 0); } private boolean isSource() { diff --git a/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java b/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java index e8bb59fa..fdafaeed 100644 --- a/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java +++ b/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java @@ -22,7 +22,7 @@ public class PastePositionableViewModelElementAction extends Action { private final GeckoViewModel geckoViewModel; private final Set> pastedElements; - private final Point2D pasteOffset = new Point2D(50, 50); + private static final Point2D PASTE_OFFSET = new Point2D(50, 50); private CopyPositionableViewModelElementVisitor copyVisitor; PastePositionableViewModelElementAction(GeckoViewModel geckoViewModel) { @@ -57,7 +57,7 @@ private boolean pasteSystem() { geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().addVariable(copy); copyVisitor.getCopiedPorts().put(v, copy); PortViewModel portViewModel = geckoViewModel.getViewModelFactory().createPortViewModelFrom(copy); - portViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(v).getKey().add(pasteOffset)); + portViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(v).getKey().add(PASTE_OFFSET)); pastedElements.add(portViewModel); } for (System s : copyVisitor.getCopiedSystems().keySet()) { @@ -72,7 +72,7 @@ private boolean pasteSystem() { } copyVisitor.getCopiedSystems().put(s, copy); SystemViewModel systemViewModel = geckoViewModel.getViewModelFactory().createSystemViewModelFrom(copy); - systemViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(s).getKey().add(pasteOffset)); + systemViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(s).getKey().add(PASTE_OFFSET)); pastedElements.add(systemViewModel); } return false; @@ -91,7 +91,7 @@ private boolean pasteAutomaton() throws MissingViewModelElementException { } copyVisitor.getCopiedStates().put(state, copy); StateViewModel stateViewModel = geckoViewModel.getViewModelFactory().createStateViewModelFrom(copy); - stateViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(state).getKey().add(pasteOffset)); + stateViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(state).getKey().add(PASTE_OFFSET)); stateViewModel.setSize(copyVisitor.getCopiedPosAndSize().get(state).getValue()); pastedElements.add(stateViewModel); } @@ -100,7 +100,7 @@ private boolean pasteAutomaton() throws MissingViewModelElementException { geckoViewModel.getGeckoModel().getModelFactory().copyRegion(copyVisitor.getCopiedRegions().get(region)); geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addRegion(copy); RegionViewModel regionViewModel = geckoViewModel.getViewModelFactory().createRegionViewModelFrom(copy); - regionViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(region).getKey().add(pasteOffset)); + regionViewModel.setPosition(copyVisitor.getCopiedPosAndSize().get(region).getKey().add(PASTE_OFFSET)); regionViewModel.setSize(copyVisitor.getCopiedPosAndSize().get(region).getValue()); pastedElements.add(regionViewModel); } diff --git a/src/main/java/org/gecko/application/GeckoIOManager.java b/src/main/java/org/gecko/application/GeckoIOManager.java index c8d0e9b6..e12dc8e4 100644 --- a/src/main/java/org/gecko/application/GeckoIOManager.java +++ b/src/main/java/org/gecko/application/GeckoIOManager.java @@ -164,7 +164,7 @@ public File getSaveFileChooser(FileTypes fileType) { private FileChooser getNewFileChooser(FileTypes fileType) { FileChooser fileChooser = new FileChooser(); fileChooser.getExtensionFilters() - .addAll(new FileChooser.ExtensionFilter(fileType.getFileDescription(), fileType.getFileNameRegex())); + .addAll(new FileChooser.ExtensionFilter(fileType.getFileDescription(), fileType.getFileNameGlob())); return fileChooser; } diff --git a/src/main/java/org/gecko/application/GeckoManager.java b/src/main/java/org/gecko/application/GeckoManager.java index f4c3aee2..c76bba80 100644 --- a/src/main/java/org/gecko/application/GeckoManager.java +++ b/src/main/java/org/gecko/application/GeckoManager.java @@ -14,6 +14,9 @@ public class GeckoManager { private Gecko gecko; private final Stage stage; + private static final int SCENE_WIDTH = 1024; + private static final int SCENE_HEIGHT = 768; + public GeckoManager(Stage stage) throws ModelException { this.stage = stage; setGecko(new Gecko()); @@ -21,6 +24,6 @@ public GeckoManager(Stage stage) throws ModelException { public void setGecko(Gecko gecko) { this.gecko = gecko; - stage.setScene(new Scene(gecko.getView().getMainPane(), 1024, 768)); + stage.setScene(new Scene(gecko.getView().getMainPane(), SCENE_WIDTH, SCENE_HEIGHT)); } } diff --git a/src/main/java/org/gecko/io/AutomatonFileSerializer.java b/src/main/java/org/gecko/io/AutomatonFileSerializer.java index 32cf85c5..fed98e4a 100644 --- a/src/main/java/org/gecko/io/AutomatonFileSerializer.java +++ b/src/main/java/org/gecko/io/AutomatonFileSerializer.java @@ -33,9 +33,23 @@ * to Gecko, such as regions, kinds and priorities, to be compatible with the sys file format. */ public class AutomatonFileSerializer implements FileSerializer { - private final GeckoModel model; + private static final String INDENT = " "; + private static final String SERIALIZED_CONTRACT_NAME_REGEX = "contract %s"; + private static final String AUTOMATON_SERIALIZATION_AS_SYSTEM_CONTRACT_REGEX + = SERIALIZED_CONTRACT_NAME_REGEX + " {"; + private static final String SERIALIZED_CONTRACT_REGEX = SERIALIZED_CONTRACT_NAME_REGEX + " := %s ==> %s"; + private static final String SERIALIZED_TRANSITION_REGEX = "%s -> %s :: %s"; + private static final String SERIALIZED_SYSTEM_REGEX = "reactor %s {"; + private static final String SERIALIZED_CONNECTION_REGEX = "%s.%s -> %s.%s"; + private static final String SERIALIZED_STATE_REGEX = "state %s: %s"; + private static final String VARIABLE_ATTRIBUTES_REGEX = " %s: %s"; + private static final String TRUE_CONDITION = "TRUE"; + private static final String SERIALIZED_INPUT = "input"; + private static final String SERIALIZED_OUTPUT = "output"; + private static final String SERIALIZED_STATE = "state"; + private static final int HIGHEST_PRIORITY = 0; public AutomatonFileSerializer(GeckoModel model) { this.model = model; @@ -70,7 +84,7 @@ private String serializeSystems(GeckoModel model) { private String serializeAutomaton(System system) { Automaton automaton = system.getAutomaton(); StringJoiner joiner = new StringJoiner(java.lang.System.lineSeparator()); - joiner.add("contract %s {".formatted(system.getName())); + joiner.add(AUTOMATON_SERIALIZATION_AS_SYSTEM_CONTRACT_REGEX.formatted(system.getName())); if (!system.getVariables().isEmpty()) { joiner.add(serializeIo(system)); joiner.add(""); @@ -127,10 +141,10 @@ private String serializeStateContracts(State state, Automaton automaton) { } //applying priorites - int prioIndex = 0; + int prioIndex = HIGHEST_PRIORITY; for (List edgeGroup : groupedEdges) { for (Edge edge : edgeGroup) { - if (prioIndex == 0) { + if (prioIndex == HIGHEST_PRIORITY) { continue; //Highest prio doesn't need to be altered } Contract contractWithPrio = newContracts.get(edge.getContract()); @@ -147,7 +161,7 @@ private void applyKindToContract(Contract contract, Kind kind) throws ModelExcep switch (kind) { case MISS -> { contract.setPreCondition(contract.getPreCondition().not()); - contract.setPostCondition(Condition.trueCondition()); + contract.setPostCondition(new Condition(TRUE_CONDITION)); } case FAIL -> { contract.setPostCondition(contract.getPostCondition().not()); @@ -196,18 +210,18 @@ private List andConditions(List regions) { } private String serializeContract(Contract contract) { - return INDENT + "contract %s := %s ==> %s".formatted(contract.getName(), contract.getPreCondition(), + return INDENT + SERIALIZED_CONTRACT_REGEX.formatted(contract.getName(), contract.getPreCondition(), contract.getPostCondition()); } private String serializeTransition(Edge edge) { - return INDENT + "%s -> %s :: %s".formatted(edge.getSource().getName(), edge.getDestination().getName(), - edge.getContract().getName()); + return INDENT + SERIALIZED_TRANSITION_REGEX + .formatted(edge.getSource().getName(), edge.getDestination().getName(), edge.getContract().getName()); } private String serializeSystem(System system) { StringJoiner joiner = new StringJoiner(java.lang.System.lineSeparator()); - joiner.add("reactor %s {".formatted(system.getName())); + joiner.add(SERIALIZED_SYSTEM_REGEX.formatted(system.getName())); if (!system.getVariables().isEmpty()) { joiner.add(serializeIo(system)); joiner.add(""); @@ -217,7 +231,7 @@ private String serializeSystem(System system) { joiner.add(""); } if (system.getAutomaton() != null && !system.getAutomaton().isEmpty()) { - joiner.add(INDENT + "contract %s".formatted(system.getName())); + joiner.add(INDENT + SERIALIZED_CONTRACT_NAME_REGEX.formatted(system.getName())); joiner.add(""); } if (!system.getConnections().isEmpty()) { @@ -241,12 +255,12 @@ private String serializeConnection(SystemConnection connection, System parent) { String startPort = connection.getSource().getName(); String endSystem = serializeSystemReference(parent, connection.getDestination()); String endPort = connection.getDestination().getName(); - return INDENT + "%s.%s -> %s.%s".formatted(startSystem, startPort, endSystem, endPort); + return INDENT + SERIALIZED_CONNECTION_REGEX.formatted(startSystem, startPort, endSystem, endPort); } private String serializeSystemReference(System parent, Variable var) { if (parent.getVariables().contains(var)) { - return "self"; + return AutomatonFileVisitor.SELF_REFERENCE_TOKEN; } else { return parent.getChildSystemWithVariable(var).getName(); } @@ -264,24 +278,24 @@ private String serializeChildren(System system) { } private String serializeChild(System system) { - return INDENT + "state %s: %s".formatted(system.getName(), system.getName()); + return INDENT + SERIALIZED_STATE_REGEX.formatted(system.getName(), system.getName()); } private String serializeVariable(Variable variable) { String output = ""; output += INDENT + switch (variable.getVisibility()) { - case INPUT -> "input"; - case OUTPUT -> "output"; - case STATE -> "state"; + case INPUT -> SERIALIZED_INPUT; + case OUTPUT -> SERIALIZED_OUTPUT; + case STATE -> SERIALIZED_STATE; default -> throw new IllegalArgumentException("Unknown visibility: " + variable.getVisibility()); }; - output += " %s: %s".formatted(variable.getName(), variable.getType()); + output += VARIABLE_ATTRIBUTES_REGEX.formatted(variable.getName(), variable.getType()); //TODO append variable value return output; } private String serializeCode(String code) { - return INDENT + "{=" + code + "=}"; + return INDENT + AutomatonFileVisitor.CODE_BEGIN + code + AutomatonFileVisitor.CODE_END; } private String serializeCollectionWithMapping(Collection collection, Function mapping) { diff --git a/src/main/java/org/gecko/io/AutomatonFileVisitor.java b/src/main/java/org/gecko/io/AutomatonFileVisitor.java index 1ea17c00..afe17b30 100644 --- a/src/main/java/org/gecko/io/AutomatonFileVisitor.java +++ b/src/main/java/org/gecko/io/AutomatonFileVisitor.java @@ -42,9 +42,12 @@ public class AutomatonFileVisitor extends SystemDefBaseVisitor { private AutomatonFileScout scout; private int elementsCreated; - private static final String START_STATE_REGEX = "[a-z].*"; - private static final String SELF_REFERENCE_TOKEN = "self"; + private static final int USER_SYSTEM_CHOICE_VBOX_SPACING = 10; + private static final int USER_SYSTEM_CHOICE_VBOX_PADDING = 20; + protected static final String SELF_REFERENCE_TOKEN = "self"; + protected static final String CODE_BEGIN = "{="; + protected static final String CODE_END = "=}"; public AutomatonFileVisitor() throws ModelException { this.model = new GeckoModel(); @@ -384,8 +387,7 @@ private void applySubstitution(Condition condition, String toReplace, String toR } private String cleanCode(String code) { - //length("{=") = 2 - return code.substring(2, code.length() - 2); + return code.substring(CODE_BEGIN.length(), code.length() - CODE_BEGIN.length()); } private System parseSystemReference(String name) { @@ -421,8 +423,8 @@ private String makeUserChooseSystem(List systemNames) { comboBox.getItems().addAll(systemNames); comboBox.setPromptText("Choose a system"); - VBox vBox = new VBox(10); - vBox.setPadding(new Insets(20)); + VBox vBox = new VBox(USER_SYSTEM_CHOICE_VBOX_SPACING); + vBox.setPadding(new Insets(USER_SYSTEM_CHOICE_VBOX_PADDING)); vBox.getChildren().add(comboBox); Alert alert = new Alert(Alert.AlertType.WARNING); diff --git a/src/main/java/org/gecko/io/FileTypes.java b/src/main/java/org/gecko/io/FileTypes.java index 23f063ae..66dcaf1c 100644 --- a/src/main/java/org/gecko/io/FileTypes.java +++ b/src/main/java/org/gecko/io/FileTypes.java @@ -18,7 +18,7 @@ public enum FileTypes { this.fileExtension = fileExtension; } - public String getFileNameRegex() { + public String getFileNameGlob() { return "*." + fileExtension; } } diff --git a/src/main/java/org/gecko/model/Condition.java b/src/main/java/org/gecko/model/Condition.java index 84b9ec7a..71279d36 100644 --- a/src/main/java/org/gecko/model/Condition.java +++ b/src/main/java/org/gecko/model/Condition.java @@ -14,6 +14,9 @@ public class Condition { private String condition; + private static final String AND_CONDITION_REGEX = "(%s) & (%s)"; + private static final String NOT_CONDITION_REGEX = "! (%s)"; + @JsonCreator public Condition(@JsonProperty("condition") String condition) throws ModelException { setCondition(condition); @@ -30,7 +33,7 @@ public void setCondition(@NonNull String condition) throws ModelException { public Condition and(Condition other) { try { // This and other are always valid - return new Condition("(" + condition + ") & (" + other.condition + ")"); + return new Condition(AND_CONDITION_REGEX.formatted(condition, other.condition)); } catch (ModelException e) { return null; } @@ -40,7 +43,7 @@ public Condition and(Condition other) { public Condition not() { try { // This is always valid - return new Condition("! (" + condition + ")"); + return new Condition(NOT_CONDITION_REGEX.formatted(condition)); } catch (ModelException e) { return null; } diff --git a/src/main/java/org/gecko/tools/CursorTool.java b/src/main/java/org/gecko/tools/CursorTool.java index aa730d2f..91c46b4f 100644 --- a/src/main/java/org/gecko/tools/CursorTool.java +++ b/src/main/java/org/gecko/tools/CursorTool.java @@ -29,9 +29,6 @@ * the {@link Point2D starting position} and the afferent {@link javafx.scene.shape.Rectangle}. */ public class CursorTool extends Tool { - - private static final double DRAG_THRESHOLD = 4; - private boolean isDragging = false; private final SelectionManager selectionManager; private final EditorViewModel editorViewModel; @@ -39,9 +36,10 @@ public class CursorTool extends Tool { private Point2D previousDragPosition; private Point2D oldPosition; private Point2D oldSize; - private ViewElementPane viewPane; + private static final double DRAG_THRESHOLD = 4; + public CursorTool(ActionManager actionManager, SelectionManager selectionManager, EditorViewModel editorViewModel) { super(actionManager, ToolType.CURSOR, false); this.selectionManager = selectionManager; diff --git a/src/main/java/org/gecko/tools/MarqueeTool.java b/src/main/java/org/gecko/tools/MarqueeTool.java index 269bddf3..05898efc 100644 --- a/src/main/java/org/gecko/tools/MarqueeTool.java +++ b/src/main/java/org/gecko/tools/MarqueeTool.java @@ -17,6 +17,9 @@ public class MarqueeTool extends AreaTool { private final EditorViewModel editorViewModel; + private static final double STROKE_WIDTH = 1; + private static final double STROKE_DASH = 5d; + public MarqueeTool(ActionManager actionManager, EditorViewModel editorViewModel) { super(actionManager, ToolType.MARQUEE_TOOL, true); this.editorViewModel = editorViewModel; @@ -27,8 +30,8 @@ Rectangle createNewArea() { Rectangle marquee = new Rectangle(); marquee.setFill(null); marquee.setStroke(Color.BLUE); - marquee.setStrokeWidth(1); - marquee.getStrokeDashArray().addAll(5d, 5d); + marquee.setStrokeWidth(STROKE_WIDTH); + marquee.getStrokeDashArray().addAll(STROKE_DASH, STROKE_DASH); return marquee; } diff --git a/src/main/java/org/gecko/tools/RegionCreatorTool.java b/src/main/java/org/gecko/tools/RegionCreatorTool.java index fc18a901..d0a34bdf 100644 --- a/src/main/java/org/gecko/tools/RegionCreatorTool.java +++ b/src/main/java/org/gecko/tools/RegionCreatorTool.java @@ -16,6 +16,8 @@ public class RegionCreatorTool extends AreaTool { private Color color; + private static final double MEDIUM_OPACITY = 0.5; + public RegionCreatorTool(ActionManager actionManager) { super(actionManager, ToolType.REGION_CREATOR, false); } @@ -25,7 +27,7 @@ Rectangle createNewArea() { Rectangle region = new Rectangle(); color = Color.color(Math.random(), Math.random(), Math.random()); region.setFill(color); - region.setOpacity(0.5); + region.setOpacity(MEDIUM_OPACITY); return region; } diff --git a/src/main/java/org/gecko/util/graphlayouting/Graphlayouter.java b/src/main/java/org/gecko/util/graphlayouting/Graphlayouter.java index d955f913..f0650d3e 100644 --- a/src/main/java/org/gecko/util/graphlayouting/Graphlayouter.java +++ b/src/main/java/org/gecko/util/graphlayouting/Graphlayouter.java @@ -25,6 +25,8 @@ public class Graphlayouter { private final GeckoViewModel viewModel; private final ELKGraphCreator elkGraphCreator; + private static final double THIRD_OF_SYSTEM_WIDTH_DIVIDER = 3; + public Graphlayouter(GeckoViewModel viewModel) { this.viewModel = viewModel; elkGraphCreator = new ELKGraphCreator(viewModel); @@ -53,7 +55,7 @@ private void layoutGraph(ElkNode root, LayoutAlgorithms layoutAlgorithm) { return; } root.setProperty(CoreOptions.ALGORITHM, layoutAlgorithm.toString()); - double spacing = root.getChildren().getFirst().getWidth() / 3; + double spacing = root.getChildren().getFirst().getWidth() / THIRD_OF_SYSTEM_WIDTH_DIVIDER; root.setProperty(CoreOptions.SPACING_NODE_NODE, spacing); if (layoutAlgorithm == LayoutAlgorithms.LAYERED) { root.setProperty(LayeredOptions.SPACING_NODE_NODE_BETWEEN_LAYERS, spacing); diff --git a/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java index 1d4a4cdd..4a09ebd3 100644 --- a/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java @@ -6,7 +6,6 @@ import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; import org.gecko.model.Kind; -import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.EdgeViewModel; /** @@ -18,6 +17,11 @@ public class EdgeViewElementContextMenuBuilder extends ViewContextMenuBuilder { private final EdgeViewModel edgeViewModel; + private static final String CHANGE_KIND_MENU_ITEM = "Change Kind"; + private static final String HIT_MENU_ITEM = "HIT"; + private static final String MISS_KIND_MENU_ITEM = "MISS"; + private static final String FAIL_KIND_MENU_ITEM = "FAIL"; + public EdgeViewElementContextMenuBuilder( ActionManager actionManager, EdgeViewModel edgeViewModel) { super(actionManager); @@ -32,23 +36,23 @@ public ContextMenu build() { SeparatorMenuItem dataTransferToEdgeEditingSeparator = new SeparatorMenuItem(); // Edge editing commands: - Menu changeKindMenu = new Menu(ResourceHandler.getString("Buttons", "change_kind")); + Menu changeKindMenu = new Menu(CHANGE_KIND_MENU_ITEM); // TODO: Synchronize fields showed in inspector. - MenuItem hitMenuItem = new MenuItem(Kind.HIT.name()); + MenuItem hitMenuItem = new MenuItem(HIT_MENU_ITEM); hitMenuItem.setOnAction( e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, Kind.HIT))); - MenuItem missMenuItem = new MenuItem(Kind.MISS.name()); + MenuItem missMenuItem = new MenuItem(MISS_KIND_MENU_ITEM); missMenuItem.setOnAction( e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, Kind.MISS))); - MenuItem failMenuItem = new MenuItem(Kind.FAIL.name()); + MenuItem failMenuItem = new MenuItem(FAIL_KIND_MENU_ITEM); failMenuItem.setOnAction( e -> actionManager.run(actionManager.getActionFactory().createChangeKindAction(edgeViewModel, Kind.FAIL))); changeKindMenu.getItems().addAll(hitMenuItem, missMenuItem, failMenuItem); - MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete")); + MenuItem deleteMenuItem = new MenuItem(DELETE_MENU_ITEM); deleteMenuItem.setOnAction(e -> actionManager.run( actionManager.getActionFactory().createDeletePositionableViewModelElementAction(edgeViewModel))); diff --git a/src/main/java/org/gecko/view/contextmenu/RegionViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/RegionViewElementContextMenuBuilder.java index bdbe6373..7e256a16 100644 --- a/src/main/java/org/gecko/view/contextmenu/RegionViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/RegionViewElementContextMenuBuilder.java @@ -4,7 +4,6 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.RegionViewModel; /** @@ -30,7 +29,7 @@ public ContextMenu build() { SeparatorMenuItem dataTransferToRegionEditingSeparator = new SeparatorMenuItem(); // Region editing commands: - MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete")); + MenuItem deleteMenuItem = new MenuItem(DELETE_MENU_ITEM); deleteMenuItem.setOnAction(e -> actionManager.run( actionManager.getActionFactory().createDeletePositionableViewModelElementAction(regionViewModel))); diff --git a/src/main/java/org/gecko/view/contextmenu/StateViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/StateViewElementContextMenuBuilder.java index 5fe8f523..fb6544b6 100644 --- a/src/main/java/org/gecko/view/contextmenu/StateViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/StateViewElementContextMenuBuilder.java @@ -4,7 +4,6 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.StateViewModel; /** @@ -16,6 +15,8 @@ public class StateViewElementContextMenuBuilder extends ViewContextMenuBuilder { private final StateViewModel stateViewModel; + private static final String START_STATE_MENU_ITEM = "Start State"; + public StateViewElementContextMenuBuilder( ActionManager actionManager, StateViewModel stateViewModel) { super(actionManager); @@ -29,12 +30,12 @@ public ContextMenu build() { SeparatorMenuItem dataTransferToStateEditingSeparator = new SeparatorMenuItem(); // State editing commands: - MenuItem startStateMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "set_start_state")); + MenuItem startStateMenuItem = new MenuItem(START_STATE_MENU_ITEM); startStateMenuItem.setDisable(stateViewModel.getIsStartState()); startStateMenuItem.setOnAction(e -> actionManager.run( actionManager.getActionFactory().createSetStartStateViewModelElementAction(stateViewModel))); - MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete")); + MenuItem deleteMenuItem = new MenuItem(DELETE_MENU_ITEM); deleteMenuItem.setOnAction(e -> actionManager.run( actionManager.getActionFactory().createDeletePositionableViewModelElementAction(stateViewModel))); diff --git a/src/main/java/org/gecko/view/contextmenu/SystemConnectionViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/SystemConnectionViewElementContextMenuBuilder.java index 6bd236c0..f6960bca 100644 --- a/src/main/java/org/gecko/view/contextmenu/SystemConnectionViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/SystemConnectionViewElementContextMenuBuilder.java @@ -4,7 +4,6 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.SystemConnectionViewModel; /** @@ -30,7 +29,7 @@ public ContextMenu build() { SeparatorMenuItem dataTransferToEdgeEditingSeparator = new SeparatorMenuItem(); // SystemConnection editing commands: - MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete")); + MenuItem deleteMenuItem = new MenuItem(DELETE_MENU_ITEM); deleteMenuItem.setOnAction(e -> actionManager.run(actionManager.getActionFactory() .createDeletePositionableViewModelElementAction(systemConnectionViewModel))); diff --git a/src/main/java/org/gecko/view/contextmenu/SystemViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/SystemViewElementContextMenuBuilder.java index 9c011a2b..9ca5c3b4 100644 --- a/src/main/java/org/gecko/view/contextmenu/SystemViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/SystemViewElementContextMenuBuilder.java @@ -4,7 +4,6 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.view.views.shortcuts.Shortcuts; import org.gecko.viewmodel.SystemViewModel; @@ -17,6 +16,8 @@ public class SystemViewElementContextMenuBuilder extends ViewContextMenuBuilder private final SystemViewModel systemViewModel; + private static final String OPEN_SYSTEM_MENU_ITEM = "Open System"; + public SystemViewElementContextMenuBuilder( ActionManager actionManager, SystemViewModel systemViewModel) { super(actionManager); @@ -31,12 +32,12 @@ public ContextMenu build() { SeparatorMenuItem dataTransferToSystemAccessSeparator = new SeparatorMenuItem(); // Access system commands: - MenuItem openSystemMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "open_system")); + MenuItem openSystemMenuItem = new MenuItem(OPEN_SYSTEM_MENU_ITEM); openSystemMenuItem.setOnAction( e -> actionManager.run(actionManager.getActionFactory().createViewSwitchAction(systemViewModel, false))); openSystemMenuItem.setAccelerator(Shortcuts.OPEN_CHILD_SYSTEM_EDITOR.get()); - MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete")); + MenuItem deleteMenuItem = new MenuItem(DELETE_MENU_ITEM); deleteMenuItem.setOnAction(e -> actionManager.run( actionManager.getActionFactory().createDeletePositionableViewModelElementAction(systemViewModel))); diff --git a/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java index 4daaff47..f3d7732c 100644 --- a/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java @@ -4,7 +4,6 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.PortViewModel; /** @@ -28,7 +27,8 @@ public ContextMenu build() { SeparatorMenuItem dataTransferToVariableBlockEditingSeparator = new SeparatorMenuItem(); - MenuItem deleteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "delete")); + // Variable Block editing commands: + MenuItem deleteMenuItem = new MenuItem(DELETE_MENU_ITEM); deleteMenuItem.setOnAction(e -> actionManager.run( actionManager.getActionFactory().createDeletePositionableViewModelElementAction(portViewModel))); diff --git a/src/main/java/org/gecko/view/contextmenu/ViewContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/ViewContextMenuBuilder.java index 2d3696a1..2c395906 100644 --- a/src/main/java/org/gecko/view/contextmenu/ViewContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/ViewContextMenuBuilder.java @@ -7,7 +7,6 @@ import lombok.Getter; import lombok.Setter; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.view.views.shortcuts.Shortcuts; import org.gecko.viewmodel.EditorViewModel; @@ -23,6 +22,13 @@ public class ViewContextMenuBuilder { @Getter protected ContextMenu contextMenu; + protected static final String DELETE_MENU_ITEM = "Delete"; + private static final String CUT_MENU_ITEM = "Cut"; + private static final String COPY_MENU_ITEM = "Copy"; + private static final String PASTE_MENU_ITEM = "Paste"; + private static final String SELECT_ALL_MENU_ITEM = "Select All"; + private static final String DESELECT_ALL_MENU_ITEM = "Deselect All"; + public ViewContextMenuBuilder(ActionManager actionManager) { this.actionManager = actionManager; this.editorViewModel = null; @@ -37,7 +43,7 @@ public ContextMenu build() { ContextMenu contextMenu = new ContextMenu(); // Data transfer commands: - MenuItem cutMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "cut")); + MenuItem cutMenuItem = new MenuItem(CUT_MENU_ITEM); cutMenuItem.setOnAction(e -> { actionManager.run(actionManager.getActionFactory().createCopyPositionableViewModelElementAction()); actionManager.run(actionManager.getActionFactory().createDeletePositionableViewModelElementAction()); @@ -50,7 +56,7 @@ public ContextMenu build() { editorViewModel.getSelectionManager().getCurrentSelectionProperty())); } - MenuItem copyMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "copy")); + MenuItem copyMenuItem = new MenuItem(COPY_MENU_ITEM); copyMenuItem.setOnAction( e -> actionManager.run(actionManager.getActionFactory().createCopyPositionableViewModelElementAction())); copyMenuItem.setAccelerator(Shortcuts.COPY.get()); @@ -61,7 +67,7 @@ public ContextMenu build() { editorViewModel.getSelectionManager().getCurrentSelectionProperty())); } - MenuItem pasteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "paste")); + MenuItem pasteMenuItem = new MenuItem(PASTE_MENU_ITEM); pasteMenuItem.setOnAction( e -> actionManager.run(actionManager.getActionFactory().createPastePositionableViewModelElementAction())); pasteMenuItem.setAccelerator(Shortcuts.PASTE.get()); @@ -69,7 +75,7 @@ public ContextMenu build() { SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem(); separatorMenuItem.setText(""); - MenuItem selectMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "select_all")); + MenuItem selectMenuItem = new MenuItem(SELECT_ALL_MENU_ITEM); selectMenuItem.setOnAction(e -> actionManager.run(actionManager.getActionFactory() .createSelectAction(editorViewModel.getPositionableViewModelElements(), true))); selectMenuItem.setAccelerator(Shortcuts.SELECT_ALL.get()); @@ -80,7 +86,7 @@ public ContextMenu build() { editorViewModel.getContainedPositionableViewModelElementsProperty())); } - MenuItem deselectMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "deselect_all")); + MenuItem deselectMenuItem = new MenuItem(DESELECT_ALL_MENU_ITEM); deselectMenuItem.setOnAction(e -> actionManager.run(actionManager.getActionFactory().createDeselectAction())); deselectMenuItem.setAccelerator(Shortcuts.DESELECT_ALL.get()); if (editorViewModel != null) { diff --git a/src/main/java/org/gecko/view/inspector/Inspector.java b/src/main/java/org/gecko/view/inspector/Inspector.java index 70a8b39d..2fe6bf46 100644 --- a/src/main/java/org/gecko/view/inspector/Inspector.java +++ b/src/main/java/org/gecko/view/inspector/Inspector.java @@ -20,6 +20,7 @@ public class Inspector extends ScrollPane { private static final int INSPECTOR_ELEMENT_SPACING = 10; + private static final double INSPECTOR_ELEMENT_PADDING = INSPECTOR_ELEMENT_SPACING / 2.0; private static final int INSPECTOR_WIDTH = 320; private static final String INSPECTOR_STYLE_NAME = "inspector"; @@ -45,7 +46,7 @@ public Inspector( for (InspectorElement element : elements) { vBox.getChildren().add(element.getControl()); } - setPadding(new Insets(INSPECTOR_ELEMENT_SPACING / 2.0)); + setPadding(new Insets(INSPECTOR_ELEMENT_PADDING)); vBox.setSpacing(INSPECTOR_ELEMENT_SPACING); getStyleClass().add(INSPECTOR_STYLE_NAME); setContent(vBox); diff --git a/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java b/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java index a30e80fd..33e51959 100644 --- a/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/AbstractInspectorBuilder.java @@ -24,6 +24,8 @@ public abstract class AbstractInspectorBuilder> inspectorElements; + public static final String INSPECTOR = "Inspector"; + protected AbstractInspectorBuilder(ActionManager actionManager, T viewModel) { this.actionManager = actionManager; this.viewModel = viewModel; 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 39fb1bf0..9ada2066 100644 --- a/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/AutomatonVariablePaneBuilder.java @@ -18,6 +18,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 static final double ELEMENT_PADDING = ELEMENT_SPACING / 2.0; private final ScrollPane scrollPane; @@ -42,7 +43,7 @@ public AutomatonVariablePaneBuilder(ActionManager actionManager, SystemViewModel .addAll(inputLabel.getControl(), inputList.getControl(), outputLabel.getControl(), outputList.getControl()); content.setSpacing(ELEMENT_SPACING); scrollPane.setFitToWidth(true); - scrollPane.setPadding(new Insets(ELEMENT_SPACING / 2.0)); + scrollPane.setPadding(new Insets(ELEMENT_PADDING)); scrollPane.setContent(content); } diff --git a/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java b/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java index 792c3596..59abc442 100644 --- a/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/EdgeInspectorBuilder.java @@ -19,6 +19,9 @@ * {@link InspectorContractComboBox}. */ public class EdgeInspectorBuilder extends AbstractInspectorBuilder { + private static final String SOURCE_KEY = "source"; + private static final String TARGET_KEY = "source"; + private static final String CONTRACTS_KEY = "contract_plural"; public EdgeInspectorBuilder(ActionManager actionManager, EdgeViewModel viewModel) { super(actionManager, viewModel); @@ -29,9 +32,9 @@ public EdgeInspectorBuilder(ActionManager actionManager, EdgeViewModel viewModel // Connected states addInspectorElement(new InspectorEdgeStateLabel(actionManager, viewModel.getSource(), - ResourceHandler.getString("Inspector", "source"))); + ResourceHandler.getString(INSPECTOR, SOURCE_KEY))); addInspectorElement(new InspectorEdgeStateLabel(actionManager, viewModel.getDestination(), - ResourceHandler.getString("Inspector", "target"))); + ResourceHandler.getString(INSPECTOR, TARGET_KEY))); addInspectorElement(new InspectorSeparator()); // Priority @@ -39,7 +42,7 @@ public EdgeInspectorBuilder(ActionManager actionManager, EdgeViewModel viewModel addInspectorElement(new InspectorSeparator()); // Contracts - addInspectorElement(new InspectorLabel(ResourceHandler.getString("Inspector", "contract_plural"))); + addInspectorElement(new InspectorLabel(ResourceHandler.getString(INSPECTOR, CONTRACTS_KEY))); addInspectorElement(new InspectorContractComboBox(actionManager, viewModel)); } } diff --git a/src/main/java/org/gecko/view/inspector/builder/RegionInspectorBuilder.java b/src/main/java/org/gecko/view/inspector/builder/RegionInspectorBuilder.java index 92bc0de2..8f414e49 100644 --- a/src/main/java/org/gecko/view/inspector/builder/RegionInspectorBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/RegionInspectorBuilder.java @@ -16,6 +16,7 @@ * {@link InspectorContractItem}. */ public class RegionInspectorBuilder extends AbstractInspectorBuilder { + private static final String CONTRACT_KEY = "contract"; public RegionInspectorBuilder(ActionManager actionManager, RegionViewModel viewModel) { super(actionManager, viewModel); @@ -25,7 +26,7 @@ public RegionInspectorBuilder(ActionManager actionManager, RegionViewModel viewM addInspectorElement(new InspectorSeparator()); // Contracts - addInspectorElement(new InspectorLabel(ResourceHandler.getString("Inspector", "contract"))); + addInspectorElement(new InspectorLabel(ResourceHandler.getString(INSPECTOR, CONTRACT_KEY))); addInspectorElement(new InspectorContractItem(actionManager, viewModel)); } } diff --git a/src/main/java/org/gecko/view/inspector/builder/StateInspectorBuilder.java b/src/main/java/org/gecko/view/inspector/builder/StateInspectorBuilder.java index 5802b071..f4d51865 100644 --- a/src/main/java/org/gecko/view/inspector/builder/StateInspectorBuilder.java +++ b/src/main/java/org/gecko/view/inspector/builder/StateInspectorBuilder.java @@ -2,7 +2,6 @@ import javafx.collections.ObservableList; import org.gecko.actions.ActionManager; -import org.gecko.view.ResourceHandler; import org.gecko.view.inspector.element.InspectorSeparator; import org.gecko.view.inspector.element.button.InspectorSetStartStateButton; import org.gecko.view.inspector.element.container.InspectorContractLabel; @@ -22,13 +21,14 @@ * {@link InspectorContractList}. */ public class StateInspectorBuilder extends AbstractInspectorBuilder { + private static final String REGIONS = "Regions"; public StateInspectorBuilder( ActionManager actionManager, EditorViewModel editorViewModel, StateViewModel viewModel) { super(actionManager, viewModel); // Region label - addInspectorElement(new InspectorLabel(ResourceHandler.getString("Inspector", "region_plural"))); + addInspectorElement(new InspectorLabel(REGIONS)); ObservableList regionViewModelList = editorViewModel.getRegionViewModels(viewModel); addInspectorElement(new InspectorRegionList(regionViewModelList)); diff --git a/src/main/java/org/gecko/view/inspector/element/InspectorElement.java b/src/main/java/org/gecko/view/inspector/element/InspectorElement.java index 69a53100..a29ba08a 100644 --- a/src/main/java/org/gecko/view/inspector/element/InspectorElement.java +++ b/src/main/java/org/gecko/view/inspector/element/InspectorElement.java @@ -9,4 +9,6 @@ */ public interface InspectorElement { T getControl(); + + int FIELD_OFFSET = 50; } diff --git a/src/main/java/org/gecko/view/inspector/element/button/AbstractInspectorButton.java b/src/main/java/org/gecko/view/inspector/element/button/AbstractInspectorButton.java index 4d17efb0..587ce0ef 100644 --- a/src/main/java/org/gecko/view/inspector/element/button/AbstractInspectorButton.java +++ b/src/main/java/org/gecko/view/inspector/element/button/AbstractInspectorButton.java @@ -8,6 +8,7 @@ */ public abstract class AbstractInspectorButton extends Button implements InspectorElement