From 329b563f016f8fd1281fd692182c9c734516544a Mon Sep 17 00:00:00 2001 From: uhypu Date: Sun, 10 Mar 2024 20:19:05 +0100 Subject: [PATCH] paste in middle of screen --- .../java/org/gecko/actions/ActionFactory.java | 4 +- ...stePositionableViewModelElementAction.java | 10 +- ...tePositionableViewModelElementVisitor.java | 102 +++++++++++------- .../EdgeViewElementContextMenuBuilder.java | 5 +- .../RegionViewElementContextMenuBuilder.java | 5 +- .../StateViewElementContextMenuBuilder.java | 5 +- ...nnectionViewElementContextMenuBuilder.java | 5 +- .../SystemViewElementContextMenuBuilder.java | 5 +- ...bleBlockViewElementContextMenuBuilder.java | 5 +- .../contextmenu/ViewContextMenuBuilder.java | 16 ++- .../gecko/view/menubar/MenuBarBuilder.java | 7 +- .../java/org/gecko/view/views/EditorView.java | 9 +- .../org/gecko/view/views/ViewElementPane.java | 2 +- .../org/gecko/view/views/ViewFactory.java | 13 +-- 14 files changed, 117 insertions(+), 76 deletions(-) diff --git a/src/main/java/org/gecko/actions/ActionFactory.java b/src/main/java/org/gecko/actions/ActionFactory.java index 49d74f71..9fdf8842 100644 --- a/src/main/java/org/gecko/actions/ActionFactory.java +++ b/src/main/java/org/gecko/actions/ActionFactory.java @@ -172,8 +172,8 @@ public MoveSystemConnectionViewModelElementAction createMoveSystemConnectionView elementScalerBlock, portViewModel, isVariableBlock); } - public PastePositionableViewModelElementAction createPastePositionableViewModelElementAction() { - return new PastePositionableViewModelElementAction(geckoViewModel); + public PastePositionableViewModelElementAction createPastePositionableViewModelElementAction(Point2D center) { + return new PastePositionableViewModelElementAction(geckoViewModel, center); } public RenameViewModelElementAction createRenameViewModelElementAction(Renamable renamable, String name) { diff --git a/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java b/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java index 6fc5dc66..2cf62704 100644 --- a/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java +++ b/src/main/java/org/gecko/actions/PastePositionableViewModelElementAction.java @@ -11,12 +11,13 @@ public class PastePositionableViewModelElementAction extends Action { private final GeckoViewModel geckoViewModel; private final Set> pastedElements; - private static final Point2D PASTE_OFFSET = new Point2D(50, 50); + private final Point2D pasteOffset; private CopyPositionableViewModelElementVisitor copyVisitor; - PastePositionableViewModelElementAction(GeckoViewModel geckoViewModel) { + PastePositionableViewModelElementAction(GeckoViewModel geckoViewModel, Point2D center) { this.geckoViewModel = geckoViewModel; - pastedElements = new HashSet<>(); + this.pastedElements = new HashSet<>(); + this.pasteOffset = center; } @Override @@ -30,7 +31,7 @@ boolean run() throws GeckoException { } PastePositionableViewModelElementVisitor pasteVisitor = - new PastePositionableViewModelElementVisitor(geckoViewModel, copyVisitor); + new PastePositionableViewModelElementVisitor(geckoViewModel, copyVisitor, pasteOffset); for (Element element : copyVisitor.getOriginalToClipboard().values()) { element.accept(pasteVisitor); } @@ -41,6 +42,7 @@ boolean run() throws GeckoException { element.accept(pasteVisitor); } } + pasteVisitor.updatePositions(); pastedElements.addAll(pasteVisitor.getPastedElements()); Action selectAction = geckoViewModel.getActionManager().getActionFactory().createSelectAction(pastedElements, true); diff --git a/src/main/java/org/gecko/actions/PastePositionableViewModelElementVisitor.java b/src/main/java/org/gecko/actions/PastePositionableViewModelElementVisitor.java index 4b228e73..a3e5fbc0 100644 --- a/src/main/java/org/gecko/actions/PastePositionableViewModelElementVisitor.java +++ b/src/main/java/org/gecko/actions/PastePositionableViewModelElementVisitor.java @@ -10,6 +10,7 @@ import lombok.Getter; import org.gecko.exceptions.MissingViewModelElementException; import org.gecko.exceptions.ModelException; +import org.gecko.model.Automaton; import org.gecko.model.Contract; import org.gecko.model.Edge; import org.gecko.model.Element; @@ -31,7 +32,7 @@ public class PastePositionableViewModelElementVisitor implements ElementVisitor { private final GeckoViewModel geckoViewModel; private final CopyPositionableViewModelElementVisitor copyVisitor; - private final Point2D pasteOffset = new Point2D(50, 50); + private final Point2D pasteOffset; @Getter private final Set> pastedElements; private final BiMap clipboardToPasted; @@ -39,12 +40,13 @@ public class PastePositionableViewModelElementVisitor implements ElementVisitor private final Set unsuccessfulPastes; PastePositionableViewModelElementVisitor( - GeckoViewModel geckoViewModel, CopyPositionableViewModelElementVisitor copyVisitor) { + GeckoViewModel geckoViewModel, CopyPositionableViewModelElementVisitor copyVisitor, Point2D pasteOffset) { this.geckoViewModel = geckoViewModel; this.copyVisitor = copyVisitor; pastedElements = new HashSet<>(); clipboardToPasted = HashBiMap.create(); unsuccessfulPastes = new HashSet<>(); + this.pasteOffset = pasteOffset; } @Override @@ -53,10 +55,13 @@ public void visit(State stateFromClipboard) throws ModelException { geckoViewModel.getGeckoModel().getModelFactory().copyState(stateFromClipboard); State stateToPaste = copyResult.getKey(); clipboardToPasted.putAll(copyResult.getValue()); - geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addState(stateToPaste); + Automaton automaton = geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton(); + automaton.addState(stateToPaste); + if (automaton.getStartState() == null) { + automaton.setStartState(stateToPaste); + } StateViewModel stateViewModel = geckoViewModel.getViewModelFactory().createStateViewModelFrom(stateToPaste); - stateViewModel.setPosition( - copyVisitor.getElementToPosAndSize().get(stateFromClipboard).getKey().add(pasteOffset)); + stateViewModel.setPosition(copyVisitor.getElementToPosAndSize().get(stateFromClipboard).getKey()); stateViewModel.setSize(copyVisitor.getElementToPosAndSize().get(stateFromClipboard).getValue()); clipboardToPasted.put(stateFromClipboard, stateToPaste); pastedElements.add(stateViewModel); @@ -100,7 +105,6 @@ public void visit(Variable variableFromClipboard) throws ModelException { Variable variableToPaste = geckoViewModel.getGeckoModel().getModelFactory().copyVariable(variableFromClipboard); geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().addVariable(variableToPaste); PortViewModel portViewModel = geckoViewModel.getViewModelFactory().createPortViewModelFrom(variableToPaste); - //portViewModel.setPosition(copyVisitor.getElementToPosAndSize().get(variableFromClipboard).getKey().add(pasteOffset)); clipboardToPasted.put(variableFromClipboard, variableToPaste); pastedElements.add(portViewModel); } @@ -120,6 +124,36 @@ public void visit(System systemFromClipboard) throws ModelException { clipboardToPasted.put(systemFromClipboard, systemToPaste); } + @Override + public void visit(Region regionFromClipboard) throws ModelException, MissingViewModelElementException { + Region regionToPaste = geckoViewModel.getGeckoModel().getModelFactory().copyRegion(regionFromClipboard); + clipboardToPasted.put(regionFromClipboard, regionToPaste); + geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addRegion(regionToPaste); + RegionViewModel regionViewModel = geckoViewModel.getViewModelFactory().createRegionViewModelFrom(regionToPaste); + regionViewModel.setPosition( + copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getKey().add(pasteOffset)); + regionViewModel.setSize(copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getValue()); + pastedElements.add(regionViewModel); + } + + @Override + public void visit(Edge edge) throws ModelException, MissingViewModelElementException { + Edge copy = geckoViewModel.getGeckoModel().getModelFactory().copyEdge(edge); + State pastedSource = (State) clipboardToPasted.get(edge.getSource()); + State pastedDestination = (State) clipboardToPasted.get(edge.getDestination()); + Contract pastedContract = (Contract) clipboardToPasted.get(edge.getContract()); + if (pastedSource == null || pastedDestination == null) { + unsuccessfulPastes.add(edge); + return; + } + geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addEdge(copy); + copy.setSource(pastedSource); + copy.setDestination(pastedDestination); + copy.setContract(pastedContract); + EdgeViewModel edgeViewModel = geckoViewModel.getViewModelFactory().createEdgeViewModelFrom(copy); + pastedElements.add(edgeViewModel); + } + private void createRecursiveSystemViewModels(System systemToPaste) { System systemFromClipboard = (System) clipboardToPasted.inverse().get(systemToPaste); SystemViewModel systemViewModel = geckoViewModel.getViewModelFactory().createSystemViewModelFrom(systemToPaste); @@ -130,19 +164,15 @@ private void createRecursiveSystemViewModels(System systemToPaste) { } for (State state : systemToPaste.getAutomaton().getStates()) { StateViewModel stateViewModel = geckoViewModel.getViewModelFactory().createStateViewModelFrom(state); - stateViewModel.setPosition(copyVisitor.getElementToPosAndSize() - .get(clipboardToPasted.inverse().get(state)) - .getKey() - .add(pasteOffset)); + stateViewModel.setPosition( + copyVisitor.getElementToPosAndSize().get(clipboardToPasted.inverse().get(state)).getKey()); } for (Region region : systemToPaste.getAutomaton().getRegions()) { try { RegionViewModel regionViewModel = geckoViewModel.getViewModelFactory().createRegionViewModelFrom(region); - regionViewModel.setPosition(copyVisitor.getElementToPosAndSize() - .get(clipboardToPasted.inverse().get(region)) - .getKey() - .add(pasteOffset)); + regionViewModel.setPosition( + copyVisitor.getElementToPosAndSize().get(clipboardToPasted.inverse().get(region)).getKey()); } catch (MissingViewModelElementException e) { throw new RuntimeException(e); } @@ -166,33 +196,23 @@ private void createRecursiveSystemViewModels(System systemToPaste) { } } - @Override - public void visit(Region regionFromClipboard) throws ModelException, MissingViewModelElementException { - Region regionToPaste = geckoViewModel.getGeckoModel().getModelFactory().copyRegion(regionFromClipboard); - clipboardToPasted.put(regionFromClipboard, regionToPaste); - geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addRegion(regionToPaste); - RegionViewModel regionViewModel = geckoViewModel.getViewModelFactory().createRegionViewModelFrom(regionToPaste); - regionViewModel.setPosition( - copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getKey().add(pasteOffset)); - regionViewModel.setSize(copyVisitor.getElementToPosAndSize().get(regionFromClipboard).getValue()); - pastedElements.add(regionViewModel); - } - - @Override - public void visit(Edge edge) throws ModelException, MissingViewModelElementException { - Edge copy = geckoViewModel.getGeckoModel().getModelFactory().copyEdge(edge); - State pastedSource = (State) clipboardToPasted.get(edge.getSource()); - State pastedDestination = (State) clipboardToPasted.get(edge.getDestination()); - Contract pastedContract = (Contract) clipboardToPasted.get(edge.getContract()); - if (pastedSource == null || pastedDestination == null) { - unsuccessfulPastes.add(edge); - return; + public void updatePositions() { + Point2D minPos = new Point2D(Double.MAX_VALUE, Double.MAX_VALUE); + Point2D maxPos = new Point2D(-Double.MAX_VALUE, -Double.MAX_VALUE); + for (PositionableViewModelElement element : pastedElements) { + if (element.getSize().equals(Point2D.ZERO)) { + continue; + } + double x = element.getPosition().getX(); + double y = element.getPosition().getY(); + minPos = new Point2D(Math.min(minPos.getX(), x), Math.min(minPos.getY(), y)); + maxPos = new Point2D(Math.max(maxPos.getX(), x + element.getSize().getX()), + Math.max(maxPos.getY(), y + element.getSize().getY())); + } + Point2D center = minPos.midpoint(maxPos); + for (PositionableViewModelElement element : pastedElements) { + Point2D pos = element.getCenter(); + element.setCenter(pos.subtract(center).add(pasteOffset)); } - geckoViewModel.getCurrentEditor().getCurrentSystem().getTarget().getAutomaton().addEdge(copy); - copy.setSource(pastedSource); - copy.setDestination(pastedDestination); - copy.setContract(pastedContract); - EdgeViewModel edgeViewModel = geckoViewModel.getViewModelFactory().createEdgeViewModelFrom(copy); - pastedElements.add(edgeViewModel); } } diff --git a/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java index 3eef7d33..e5080df1 100644 --- a/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/EdgeViewElementContextMenuBuilder.java @@ -6,6 +6,7 @@ import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; import org.gecko.model.Kind; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.EdgeViewModel; @@ -19,8 +20,8 @@ public class EdgeViewElementContextMenuBuilder extends ViewContextMenuBuilder { private final EdgeViewModel edgeViewModel; public EdgeViewElementContextMenuBuilder( - ActionManager actionManager, EdgeViewModel edgeViewModel) { - super(actionManager); + ActionManager actionManager, EdgeViewModel edgeViewModel, GeckoView geckoView) { + super(actionManager, geckoView); this.edgeViewModel = 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..f2d1a896 100644 --- a/src/main/java/org/gecko/view/contextmenu/RegionViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/RegionViewElementContextMenuBuilder.java @@ -4,6 +4,7 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.RegionViewModel; @@ -17,8 +18,8 @@ public class RegionViewElementContextMenuBuilder extends ViewContextMenuBuilder private final RegionViewModel regionViewModel; public RegionViewElementContextMenuBuilder( - ActionManager actionManager, RegionViewModel regionViewModel) { - super(actionManager); + ActionManager actionManager, RegionViewModel regionViewModel, GeckoView geckoView) { + super(actionManager, geckoView); this.regionViewModel = 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..9fc3895e 100644 --- a/src/main/java/org/gecko/view/contextmenu/StateViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/StateViewElementContextMenuBuilder.java @@ -4,6 +4,7 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.StateViewModel; @@ -17,8 +18,8 @@ public class StateViewElementContextMenuBuilder extends ViewContextMenuBuilder { private final StateViewModel stateViewModel; public StateViewElementContextMenuBuilder( - ActionManager actionManager, StateViewModel stateViewModel) { - super(actionManager); + ActionManager actionManager, StateViewModel stateViewModel, GeckoView geckoView) { + super(actionManager, geckoView); this.stateViewModel = 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..4ea5f0a5 100644 --- a/src/main/java/org/gecko/view/contextmenu/SystemConnectionViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/SystemConnectionViewElementContextMenuBuilder.java @@ -4,6 +4,7 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.SystemConnectionViewModel; @@ -17,8 +18,8 @@ public class SystemConnectionViewElementContextMenuBuilder extends ViewContextMe private final SystemConnectionViewModel systemConnectionViewModel; public SystemConnectionViewElementContextMenuBuilder( - ActionManager actionManager, SystemConnectionViewModel systemConnectionViewModel) { - super(actionManager); + ActionManager actionManager, SystemConnectionViewModel systemConnectionViewModel, GeckoView geckoView) { + super(actionManager, geckoView); this.systemConnectionViewModel = 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..ace005bc 100644 --- a/src/main/java/org/gecko/view/contextmenu/SystemViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/SystemViewElementContextMenuBuilder.java @@ -4,6 +4,7 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; import org.gecko.view.views.shortcuts.Shortcuts; import org.gecko.viewmodel.SystemViewModel; @@ -18,8 +19,8 @@ public class SystemViewElementContextMenuBuilder extends ViewContextMenuBuilder private final SystemViewModel systemViewModel; public SystemViewElementContextMenuBuilder( - ActionManager actionManager, SystemViewModel systemViewModel) { - super(actionManager); + ActionManager actionManager, SystemViewModel systemViewModel, GeckoView geckoView) { + super(actionManager, geckoView); this.systemViewModel = systemViewModel; } diff --git a/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java b/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java index c320a358..61e87fd4 100644 --- a/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/VariableBlockViewElementContextMenuBuilder.java @@ -4,6 +4,7 @@ import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import org.gecko.actions.ActionManager; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; import org.gecko.viewmodel.PortViewModel; @@ -17,8 +18,8 @@ public class VariableBlockViewElementContextMenuBuilder extends ViewContextMenuB private final PortViewModel portViewModel; public VariableBlockViewElementContextMenuBuilder( - ActionManager actionManager, PortViewModel portViewModel) { - super(actionManager); + ActionManager actionManager, PortViewModel portViewModel, GeckoView geckoView) { + super(actionManager, geckoView); this.portViewModel = 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..00f8f6b2 100644 --- a/src/main/java/org/gecko/view/contextmenu/ViewContextMenuBuilder.java +++ b/src/main/java/org/gecko/view/contextmenu/ViewContextMenuBuilder.java @@ -1,13 +1,16 @@ package org.gecko.view.contextmenu; import javafx.beans.binding.Bindings; +import javafx.geometry.Point2D; import javafx.scene.control.ContextMenu; import javafx.scene.control.MenuItem; import javafx.scene.control.SeparatorMenuItem; import lombok.Getter; import lombok.Setter; import org.gecko.actions.ActionManager; +import org.gecko.view.GeckoView; import org.gecko.view.ResourceHandler; +import org.gecko.view.views.EditorView; import org.gecko.view.views.shortcuts.Shortcuts; import org.gecko.viewmodel.EditorViewModel; @@ -22,15 +25,18 @@ public class ViewContextMenuBuilder { protected EditorViewModel editorViewModel; @Getter protected ContextMenu contextMenu; + private final EditorView editorView; - public ViewContextMenuBuilder(ActionManager actionManager) { + public ViewContextMenuBuilder(ActionManager actionManager, GeckoView geckoView) { this.actionManager = actionManager; this.editorViewModel = null; + this.editorView = geckoView.getCurrentView(); } - public ViewContextMenuBuilder(ActionManager actionManager, EditorViewModel editorViewModel) { + public ViewContextMenuBuilder(ActionManager actionManager, EditorViewModel editorViewModel, EditorView editorView) { this.actionManager = actionManager; this.editorViewModel = editorViewModel; + this.editorView = editorView; } public ContextMenu build() { @@ -62,8 +68,10 @@ public ContextMenu build() { } MenuItem pasteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "paste")); - pasteMenuItem.setOnAction( - e -> actionManager.run(actionManager.getActionFactory().createPastePositionableViewModelElementAction())); + pasteMenuItem.setOnAction(e -> { + Point2D center = editorView.getViewElementPane().screenCenterWorldCoords(); + actionManager.run(actionManager.getActionFactory().createPastePositionableViewModelElementAction(center)); + }); pasteMenuItem.setAccelerator(Shortcuts.PASTE.get()); SeparatorMenuItem separatorMenuItem = new SeparatorMenuItem(); diff --git a/src/main/java/org/gecko/view/menubar/MenuBarBuilder.java b/src/main/java/org/gecko/view/menubar/MenuBarBuilder.java index feff1a60..6a188c07 100644 --- a/src/main/java/org/gecko/view/menubar/MenuBarBuilder.java +++ b/src/main/java/org/gecko/view/menubar/MenuBarBuilder.java @@ -3,6 +3,7 @@ import java.io.File; import java.util.Set; import javafx.beans.binding.Bindings; +import javafx.geometry.Point2D; import javafx.scene.control.CustomMenuItem; import javafx.scene.control.Label; import javafx.scene.control.Menu; @@ -142,8 +143,10 @@ private Menu setupEditMenu() { copyMenuItem.setAccelerator(Shortcuts.COPY.get()); MenuItem pasteMenuItem = new MenuItem(ResourceHandler.getString("Buttons", "paste")); - pasteMenuItem.setOnAction( - e -> actionManager.run(actionManager.getActionFactory().createPastePositionableViewModelElementAction())); + pasteMenuItem.setOnAction(e -> { + Point2D center = view.getCurrentView().getViewElementPane().screenCenterWorldCoords(); + actionManager.run(actionManager.getActionFactory().createPastePositionableViewModelElementAction(center)); + }); pasteMenuItem.setAccelerator(Shortcuts.PASTE.get()); // General selection commands: diff --git a/src/main/java/org/gecko/view/views/EditorView.java b/src/main/java/org/gecko/view/views/EditorView.java index bacca8c5..d493ca7f 100644 --- a/src/main/java/org/gecko/view/views/EditorView.java +++ b/src/main/java/org/gecko/view/views/EditorView.java @@ -53,7 +53,7 @@ public class EditorView { private final InspectorFactory inspectorFactory; private final Inspector emptyInspector; private final Node searchWindow; - + @Getter private final ViewElementPane viewElementPane; @Getter @@ -86,8 +86,8 @@ public EditorView( StringProperty tabName = new SimpleStringProperty("Error_Name"); tabName.bind(Bindings.createStringBinding(() -> { String name = viewModel.getCurrentSystem().getName(); - return name + (viewModel.isAutomatonEditor() ? " (" + ResourceHandler.getString("View", "automaton") + ")" : - " (" + ResourceHandler.getString("View", "system") + ")"); + return name + (viewModel.isAutomatonEditor() ? " (" + ResourceHandler.getString("View", "automaton") + ")" + : " (" + ResourceHandler.getString("View", "system") + ")"); }, viewModel.getCurrentSystem().getNameProperty())); Label tabLabel = new Label(); @@ -129,7 +129,8 @@ public EditorView( // Set current tool viewModel.getCurrentToolProperty().addListener(this::onToolChanged); - ViewContextMenuBuilder contextMenuBuilder = new ViewContextMenuBuilder(viewModel.getActionManager(), viewModel); + ViewContextMenuBuilder contextMenuBuilder = + new ViewContextMenuBuilder(viewModel.getActionManager(), viewModel, this); this.contextMenu = contextMenuBuilder.build(); currentViewPane.setOnContextMenuRequested(event -> { changeContextMenu(contextMenuBuilder.getContextMenu()); diff --git a/src/main/java/org/gecko/view/views/ViewElementPane.java b/src/main/java/org/gecko/view/views/ViewElementPane.java index 00e92a48..ca2dbd7a 100644 --- a/src/main/java/org/gecko/view/views/ViewElementPane.java +++ b/src/main/java/org/gecko/view/views/ViewElementPane.java @@ -185,7 +185,7 @@ private Point2D localViewPortPosition() { return new Point2D(x, y); } - private Point2D screenCenterWorldCoords() { + public Point2D screenCenterWorldCoords() { //Can't use screenToLocal because we don't want the pane.localToScreen() offset Point2D screenCenter = new Point2D(pane.getViewportBounds().getWidth() / 2, pane.getViewportBounds().getHeight() / 2); diff --git a/src/main/java/org/gecko/view/views/ViewFactory.java b/src/main/java/org/gecko/view/views/ViewFactory.java index 78c169c8..d549cb36 100644 --- a/src/main/java/org/gecko/view/views/ViewFactory.java +++ b/src/main/java/org/gecko/view/views/ViewFactory.java @@ -52,7 +52,7 @@ public ViewElement createViewElementFrom(StateViewModel stateViewModel) { StateViewElement newStateViewElement = new StateViewElement(stateViewModel); ViewContextMenuBuilder contextMenuBuilder = - new StateViewElementContextMenuBuilder(actionManager, stateViewModel); + new StateViewElementContextMenuBuilder(actionManager, stateViewModel, geckoView); setContextMenu(newStateViewElement, contextMenuBuilder); return new SelectableViewElementDecorator(newStateViewElement); } @@ -61,7 +61,7 @@ public ViewElement createViewElementFrom(RegionViewModel regionViewModel) { RegionViewElement newRegionViewElement = new RegionViewElement(regionViewModel); ViewContextMenuBuilder contextMenuBuilder = - new RegionViewElementContextMenuBuilder(actionManager, regionViewModel); + new RegionViewElementContextMenuBuilder(actionManager, regionViewModel, geckoView); setContextMenu(newRegionViewElement, contextMenuBuilder); return new BlockElementScalerViewElementDecorator(new SelectableViewElementDecorator(newRegionViewElement)); } @@ -70,7 +70,7 @@ public ViewElement createViewElementFrom(PortViewModel portViewModel) { VariableBlockViewElement newVariableBlockViewElement = new VariableBlockViewElement(portViewModel); ViewContextMenuBuilder contextMenuBuilder = - new VariableBlockViewElementContextMenuBuilder(actionManager, portViewModel); + new VariableBlockViewElementContextMenuBuilder(actionManager, portViewModel, geckoView); setContextMenu(newVariableBlockViewElement, contextMenuBuilder); return new SelectableViewElementDecorator(newVariableBlockViewElement); @@ -79,7 +79,8 @@ public ViewElement createViewElementFrom(PortViewModel portViewModel) { public ViewElement createViewElementFrom(EdgeViewModel edgeViewModel) { EdgeViewElement newEdgeViewElement = new EdgeViewElement(edgeViewModel); - ViewContextMenuBuilder contextMenuBuilder = new EdgeViewElementContextMenuBuilder(actionManager, edgeViewModel); + ViewContextMenuBuilder contextMenuBuilder = + new EdgeViewElementContextMenuBuilder(actionManager, edgeViewModel, geckoView); setContextMenu(newEdgeViewElement, contextMenuBuilder); return new ConnectionElementScalerViewElementDecorator(newEdgeViewElement); @@ -90,7 +91,7 @@ public ViewElement createViewElementFrom(SystemConnectionViewModel systemConn new SystemConnectionViewElement(systemConnectionViewModel); ViewContextMenuBuilder contextMenuBuilder = - new SystemConnectionViewElementContextMenuBuilder(actionManager, systemConnectionViewModel); + new SystemConnectionViewElementContextMenuBuilder(actionManager, systemConnectionViewModel, geckoView); setContextMenu(newSystemConnectionViewElement, contextMenuBuilder); return new ConnectionElementScalerViewElementDecorator(newSystemConnectionViewElement); @@ -100,7 +101,7 @@ public ViewElement createViewElementFrom(SystemViewModel systemViewModel) { SystemViewElement newSystemViewElement = new SystemViewElement(systemViewModel); ViewContextMenuBuilder contextMenuBuilder = - new SystemViewElementContextMenuBuilder(actionManager, systemViewModel); + new SystemViewElementContextMenuBuilder(actionManager, systemViewModel, geckoView); setContextMenu(newSystemViewElement, contextMenuBuilder); return new SelectableViewElementDecorator(newSystemViewElement);