changeset 5881:2698d86919d4

RT-34610: SwingNode: Ending a drag gesture should not generate an AWT mouse clicked event Summary: Skip unwanted MOUSE_CLICKED events Reviewed-by: ant, snorthov
author Anthony Petrov <anthony.petrov@oracle.com>
date Tue, 03 Dec 2013 16:43:23 +0400
parents 5da49a57a37f
children 4e5dd280c928
files modules/swing/src/main/java/javafx/embed/swing/SwingNode.java
diffstat 1 files changed, 22 insertions(+), 0 deletions(-) [+]
line wrap: on
line diff
--- a/modules/swing/src/main/java/javafx/embed/swing/SwingNode.java	Tue Dec 03 12:38:49 2013 +0200
+++ b/modules/swing/src/main/java/javafx/embed/swing/SwingNode.java	Tue Dec 03 16:43:23 2013 +0400
@@ -30,6 +30,7 @@
 import javafx.beans.value.ChangeListener;
 import javafx.beans.value.ObservableValue;
 import javafx.event.EventHandler;
+import javafx.event.EventType;
 import javafx.geometry.Point2D;
 import javafx.scene.Node;
 import javafx.scene.Scene;
@@ -53,7 +54,9 @@
 import java.security.AccessController;
 import java.security.PrivilegedAction;
 import java.util.ArrayList;
+import java.util.HashSet;
 import java.util.List;
+import java.util.Set;
 import java.util.concurrent.locks.ReentrantLock;
 import com.sun.javafx.geom.BaseBounds;
 import com.sun.javafx.geom.transform.BaseTransform;
@@ -723,6 +726,8 @@
     }
 
     private class SwingMouseEventHandler implements EventHandler<MouseEvent> {
+        private final Set<MouseButton> mouseClickedAllowed = new HashSet<>();
+
         @Override
         public void handle(MouseEvent event) {
             JLightweightFrame frame = lwFrame;
@@ -733,6 +738,23 @@
             if (swingID < 0) {
                 return;
             }
+            final EventType<?> type = event.getEventType();
+            if (type == MouseEvent.MOUSE_PRESSED) {
+                mouseClickedAllowed.add(event.getButton());
+            } else if (type == MouseEvent.MOUSE_RELEASED) {
+                // RELEASED comes before CLICKED, so we don't remove the button from the set
+                //mouseClickedAllowed.remove(event.getButton());
+            } else if (type == MouseEvent.MOUSE_DRAGGED) {
+                // This is what AWT/Swing do
+                mouseClickedAllowed.clear();
+            } else if (type == MouseEvent.MOUSE_CLICKED) {
+                if (event.getClickCount() == 1 && !mouseClickedAllowed.contains(event.getButton())) {
+                    // RT-34610: In FX, CLICKED events are generated even after dragging the mouse pointer
+                    // Note that this is only relevant for single clicks. Double clicks use a smudge factor.
+                    return;
+                }
+                mouseClickedAllowed.remove(event.getButton());
+            }
             int swingModifiers = SwingEvents.fxMouseModsToMouseMods(event);
             // TODO: popupTrigger
             boolean swingPopupTrigger = event.getButton() == MouseButton.SECONDARY;