From 550851f8bc1dae0b900f9d6f4ffe2d117609f379 Mon Sep 17 00:00:00 2001 From: Simon Barner <barner@fortiss.org> Date: Sat, 23 Jan 2021 06:49:30 +0100 Subject: [PATCH] Add "Display" menu item to show/hide the grid Issue-Ref: 4097 Issue-Url: https://af3-developer.fortiss.org/issues/4097 Signed-off-by: Simon Barner <barner@fortiss.org> --- .../ui/javafx/lwfxef/controller/base/.ratings | 2 +- .../base/DefaultDiagramController.java | 37 ++++++++++++++++++- 2 files changed, 36 insertions(+), 3 deletions(-) diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/.ratings b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/.ratings index b24623e41..b6b4037a2 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/.ratings +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/.ratings @@ -2,7 +2,7 @@ AnchorageContentControllerBase.java da56b10cbf2711b5da69f0b59f43eacbe54f4eea GRE ClickControllerBase.java 8e5861ed5f9318008ad0fdd5497ed320cd5bd647 GREEN ContentAnchorageMoveControllerBase.java c18e7915ce23e124757f5b736086ecc46694800a GREEN ControllerBase.java 9311521b252e46640e26d409610e527fd5ed6922 GREEN -DefaultDiagramController.java 2d229228a05a96c54464575643bcb25e2e58efec YELLOW +DefaultDiagramController.java 1d162fc6789ad63081e81906a4ba649b5d459439 YELLOW DelegatingContentAnchorageController.java 1889628a346a2183082ffe213978f9d15a949494 GREEN DragControllerBase.java b15ff874304f679fe494d85f57cc8cbe4d0d1d15 GREEN DraggingUtils.java 95117e2ea4c36b6c6a31f8088bb95b484e0e6612 GREEN diff --git a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/DefaultDiagramController.java b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/DefaultDiagramController.java index 2d229228a..1d162fc67 100644 --- a/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/DefaultDiagramController.java +++ b/org.fortiss.tooling.common.ui/src/org/fortiss/tooling/common/ui/javafx/lwfxef/controller/base/DefaultDiagramController.java @@ -15,12 +15,14 @@ import java.util.List; import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramCoordinate; import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerFeatures; +import org.fortiss.tooling.common.ui.javafx.lwfxef.DiagramViewerFeatures.IndicatorType; import org.fortiss.tooling.common.ui.javafx.lwfxef.EDragGesture; import org.fortiss.tooling.common.ui.javafx.lwfxef.change.Change; import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IClickController; import org.fortiss.tooling.common.ui.javafx.lwfxef.controller.IDragController; import org.fortiss.tooling.common.ui.javafx.lwfxef.mvc.IMVCBundle; +import javafx.collections.ObservableList; import javafx.scene.Node; import javafx.scene.control.Menu; import javafx.scene.control.MenuItem; @@ -33,6 +35,9 @@ public class DefaultDiagramController extends ControllerBase { /** Flag for ignoring mouse click event after dragging gesture. */ private boolean ignoreNextMouseClick = false; + /** Previous grid indicator type (to restore grid after it has been hidden. */ + private IndicatorType previousGridIndicatorType = null; + /** Constructor. */ public DefaultDiagramController(IMVCBundle mvcb) { super(mvcb); @@ -72,14 +77,42 @@ public class DefaultDiagramController extends ControllerBase { return interactionAreaShadingMenuItem; } + /** + * Creates a {@link MenuItem} to hide/show the grid (returns {@code null} in case the diagram + * does not have a grid). + */ + private MenuItem createGridMenuItem(DiagramViewerFeatures features) { + MenuItem gridMenuItem = null; + if(features.getIndicatorType() == IndicatorType.INVISIBLE) { + if(previousGridIndicatorType != null) { + gridMenuItem = new MenuItem("Show Grid"); + gridMenuItem.setOnAction(evt -> { + features.setIndicatorType(previousGridIndicatorType); + }); + } + } else { + gridMenuItem = new MenuItem("Hide Grid"); + gridMenuItem.setOnAction(evt -> { + previousGridIndicatorType = features.getIndicatorType(); + features.setIndicatorType(IndicatorType.INVISIBLE); + }); + } + return gridMenuItem; + } + /** {@inheritDoc} */ @Override public List<MenuItem> contextMenuContributions(Node node, DiagramCoordinate diagramLocation) { Menu menu = new Menu("Display ..."); + ObservableList<MenuItem> menuItems = menu.getItems(); DiagramViewerFeatures features = getViewer().getFeatures(); - menu.getItems().add(createLinkHighlightingMenuItem(features)); - menu.getItems().add(createInteractionAreaShadingMenuItem(features)); + menuItems.add(createLinkHighlightingMenuItem(features)); + menuItems.add(createInteractionAreaShadingMenuItem(features)); + MenuItem gridMenuItem = createGridMenuItem(features); + if(gridMenuItem != null) { + menuItems.add(gridMenuItem); + } return asList(menu); } -- GitLab