sis-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From desruisse...@apache.org
Subject [sis] 03/04: Hide context menu when click happen outside.
Date Thu, 02 Jul 2020 16:52:24 GMT
This is an automated email from the ASF dual-hosted git repository.

desruisseaux pushed a commit to branch geoapi-4.0
in repository https://gitbox.apache.org/repos/asf/sis.git

commit d139a0b009ffe279750563b48a073ec2f6c62379
Author: Martin Desruisseaux <martin.desruisseaux@geomatys.com>
AuthorDate: Thu Jul 2 16:05:28 2020 +0200

    Hide context menu when click happen outside.
---
 .../main/java/org/apache/sis/gui/map/MapCanvas.java    | 18 ++++++++++++++++++
 1 file changed, 18 insertions(+)

diff --git a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
index 753f5a3..d60be6b 100644
--- a/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
+++ b/application/sis-javafx/src/main/java/org/apache/sis/gui/map/MapCanvas.java
@@ -275,6 +275,11 @@ public abstract class MapCanvas extends PlanarCanvas {
     private final ReadOnlyObjectWrapper<Throwable> error;
 
     /**
+     * If a contextual menu is currently visible, that menu. Otherwise {@code null}.
+     */
+    private ContextMenu menuShown;
+
+    /**
      * Creates a new canvas for JavaFX application.
      *
      * @param  locale  the locale to use for labels and some messages, or {@code null} for
default.
@@ -334,6 +339,7 @@ public abstract class MapCanvas extends PlanarCanvas {
         final double y = event.getY();
         final EventType<? extends MouseEvent> type = event.getEventType();
         if (type == MouseEvent.MOUSE_PRESSED && event.isPrimaryButtonDown()) {
+            hideContextMenu();
             floatingPane.setCursor(Cursor.CLOSED_HAND);
             floatingPane.requestFocus();
             isDragging = true;
@@ -514,6 +520,16 @@ public abstract class MapCanvas extends PlanarCanvas {
     }
 
     /**
+     * If a context menu is currently shown, hide that menu. Otherwise does nothing.
+     */
+    private void hideContextMenu() {
+        if (menuShown != null) {
+            menuShown.hide();
+            menuShown = null;
+        }
+    }
+
+    /**
      * Creates and register a contextual menu.
      *
      * @return the property for the selected value, or {@code null} if none.
@@ -587,10 +603,12 @@ public abstract class MapCanvas extends PlanarCanvas {
          */
         @Override
         public void handle(final MouseEvent event) {
+            hideContextMenu();
             if (event.isSecondaryButtonDown()) {
                 x = event.getX();
                 y = event.getY();
                 menu.show((Pane) event.getSource(), event.getScreenX(), event.getScreenY());
+                menuShown = menu;
                 event.consume();
             } else {
                 menu.hide();


Mime
View raw message