From cabb6b058c5f5438929faaef2e7808771bcf8a77 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Fri, 15 May 2020 20:33:53 +0200 Subject: [PATCH 01/13] WIP: Handling DPI scaling --- .../java/dk/cs/aau/huppaal/controllers/HUPPAALController.java | 4 ++++ 1 file changed, 4 insertions(+) diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java index cdc369f6..de619986 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java @@ -36,10 +36,12 @@ import javafx.scene.shape.Rectangle; import javafx.scene.text.Text; import javafx.stage.DirectoryChooser; +import javafx.stage.WindowEvent; import javafx.util.Duration; import javafx.util.Pair; import org.kordamp.ikonli.javafx.FontIcon; +import java.awt.event.WindowListener; import java.io.File; import java.io.IOException; import java.net.URL; @@ -231,6 +233,8 @@ public void onChanged(final Change c) { } }); + //root.getScene().getWindow().outputScaleXProperty().addListener(e -> { }); + initializeTabPane(); initializeStatusBar(); initializeMessages(); From bad2d90e0e4f06bc524616562a5462828757af0a Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Sun, 31 May 2020 12:59:17 +0200 Subject: [PATCH 02/13] =?UTF-8?q?WIP:=20ContextMenu=20contained=20inside?= =?UTF-8?q?=20screen=20bounds=C2=A8?= MIME-Version: 1.0 Content-Type: text/plain; charset=UTF-8 Content-Transfer-Encoding: 8bit --- .../controllers/ComponentController.java | 4 ++-- .../huppaal/controllers/EdgeController.java | 2 +- .../huppaal/controllers/JorkController.java | 8 +++---- .../controllers/LocationController.java | 2 +- .../huppaal/controllers/NailController.java | 6 +++--- .../controllers/ProjectPaneController.java | 2 +- .../controllers/SubComponentController.java | 2 +- .../huppaal/presentations/DropDownMenu.java | 21 +++++++++++++++++-- .../presentations/QueryPresentation.java | 2 +- 9 files changed, 33 insertions(+), 16 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java b/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java index 0e9a58d4..31c0f600 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java @@ -868,10 +868,10 @@ private void modelContainerPressed(final MouseEvent event) { DropDownMenu.y = event.getY(); if (unfinishedEdge == null) { - contextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + contextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); } else { initializeFinishEdgeContextMenu(unfinishedEdge); - finishEdgeContextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + finishEdgeContextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); } } else if(event.isPrimaryButtonDown()) { // We are drawing an edge diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java b/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java index a2f68bc1..747498ae 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java @@ -548,7 +548,7 @@ public void onChanged(final Change c) { }, "Deleted edge " + getEdge(), "delete"); }); - dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); + dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); DropDownMenu.x = CanvasPresentation.mouseTracker.getGridX(); DropDownMenu.y = CanvasPresentation.mouseTracker.getGridY(); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java b/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java index 8164af7f..18260844 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java @@ -99,7 +99,7 @@ private void initializeMouseControls() { unfinishedEdge.setTargetJork(getJork()); } else if (event.isSecondaryButtonDown()) { - showContextMenu(); + showContextMenu(event); } else if ((event.isShiftDown() && event.isPrimaryButtonDown()) || event.isMiddleButtonDown()) { final Edge newEdge = new Edge(getJork()); @@ -119,12 +119,12 @@ private void initializeMouseControls() { ItemDragHelper.makeDraggable(root, this::getDragBounds); } - private void showContextMenu() { + private void showContextMenu(final MouseEvent event) { final DropDownMenu contextMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent().getParent()), root, 230, true); contextMenu.addClickableListElement("Draw edge", - (event) -> { + (mouseEvent) -> { final Edge newEdge = new Edge(getJork()); KeyboardTracker.registerKeybind(KeyboardTracker.ABANDON_EDGE, new Keybind(new KeyCodeCombination(KeyCode.ESCAPE), () -> { @@ -164,7 +164,7 @@ private void showContextMenu() { contextMenu.close(); })); - contextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + contextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); } public Jork getJork() { diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java b/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java index 256d2298..81a861e6 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java @@ -373,7 +373,7 @@ private void initializeMouseControls() { if (unfinishedEdge == null && event.getButton().equals(MouseButton.SECONDARY)) { initializeDropDownMenu(); - dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 20, 20); + dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 20, 20); } else if (unfinishedEdge != null) { unfinishedEdge.setTargetLocation(getLocation()); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java b/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java index 248d9b91..6f732af0 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java @@ -71,7 +71,7 @@ public void initialize(final URL location, final ResourceBundle resources) { initializeMouseControls(); } - private void showContextMenu() { + private void showContextMenu(final MouseEvent event) { final DropDownMenu contextMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent().getParent()), root, 230, true); @@ -113,7 +113,7 @@ private void showContextMenu() { contextMenu.close(); })); - contextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0.5,0.5); + contextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0.5,0.5); } private void initializeMouseControls() { @@ -123,7 +123,7 @@ private void initializeMouseControls() { if (event.isShortcutDown()) { SelectHelper.addToSelection(this); } else if(event.isSecondaryButtonDown()) { - showContextMenu(); + showContextMenu(event); } else { SelectHelper.select(this); } diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java b/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java index a7df3b68..f285d861 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java @@ -153,7 +153,7 @@ private void initializeColorSelector(final FilePresentation filePresentation) { moreInformation.setOnMousePressed((e) -> { e.consume(); - moreInformationDropDown.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 10, 10); + moreInformationDropDown.show(e, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 10, 10); }); } diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java b/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java index 4a122ddf..12d53b86 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java @@ -296,7 +296,7 @@ private void makeDraggable() { }, "Created edge starting from subcomponent " + getSubComponent().getIdentifier(), "add-circle"); } else if (event.isSecondaryButtonDown() && unfinishedEdge == null) { initializeDropDownMenu(); - dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX() - 5, event.getY() - 5); + dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX() - 5, event.getY() - 5); } else if(event.isPrimaryButtonDown()) { // If the sub component is pressed twice open its corresponding component in the canvas if(event.getClickCount() > 1) { diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index 3e0f6c2e..ceb19a8a 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -1,5 +1,6 @@ package dk.cs.aau.huppaal.presentations; +import dk.cs.aau.huppaal.HUPPAAL; import dk.cs.aau.huppaal.utility.colors.Color; import dk.cs.aau.huppaal.utility.colors.EnabledColor; import com.jfoenix.controls.JFXPopup; @@ -17,6 +18,7 @@ import javafx.scene.layout.*; import javafx.scene.shape.Circle; import javafx.scene.shape.Line; +import javafx.stage.Screen; import javafx.util.Duration; import org.kordamp.ikonli.javafx.FontIcon; @@ -87,8 +89,23 @@ public void close() { popup.hide(); } - public void show(final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { - popup.show(this.source, vAlign, hAlign, initOffsetX, initOffsetY); + public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { + //Check if the dropdown will appear outside the screen and change the offset accordingly + double offsetX = initOffsetX; + double offsetY = initOffsetY; + double distEdgeX = Screen.getPrimary().getBounds().getWidth() - event.getScreenX(); + double distEdgeY = Screen.getPrimary().getBounds().getHeight() - event.getScreenY(); + + if(distEdgeX < width){ + offsetX -= width - distEdgeX; + } + + //400 is used, because the animation prevents the height from being accessed before it is already shown + if(distEdgeY < 400){ + offsetY -= 400 - distEdgeY; + } + + popup.show(this.source, vAlign, hAlign, offsetX, offsetY); } public void addListElement(final String s) { diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java b/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java index eb1ab182..921deda1 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java @@ -111,7 +111,7 @@ private void initializeDetailsButton() { detailsButton.getChildren().get(0).setOnMousePressed(event -> { // Show the popup - dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, -20, 35); + dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, -20, 35); }); } From 0cfb26310c88182644c5a0f50866eb248c3cb8aa Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Mon, 1 Jun 2020 09:36:39 +0200 Subject: [PATCH 03/13] WIP: Submenu overflow fix --- .../aau/huppaal/presentations/DropDownMenu.java | 15 +++++++++++++++ 1 file changed, 15 insertions(+) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index ceb19a8a..aadb8049 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -175,9 +175,24 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off subMenuContent.setTranslateY(offset); subMenuContent.setOpacity(0); + final Runnable showHideSubMenu = () -> { if (showSubMenu.get() || isHoveringSubMenu.get()) { subMenuContent.setOpacity(1); + + //Set the x-coordinate of the submenu to avoid screen overflow + if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ + subMenuContent.setTranslateX(- width + 35); + } else{ + subMenuContent.setTranslateX(width - 40); + } + + //Set the y-coordinate of the submenu to avoid screen overflow + final double height = subMenu.content.getHeight(); + if(Screen.getPrimary().getBounds().getHeight() - height < height){ + subMenuContent.setTranslateY((Screen.getPrimary().getBounds().getHeight() - height) - height); + } + } else { subMenuContent.setOpacity(0); } From f5ba787c6781b0c00d46ad77e458423051295fe1 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Mon, 1 Jun 2020 20:41:15 +0200 Subject: [PATCH 04/13] WIP: SubMenu overflow fix (flicker when co-ordinates are updated) --- .../huppaal/presentations/DropDownMenu.java | 18 +++++++++++------- 1 file changed, 11 insertions(+), 7 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index aadb8049..9a33c5c7 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -178,8 +178,6 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off final Runnable showHideSubMenu = () -> { if (showSubMenu.get() || isHoveringSubMenu.get()) { - subMenuContent.setOpacity(1); - //Set the x-coordinate of the submenu to avoid screen overflow if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ subMenuContent.setTranslateX(- width + 35); @@ -188,24 +186,30 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off } //Set the y-coordinate of the submenu to avoid screen overflow - final double height = subMenu.content.getHeight(); - if(Screen.getPrimary().getBounds().getHeight() - height < height){ - subMenuContent.setTranslateY((Screen.getPrimary().getBounds().getHeight() - height) - height); + final double height = subMenu.list.getHeight(); + final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - list.localToScreen(list.getLayoutBounds()).getMinY(); + + if(distToEdgeY < height + 10){ + subMenuContent.setTranslateY(distToEdgeY - (height + 10)); + } else { + subMenuContent.setTranslateY(offset); } + subMenuContent.setOpacity(1); } else { subMenuContent.setOpacity(0); } }; - showSubMenu.addListener((obs, oldShow, newShow) -> showHideSubMenu.run()); - isHoveringSubMenu.addListener((obs, oldHovering, newHovering) -> showHideSubMenu.run()); + showSubMenu.addListener((obs) -> showHideSubMenu.run()); + isHoveringSubMenu.addListener((obs) -> showHideSubMenu.run()); subMenuContent.setOnMouseEntered(event -> { if (canIShowSubMenu.get()) { isHoveringSubMenu.set(true); } }); + subMenuContent.setOnMouseExited(event -> { isHoveringSubMenu.set(false); }); From 0c6eba7939e63abdea26f43f28ee114deca80386 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Thu, 4 Jun 2020 19:20:43 +0200 Subject: [PATCH 05/13] Better handling of submenu placement --- .../dk/cs/aau/huppaal/presentations/DropDownMenu.java | 8 +++++--- 1 file changed, 5 insertions(+), 3 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index 9a33c5c7..814fed90 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -187,10 +187,12 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off //Set the y-coordinate of the submenu to avoid screen overflow final double height = subMenu.list.getHeight(); - final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - list.localToScreen(list.getLayoutBounds()).getMinY(); + final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - list.localToScreen(list.getLayoutBounds()).getMaxY(); + HUPPAAL.showToast((distToEdgeY) + " " + (height)); - if(distToEdgeY < height + 10){ - subMenuContent.setTranslateY(distToEdgeY - (height + 10)); + //height/2 makes the submenu edge the bottom of the screen, the + 20 raises it + if(distToEdgeY < height/2 - 20){ + subMenuContent.setTranslateY(distToEdgeY - height/2 - 20); } else { subMenuContent.setTranslateY(offset); } From d6731415e71c8600fd0c4698084c500c97028f78 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Thu, 4 Jun 2020 20:31:55 +0200 Subject: [PATCH 06/13] Dropdown show method clean up and wrong initial position fixed --- .../controllers/ComponentController.java | 10 ++++---- .../huppaal/controllers/EdgeController.java | 5 ++-- .../huppaal/controllers/JorkController.java | 3 +-- .../controllers/LocationController.java | 3 +-- .../huppaal/controllers/NailController.java | 3 +-- .../controllers/ProjectPaneController.java | 2 +- .../controllers/SubComponentController.java | 4 +-- .../huppaal/presentations/DropDownMenu.java | 25 +++++++++++-------- .../presentations/QueryPresentation.java | 2 +- 9 files changed, 29 insertions(+), 28 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java b/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java index 31c0f600..a78118ee 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java @@ -391,7 +391,7 @@ private void initializeComponentContextMenu() { return; } - contextMenu = new DropDownMenu(root, dropDownMenuHelperCircle, 230, true); + contextMenu = new DropDownMenu(dropDownMenuHelperCircle, 230, true); contextMenu.addClickableListElement("Add Location", event -> { contextMenu.close(); @@ -463,7 +463,7 @@ private void initializeComponentContextMenu() { //If-statement added to avoid empty submenu being added and appearing as a white box if(HUPPAAL.getProject().getComponents().size() > 1){ - subMenu = new DropDownMenu(root, dropDownMenuHelperCircle, 150, false); + subMenu = new DropDownMenu(dropDownMenuHelperCircle, 150, false); HUPPAAL.getProject().getComponents().forEach(c -> { if (!c.equals(component)) { subMenu.addClickableListElement(c.getName(), event -> { @@ -490,7 +490,7 @@ private void initializeComponentContextMenu() { }); } else { - subMenu = new DropDownMenu(root, dropDownMenuHelperCircle, 150, false); + subMenu = new DropDownMenu(dropDownMenuHelperCircle, 150, false); subMenu.addClickableAndDisableableListElement("No Subcomponents", new SimpleBooleanProperty(true), event -> {}); } @@ -556,7 +556,7 @@ private void initializeFinishEdgeContextMenu(final Edge unfinishedEdge) { locationAware.yProperty().set(y); }; - finishEdgeContextMenu = new DropDownMenu(root, dropDownMenuHelperCircle, 230, true); + finishEdgeContextMenu = new DropDownMenu(dropDownMenuHelperCircle, 230, true); finishEdgeContextMenu.addListElement("Finish edge in a:"); @@ -620,7 +620,7 @@ private void initializeFinishEdgeContextMenu(final Edge unfinishedEdge) { }, "Finished edge '" + unfinishedEdge + "' by adding '" + jork + "' to component '" + component.getName() + "'", "add-circle"); }); - final DropDownMenu subMenu = new DropDownMenu(root, dropDownMenuHelperCircle, 150, false); + final DropDownMenu subMenu = new DropDownMenu(dropDownMenuHelperCircle, 150, false); HUPPAAL.getProject().getComponents().forEach(c -> { if (!c.equals(component)) { subMenu.addClickableListElement(c.getName(), event -> { diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java b/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java index 747498ae..abde31b1 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java @@ -31,7 +31,6 @@ import javafx.scene.Group; import javafx.scene.Node; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Pane; import javafx.scene.shape.Circle; import javafx.util.Duration; @@ -515,7 +514,7 @@ public void onChanged(final Change c) { if (event.isSecondaryButtonDown() && getComponent().getUnfinishedEdge() == null) { event.consume(); - final DropDownMenu dropDownMenu = new DropDownMenu(((Pane) edgeRoot.getParent().getParent().getParent().getParent()), dropDownMenuHelperCircle, 230, true); + final DropDownMenu dropDownMenu = new DropDownMenu(dropDownMenuHelperCircle, 230, true); addEdgePropertyRow(dropDownMenu, "Add Select", Edge.PropertyType.SELECTION, link); addEdgePropertyRow(dropDownMenu, "Add Guard", Edge.PropertyType.GUARD, link); @@ -548,7 +547,7 @@ public void onChanged(final Change c) { }, "Deleted edge " + getEdge(), "delete"); }); - dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); + dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); DropDownMenu.x = CanvasPresentation.mouseTracker.getGridX(); DropDownMenu.y = CanvasPresentation.mouseTracker.getGridY(); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java b/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java index 18260844..b66674fc 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java @@ -27,7 +27,6 @@ import javafx.scene.input.KeyCode; import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Pane; import javafx.scene.shape.Path; import java.net.URL; @@ -121,7 +120,7 @@ private void initializeMouseControls() { private void showContextMenu(final MouseEvent event) { - final DropDownMenu contextMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent().getParent()), root, 230, true); + final DropDownMenu contextMenu = new DropDownMenu(root, 230, true); contextMenu.addClickableListElement("Draw edge", (mouseEvent) -> { diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java b/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java index 81a861e6..7dbec013 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java @@ -30,7 +30,6 @@ import javafx.scene.input.KeyCodeCombination; import javafx.scene.input.MouseButton; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Pane; import javafx.scene.layout.StackPane; import javafx.scene.shape.Circle; import javafx.scene.shape.Line; @@ -114,7 +113,7 @@ public void initializeDropDownMenu() { if (dropDownMenuInitialized) return; dropDownMenuInitialized = true; - dropDownMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent()), root, 230, true); + dropDownMenu = new DropDownMenu(root, 230, true); dropDownMenu.addClickableListElement("Draw edge", (event) -> { diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java b/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java index 6f732af0..676ffe33 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java @@ -24,7 +24,6 @@ import javafx.scene.Group; import javafx.scene.control.Label; import javafx.scene.input.MouseEvent; -import javafx.scene.layout.Pane; import javafx.scene.shape.Circle; import javafx.scene.shape.Line; @@ -73,7 +72,7 @@ public void initialize(final URL location, final ResourceBundle resources) { private void showContextMenu(final MouseEvent event) { - final DropDownMenu contextMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent().getParent()), root, 230, true); + final DropDownMenu contextMenu = new DropDownMenu(root, 230, true); contextMenu.addClickableListElement("Delete", (mouseEvent -> { final Nail nail = getNail(); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java b/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java index f285d861..8764f699 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java @@ -74,7 +74,7 @@ private void sortPresentations() { private void initializeColorSelector(final FilePresentation filePresentation) { final JFXRippler moreInformation = (JFXRippler) filePresentation.lookup("#moreInformation"); final int listWidth = 230; - final DropDownMenu moreInformationDropDown = new DropDownMenu(root, moreInformation, listWidth, true); + final DropDownMenu moreInformationDropDown = new DropDownMenu(moreInformation, listWidth, true); final Component component = filePresentation.getComponent(); moreInformationDropDown.addListElement("Configuration"); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java b/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java index 12d53b86..10041de9 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java @@ -78,7 +78,7 @@ private void initializeDropDownMenu() { if (dropDownMenuInitialized) return; dropDownMenuInitialized = true; - dropDownMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent()), root, 230, true); + dropDownMenu = new DropDownMenu(root, 230, true); dropDownMenu.addClickableListElement("Open in canvas", event -> { CanvasController.setActiveComponent(getSubComponent().getComponent()); @@ -106,7 +106,7 @@ private void initializeDropDownMenu() { dropDownMenu.addSpacerElement(); - final DropDownMenu subMenu = new DropDownMenu(((Pane) root.getParent().getParent().getParent()), root, 150, false); + final DropDownMenu subMenu = new DropDownMenu(root, 150, false); HUPPAAL.getProject().getComponents().forEach(c -> { if (!c.equals(getParentComponent())) { subMenu.addClickableListElement(c.getName(), event -> { diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index 814fed90..a5203303 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -1,6 +1,5 @@ package dk.cs.aau.huppaal.presentations; -import dk.cs.aau.huppaal.HUPPAAL; import dk.cs.aau.huppaal.utility.colors.Color; import dk.cs.aau.huppaal.utility.colors.EnabledColor; import com.jfoenix.controls.JFXPopup; @@ -45,7 +44,7 @@ public class DropDownMenu { private StackPane subMenuContent; private final Node source; - public DropDownMenu(final Pane container, final Node source, final int width, final boolean closeOnMouseExit) { + public DropDownMenu(final Node source, final int width, final boolean closeOnMouseExit) { this.width = width; this.source = source; @@ -90,19 +89,21 @@ public void close() { } public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { + //Needed to update the location of the popup before it is displayed + this.flashDropdown(); + //Check if the dropdown will appear outside the screen and change the offset accordingly double offsetX = initOffsetX; double offsetY = initOffsetY; - double distEdgeX = Screen.getPrimary().getBounds().getWidth() - event.getScreenX(); - double distEdgeY = Screen.getPrimary().getBounds().getHeight() - event.getScreenY(); + double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (event.getScreenX() + offsetX); + double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (event.getScreenY() + offsetY); - if(distEdgeX < width){ - offsetX -= width - distEdgeX; + if(distEdgeX < width + 20){ + offsetX -= (width + 20) - distEdgeX; } - //400 is used, because the animation prevents the height from being accessed before it is already shown - if(distEdgeY < 400){ - offsetY -= 400 - distEdgeY; + if(distEdgeY < list.getHeight() + 20){ + offsetY -= (list.getHeight() + 20) - distEdgeY; } popup.show(this.source, vAlign, hAlign, offsetX, offsetY); @@ -188,7 +189,6 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off //Set the y-coordinate of the submenu to avoid screen overflow final double height = subMenu.list.getHeight(); final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - list.localToScreen(list.getLayoutBounds()).getMaxY(); - HUPPAAL.showToast((distToEdgeY) + " " + (height)); //height/2 makes the submenu edge the bottom of the screen, the + 20 raises it if(distToEdgeY < height/2 - 20){ @@ -456,4 +456,9 @@ public interface HasColor { ObjectProperty colorIntensityProperty(); } + + private void flashDropdown() { + popup.show(this.source, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + this.close(); + } } diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java b/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java index 921deda1..4d8c6667 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java @@ -82,7 +82,7 @@ private void initializeDetailsButton() { detailsButton.setRipplerFill(Color.GREY.getColor(Color.Intensity.I500)); detailsButton.setMaskType(JFXRippler.RipplerMask.CIRCLE); - final DropDownMenu dropDownMenu = new DropDownMenu((Pane) getParent(), detailsButton, 230, true); + final DropDownMenu dropDownMenu = new DropDownMenu(detailsButton, 230, true); dropDownMenu.addTogglableListElement("Run periodically", query.isPeriodicProperty(), event -> { // Toggle the property From f0cac3ec6f5bbcc181154c5fc72d253815a3e274 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Tue, 9 Jun 2020 19:24:28 +0200 Subject: [PATCH 07/13] Moved the flashDropdown call further down to account for updated values (does not seem to change anything) --- .../java/dk/cs/aau/huppaal/presentations/DropDownMenu.java | 6 +++--- 1 file changed, 3 insertions(+), 3 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index a5203303..45ec4082 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -89,9 +89,6 @@ public void close() { } public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { - //Needed to update the location of the popup before it is displayed - this.flashDropdown(); - //Check if the dropdown will appear outside the screen and change the offset accordingly double offsetX = initOffsetX; double offsetY = initOffsetY; @@ -106,6 +103,9 @@ public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, f offsetY -= (list.getHeight() + 20) - distEdgeY; } + //Needed to update the location of the popup before it is displayed + this.flashDropdown(); + popup.show(this.source, vAlign, hAlign, offsetX, offsetY); } From 718a4a5a1f606d3124b24db6be8bad7596168318 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Tue, 9 Jun 2020 20:51:42 +0200 Subject: [PATCH 08/13] WIP: Scrollable submenu (SubMenuContent changed to ScrollPane) --- .../huppaal/presentations/DropDownMenu.java | 33 +++++++++++-------- 1 file changed, 20 insertions(+), 13 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index 45ec4082..d112adc2 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -13,6 +13,7 @@ import javafx.geometry.Pos; import javafx.scene.Node; import javafx.scene.control.Label; +import javafx.scene.control.ScrollPane; import javafx.scene.input.MouseEvent; import javafx.scene.layout.*; import javafx.scene.shape.Circle; @@ -41,7 +42,7 @@ public class DropDownMenu { private final SimpleBooleanProperty isHoveringMenu = new SimpleBooleanProperty(false); private final SimpleBooleanProperty showSubMenu = new SimpleBooleanProperty(false); private final SimpleBooleanProperty canIShowSubMenu = new SimpleBooleanProperty(false); - private StackPane subMenuContent; + private ScrollPane subMenuContent; private final Node source; public DropDownMenu(final Node source, final int width, final boolean closeOnMouseExit) { @@ -164,16 +165,22 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off label.getStyleClass().add("body2"); label.setMinWidth(width); - subMenuContent = subMenu.content; + subMenuContent = new ScrollPane(subMenu.content.getChildren().get(0)); + subMenuContent.setMinHeight(400); + subMenuContent.setMinWidth(width); + subMenuContent.setFitToWidth(true); + subMenuContent.setFitToHeight(true); + subMenuContent.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); + subMenuContent.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); if (!this.content.getChildren().contains(subMenuContent)) { - subMenuContent.setStyle("-fx-padding: 0 0 0 5;"); + subMenuContent.setStyle("-fx-padding: 0 0 0 0;"); subMenuContent.setMinWidth(subMenuContent.getMinWidth() + 1); subMenuContent.setMaxWidth(subMenuContent.getMinWidth() + 1); - subMenuContent.setTranslateX(width - 40); + subMenuContent.setTranslateX(width + 5); this.content.getChildren().add(subMenuContent); } - subMenuContent.setTranslateY(offset); + subMenuContent.setTranslateY(offset + subMenuContent.getHeight()/2); subMenuContent.setOpacity(0); @@ -181,20 +188,20 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off if (showSubMenu.get() || isHoveringSubMenu.get()) { //Set the x-coordinate of the submenu to avoid screen overflow if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ - subMenuContent.setTranslateX(- width + 35); + subMenuContent.setTranslateX(- width); } else{ - subMenuContent.setTranslateX(width - 40); + subMenuContent.setTranslateX(width); } //Set the y-coordinate of the submenu to avoid screen overflow - final double height = subMenu.list.getHeight(); - final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - list.localToScreen(list.getLayoutBounds()).getMaxY(); + final double height = subMenuContent.getMaxHeight(); + final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - subMenuContent.localToScreen(subMenuContent.getLayoutBounds()).getMaxY(); - //height/2 makes the submenu edge the bottom of the screen, the + 20 raises it - if(distToEdgeY < height/2 - 20){ - subMenuContent.setTranslateY(distToEdgeY - height/2 - 20); + //height/2 makes the submenu edge the bottom of the screen, the + 5 raises it + if(distToEdgeY < (height/2 + 5)){ + subMenuContent.setTranslateY(distToEdgeY - (height/2 + 5)); } else { - subMenuContent.setTranslateY(offset); + subMenuContent.setTranslateY(offset + subMenuContent.getHeight()/2); } subMenuContent.setOpacity(1); From 4174a125a96ec2dbee4278334c8ef99ee779ec52 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Sat, 13 Jun 2020 14:20:38 +0200 Subject: [PATCH 09/13] SubMenu flicker issue fixed --- .../huppaal/presentations/DropDownMenu.java | 36 +++++++------------ 1 file changed, 12 insertions(+), 24 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index d112adc2..c7c27152 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -90,12 +90,16 @@ public void close() { } public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { + //Needed to update the location of the popup before it is displayed + this.flashDropdown(); + //Check if the dropdown will appear outside the screen and change the offset accordingly double offsetX = initOffsetX; double offsetY = initOffsetY; double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (event.getScreenX() + offsetX); double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (event.getScreenY() + offsetY); + //The additional 20 is added for margin if(distEdgeX < width + 20){ offsetX -= (width + 20) - distEdgeX; } @@ -104,8 +108,12 @@ public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, f offsetY -= (list.getHeight() + 20) - distEdgeY; } - //Needed to update the location of the popup before it is displayed - this.flashDropdown(); + //Set the x-coordinate of the submenu to avoid screen overflow + if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ + subMenuContent.setTranslateX(- width); + } else{ + subMenuContent.setTranslateX(width); + } popup.show(this.source, vAlign, hAlign, offsetX, offsetY); } @@ -166,44 +174,24 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off label.setMinWidth(width); subMenuContent = new ScrollPane(subMenu.content.getChildren().get(0)); - subMenuContent.setMinHeight(400); + subMenuContent.setMinHeight(340 - offset); subMenuContent.setMinWidth(width); subMenuContent.setFitToWidth(true); subMenuContent.setFitToHeight(true); subMenuContent.setHbarPolicy(ScrollPane.ScrollBarPolicy.NEVER); subMenuContent.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); + subMenuContent.setTranslateY(offset + subMenuContent.getMinHeight()/2); if (!this.content.getChildren().contains(subMenuContent)) { subMenuContent.setStyle("-fx-padding: 0 0 0 0;"); subMenuContent.setMinWidth(subMenuContent.getMinWidth() + 1); subMenuContent.setMaxWidth(subMenuContent.getMinWidth() + 1); - subMenuContent.setTranslateX(width + 5); this.content.getChildren().add(subMenuContent); } - subMenuContent.setTranslateY(offset + subMenuContent.getHeight()/2); - subMenuContent.setOpacity(0); final Runnable showHideSubMenu = () -> { if (showSubMenu.get() || isHoveringSubMenu.get()) { - //Set the x-coordinate of the submenu to avoid screen overflow - if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ - subMenuContent.setTranslateX(- width); - } else{ - subMenuContent.setTranslateX(width); - } - - //Set the y-coordinate of the submenu to avoid screen overflow - final double height = subMenuContent.getMaxHeight(); - final double distToEdgeY = Screen.getPrimary().getBounds().getHeight() - subMenuContent.localToScreen(subMenuContent.getLayoutBounds()).getMaxY(); - - //height/2 makes the submenu edge the bottom of the screen, the + 5 raises it - if(distToEdgeY < (height/2 + 5)){ - subMenuContent.setTranslateY(distToEdgeY - (height/2 + 5)); - } else { - subMenuContent.setTranslateY(offset + subMenuContent.getHeight()/2); - } - subMenuContent.setOpacity(1); } else { subMenuContent.setOpacity(0); From a6348b6f1c94c1e7f028cc1de8cdcb6963214701 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Sun, 14 Jun 2020 11:13:40 +0200 Subject: [PATCH 10/13] Unneeded padding removed --- src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java | 1 - 1 file changed, 1 deletion(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index c7c27152..82358235 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -182,7 +182,6 @@ public void addSubMenu(final String s, final DropDownMenu subMenu, final int off subMenuContent.setVbarPolicy(ScrollPane.ScrollBarPolicy.AS_NEEDED); subMenuContent.setTranslateY(offset + subMenuContent.getMinHeight()/2); if (!this.content.getChildren().contains(subMenuContent)) { - subMenuContent.setStyle("-fx-padding: 0 0 0 0;"); subMenuContent.setMinWidth(subMenuContent.getMinWidth() + 1); subMenuContent.setMaxWidth(subMenuContent.getMinWidth() + 1); this.content.getChildren().add(subMenuContent); From 9ca3bd610387af999a89540314a613beed34e4a8 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Sun, 14 Jun 2020 11:18:31 +0200 Subject: [PATCH 11/13] Empty event removed --- .../java/dk/cs/aau/huppaal/controllers/HUPPAALController.java | 2 -- 1 file changed, 2 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java index de619986..32ef2948 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/HUPPAALController.java @@ -233,8 +233,6 @@ public void onChanged(final Change c) { } }); - //root.getScene().getWindow().outputScaleXProperty().addListener(e -> { }); - initializeTabPane(); initializeStatusBar(); initializeMessages(); From aa86ab08991592703b9172c441d5de8b3b365ec5 Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Sun, 14 Jun 2020 13:43:44 +0200 Subject: [PATCH 12/13] ContextMenu for edges and locations fixed --- .../controllers/ComponentController.java | 4 ++-- .../huppaal/controllers/EdgeController.java | 7 +++---- .../huppaal/controllers/JorkController.java | 8 ++++---- .../controllers/LocationController.java | 2 +- .../huppaal/controllers/NailController.java | 6 +++--- .../controllers/ProjectPaneController.java | 2 +- .../controllers/SubComponentController.java | 2 +- .../huppaal/presentations/DropDownMenu.java | 19 +++++++++++-------- .../presentations/QueryPresentation.java | 2 +- 9 files changed, 27 insertions(+), 25 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java b/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java index a78118ee..5aa3af41 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/ComponentController.java @@ -868,10 +868,10 @@ private void modelContainerPressed(final MouseEvent event) { DropDownMenu.y = event.getY(); if (unfinishedEdge == null) { - contextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + contextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); } else { initializeFinishEdgeContextMenu(unfinishedEdge); - finishEdgeContextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + finishEdgeContextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); } } else if(event.isPrimaryButtonDown()) { // We are drawing an edge diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java b/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java index abde31b1..04193877 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/EdgeController.java @@ -1,5 +1,6 @@ package dk.cs.aau.huppaal.controllers; +import dk.cs.aau.huppaal.HUPPAAL; import dk.cs.aau.huppaal.abstractions.*; import dk.cs.aau.huppaal.code_analysis.CodeAnalysis; import dk.cs.aau.huppaal.code_analysis.Nearable; @@ -512,9 +513,7 @@ public void onChanged(final Change c) { links.forEach((link) -> link.setOnMousePressed(event -> { if (event.isSecondaryButtonDown() && getComponent().getUnfinishedEdge() == null) { - event.consume(); - - final DropDownMenu dropDownMenu = new DropDownMenu(dropDownMenuHelperCircle, 230, true); + final DropDownMenu dropDownMenu = new DropDownMenu(edgeRoot, 230, true); addEdgePropertyRow(dropDownMenu, "Add Select", Edge.PropertyType.SELECTION, link); addEdgePropertyRow(dropDownMenu, "Add Guard", Edge.PropertyType.GUARD, link); @@ -547,7 +546,7 @@ public void onChanged(final Change c) { }, "Deleted edge " + getEdge(), "delete"); }); - dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX(), event.getY()); DropDownMenu.x = CanvasPresentation.mouseTracker.getGridX(); DropDownMenu.y = CanvasPresentation.mouseTracker.getGridY(); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java b/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java index b66674fc..e2fa01c8 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/JorkController.java @@ -98,7 +98,7 @@ private void initializeMouseControls() { unfinishedEdge.setTargetJork(getJork()); } else if (event.isSecondaryButtonDown()) { - showContextMenu(event); + showContextMenu(); } else if ((event.isShiftDown() && event.isPrimaryButtonDown()) || event.isMiddleButtonDown()) { final Edge newEdge = new Edge(getJork()); @@ -118,7 +118,7 @@ private void initializeMouseControls() { ItemDragHelper.makeDraggable(root, this::getDragBounds); } - private void showContextMenu(final MouseEvent event) { + private void showContextMenu() { final DropDownMenu contextMenu = new DropDownMenu(root, 230, true); @@ -143,7 +143,7 @@ private void showContextMenu(final MouseEvent event) { contextMenu.addSpacerElement(); - contextMenu.addClickableListElement("Delete", (mouseEvent -> { + contextMenu.addClickableListElement("Delete", (event -> { final Component component = CanvasController.getActiveComponent(); final Jork jork = getJork(); @@ -163,7 +163,7 @@ private void showContextMenu(final MouseEvent event) { contextMenu.close(); })); - contextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); + contextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0, 0); } public Jork getJork() { diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java b/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java index 7dbec013..af182d75 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/LocationController.java @@ -372,7 +372,7 @@ private void initializeMouseControls() { if (unfinishedEdge == null && event.getButton().equals(MouseButton.SECONDARY)) { initializeDropDownMenu(); - dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 20, 20); + dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 20, 20); } else if (unfinishedEdge != null) { unfinishedEdge.setTargetLocation(getLocation()); diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java b/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java index 676ffe33..c8db7150 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/NailController.java @@ -70,7 +70,7 @@ public void initialize(final URL location, final ResourceBundle resources) { initializeMouseControls(); } - private void showContextMenu(final MouseEvent event) { + private void showContextMenu() { final DropDownMenu contextMenu = new DropDownMenu(root, 230, true); @@ -112,7 +112,7 @@ private void showContextMenu(final MouseEvent event) { contextMenu.close(); })); - contextMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0.5,0.5); + contextMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 0.5,0.5); } private void initializeMouseControls() { @@ -122,7 +122,7 @@ private void initializeMouseControls() { if (event.isShortcutDown()) { SelectHelper.addToSelection(this); } else if(event.isSecondaryButtonDown()) { - showContextMenu(event); + showContextMenu(); } else { SelectHelper.select(this); } diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java b/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java index 8764f699..ca753e0b 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/ProjectPaneController.java @@ -153,7 +153,7 @@ private void initializeColorSelector(final FilePresentation filePresentation) { moreInformation.setOnMousePressed((e) -> { e.consume(); - moreInformationDropDown.show(e, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 10, 10); + moreInformationDropDown.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, 10, 10); }); } diff --git a/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java b/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java index 10041de9..452951f8 100644 --- a/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java +++ b/src/main/java/dk/cs/aau/huppaal/controllers/SubComponentController.java @@ -296,7 +296,7 @@ private void makeDraggable() { }, "Created edge starting from subcomponent " + getSubComponent().getIdentifier(), "add-circle"); } else if (event.isSecondaryButtonDown() && unfinishedEdge == null) { initializeDropDownMenu(); - dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX() - 5, event.getY() - 5); + dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.LEFT, event.getX() - 5, event.getY() - 5); } else if(event.isPrimaryButtonDown()) { // If the sub component is pressed twice open its corresponding component in the canvas if(event.getClickCount() > 1) { diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index 82358235..610fd81e 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -1,5 +1,6 @@ package dk.cs.aau.huppaal.presentations; +import dk.cs.aau.huppaal.HUPPAAL; import dk.cs.aau.huppaal.utility.colors.Color; import dk.cs.aau.huppaal.utility.colors.EnabledColor; import com.jfoenix.controls.JFXPopup; @@ -89,15 +90,15 @@ public void close() { popup.hide(); } - public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { + public void show(final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosition hAlign, final double initOffsetX, final double initOffsetY) { //Needed to update the location of the popup before it is displayed this.flashDropdown(); //Check if the dropdown will appear outside the screen and change the offset accordingly double offsetX = initOffsetX; double offsetY = initOffsetY; - double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (event.getScreenX() + offsetX); - double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (event.getScreenY() + offsetY); + double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (popup.getX() + offsetX + 20); + double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (popup.getY() + offsetY + 20); //The additional 20 is added for margin if(distEdgeX < width + 20){ @@ -108,11 +109,13 @@ public void show(final MouseEvent event, final JFXPopup.PopupVPosition vAlign, f offsetY -= (list.getHeight() + 20) - distEdgeY; } - //Set the x-coordinate of the submenu to avoid screen overflow - if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ - subMenuContent.setTranslateX(- width); - } else{ - subMenuContent.setTranslateX(width); + //Set the x-coordinate of the potential submenu to avoid screen overflow + if(subMenuContent != null){ + if(Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + width) < width){ + subMenuContent.setTranslateX(- width); + } else{ + subMenuContent.setTranslateX(width); + } } popup.show(this.source, vAlign, hAlign, offsetX, offsetY); diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java b/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java index 4d8c6667..058d78aa 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/QueryPresentation.java @@ -111,7 +111,7 @@ private void initializeDetailsButton() { detailsButton.getChildren().get(0).setOnMousePressed(event -> { // Show the popup - dropDownMenu.show(event, JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, -20, 35); + dropDownMenu.show(JFXPopup.PopupVPosition.TOP, JFXPopup.PopupHPosition.RIGHT, -20, 35); }); } From 058c5df6b886159b091c0f1e6e18d3cfc35b575d Mon Sep 17 00:00:00 2001 From: Niels Vistisen Date: Sun, 14 Jun 2020 13:54:07 +0200 Subject: [PATCH 13/13] Final adjustments to offset around screen edges --- .../java/dk/cs/aau/huppaal/presentations/DropDownMenu.java | 4 ++-- 1 file changed, 2 insertions(+), 2 deletions(-) diff --git a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java index 610fd81e..cc5987b1 100644 --- a/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java +++ b/src/main/java/dk/cs/aau/huppaal/presentations/DropDownMenu.java @@ -97,8 +97,8 @@ public void show(final JFXPopup.PopupVPosition vAlign, final JFXPopup.PopupHPosi //Check if the dropdown will appear outside the screen and change the offset accordingly double offsetX = initOffsetX; double offsetY = initOffsetY; - double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (popup.getX() + offsetX + 20); - double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (popup.getY() + offsetY + 20); + double distEdgeX = Screen.getPrimary().getBounds().getWidth() - (popup.getAnchorX() + offsetX); + double distEdgeY = Screen.getPrimary().getBounds().getHeight() - (popup.getAnchorY() + offsetY); //The additional 20 is added for margin if(distEdgeX < width + 20){