]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Trigger all drag start events from single place 85/2685/1
authorJussi Koskela <jussi.koskela@semantum.fi>
Thu, 6 Sep 2018 13:46:17 +0000 (16:46 +0300)
committerMarko Luukkainen <marko.luukkainen@semantum.fi>
Mon, 25 Feb 2019 10:03:13 +0000 (10:03 +0000)
gitlab #112

Change-Id: Ifdde60194967fc80fbf0276c754af00e3c2a3ca2
(cherry picked from commit bdb7180f6425b460b8566a3223b319caf9dbc56f)

bundles/org.simantics.diagram/src/org/simantics/diagram/elements/TextNode.java
bundles/org.simantics.g2d/src/org/simantics/g2d/chassis/AWTChassis.java
bundles/org.simantics.g2d/src/org/simantics/g2d/diagram/impl/ElementDiagram.java
bundles/org.simantics.g2d/src/org/simantics/g2d/participant/MouseUtil.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/G2DSceneGraph.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/NodeEventHandler.java
bundles/org.simantics.scenegraph/src/org/simantics/scenegraph/g2d/events/adapter/AWTMouseEventAdapter.java

index 4fe3b51d898183c882b81b1feb14d7abd665ad44..43653cbd0930abc7da98159406c44a71122ed235 100644 (file)
@@ -1806,7 +1806,6 @@ public class TextNode extends G2DNode implements IDynamicSelectionPainterNode, L
     protected boolean mouseDragged(MouseDragBegin e) {
         if (isHovering()
                 && (isControlDown(e) || isShiftDown(e))
-                && e.context instanceof NodeEventHandler
                 && (dataRVI != null || text != null))
         {
             List<Transferable> trs = new ArrayList<>(2);
index 2679ef620ac5c87b65de2337c9a188219895a88e..06b3ca22044dbb9ddfe808fe75ab2a8c94241532 100644 (file)
@@ -16,6 +16,7 @@ import java.awt.Container;
 import java.awt.Cursor;
 import java.awt.Graphics;
 import java.awt.Graphics2D;
+import java.awt.GraphicsEnvironment;
 import java.awt.Rectangle;
 import java.awt.image.VolatileImage;
 import java.lang.reflect.Method;
@@ -31,6 +32,7 @@ import org.simantics.g2d.canvas.IMouseCursorListener;
 import org.simantics.g2d.dnd.DragInteractor;
 import org.simantics.g2d.dnd.DropInteractor;
 import org.simantics.g2d.internal.DebugPolicy;
+import org.simantics.g2d.participant.TransformUtil;
 import org.simantics.scenegraph.g2d.G2DRenderingHints;
 import org.simantics.scenegraph.g2d.events.Event;
 import org.simantics.scenegraph.g2d.events.IEventQueue;
@@ -239,6 +241,12 @@ public class AWTChassis extends JComponent implements ICanvasChassis {
                     holder.addMouseMotionListener(mouseAdapter);
                     holder.addMouseWheelListener(mouseAdapter);
                     holder.addFocusListener(focusAdapter);
+
+                    TransformUtil util = canvasContext.getAtMostOneItemOfClass(TransformUtil.class);
+                    if (util != null) {
+                        mouseAdapter.initDragGestureListener(holder, (control) -> util.controlToCanvas(control, null));
+                    }
+
                 }
             };
             if (AWTThread.getThreadAccess().currentThreadAccess())
index 7bec43780df1bb9904e943a347b6b98fedeeb624..07ffe5436d7d67fd9aa5ee5119f71d65b98fb35a 100644 (file)
@@ -670,20 +670,6 @@ public class ElementDiagram implements IDiagram {
                 if (deltaDistance > 0)
                     mi.addDistanceForButtons(deltaDistance);
 
-                // Send mouse drag events.
-                for (ButtonInfo bi : mi.buttonPressInfo.values()) {
-                    if (!bi.down)
-                        continue;
-                    if (bi.deltaMotion <= profile.movementTolerance)
-                        continue;
-                    if (bi.drag)
-                        continue;
-                    bi.drag = true;
-                    MouseDragBegin db = new MouseDragBegin(this, e.time, e.mouseId, e.buttons, e.stateMask, bi.button,
-                            bi.canvasPosition, bi.controlPosition, e.controlPosition, e.screenPosition);
-                    getContext().getEventQueue().queueFirst(db);
-                }
-
             } else if (e instanceof MouseButtonPressedEvent) {
                 Point2D canvasPosition = util.controlToCanvas(e.controlPosition, null);
                 MouseButtonPressedEvent me = (MouseButtonPressedEvent) e;
index 44ded472960a1686f100d1cc69f8fed9bd8137a6..d5fbdc12b2a84a29493d5c0a1ee017b4a0ee02ff 100644 (file)
@@ -111,21 +111,6 @@ public class MouseUtil extends AbstractCanvasParticipant {
                     if (deltaDistance>0)
                         mi.addDistanceForButtons(deltaDistance);
 
-                    // Send mouse drag events.
-                    for (ButtonInfo bi : mi.buttonPressInfo.values())
-                    {
-                        if (!bi.down) continue;
-                        if (bi.deltaMotion<=profile.movementTolerance) continue;
-                        if (bi.drag) continue;
-                        bi.drag = true;
-                        MouseDragBegin db = new MouseDragBegin(
-                                this, e.time, e.mouseId, e.buttons, e.stateMask, bi.button,
-                                bi.canvasPosition, bi.controlPosition,
-                                e.controlPosition, e.screenPosition
-                                );
-                        getContext().getEventQueue().queueFirst(db);
-                    }
-
                 } else
                     if (e instanceof MouseButtonPressedEvent)
                     {
index 885b8c3a049aae024848250847310d78853f6a16..204181c3786fe01631e4b333cce06a7e681bdfd3 100644 (file)
@@ -158,7 +158,6 @@ public class G2DSceneGraph extends G2DParentNode implements ILookupService, INod
             RepaintManager.setCurrentManager(repaintManager);
         }
         this.rootPane = rootPane;
-        eventHandler.setRootPane(rootPane);
     }
 
     private RepaintManager findProperRepaintManager(RepaintManager old) {
index 1c1ac8a37a7b523ace66705188f148c1972ed763..8d3ba3a94482e3405382ea4817faa90c0c107441 100644 (file)
  *******************************************************************************/
 package org.simantics.scenegraph.g2d.events;
 
-import java.awt.Component;
-import java.awt.GraphicsEnvironment;
-import java.awt.dnd.DnDConstants;
-import java.awt.dnd.DragGestureEvent;
-import java.awt.dnd.DragGestureListener;
-import java.awt.dnd.DragSource;
-import java.awt.dnd.DragSourceDragEvent;
-import java.awt.dnd.DragSourceDropEvent;
-import java.awt.dnd.DragSourceEvent;
-import java.awt.dnd.DragSourceListener;
-import java.awt.event.InputEvent;
-import java.awt.geom.Point2D;
 import java.util.ArrayList;
 import java.util.Arrays;
 import java.util.Comparator;
@@ -34,7 +22,6 @@ import org.simantics.scenegraph.g2d.G2DSceneGraph;
 import org.simantics.scenegraph.g2d.IG2DNode;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;
-import org.simantics.scenegraph.g2d.events.adapter.AWTMouseEventAdapter;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
 import org.slf4j.Logger;
 import org.slf4j.LoggerFactory;
@@ -220,65 +207,6 @@ public class NodeEventHandler implements IEventHandler {
         return sort;
     }
 
-    public void setRootPane(Component rootPane) {
-        if (GraphicsEnvironment.isHeadless()) {
-            LOGGER.info("Disabling DragSource in headless environments");
-            return;
-        }
-        final DragSource ds = new DragSource();
-        final DragSourceListener dsl = new DragSourceListener() {
-            @Override
-            public void dropActionChanged(DragSourceDragEvent dsde) {
-            }
-            @Override
-            public void dragOver(DragSourceDragEvent dsde) {
-            }
-            @Override
-            public void dragExit(DragSourceEvent dse) {
-            }
-            @Override
-            public void dragEnter(DragSourceDragEvent dsde) {
-            }
-            @Override
-            public void dragDropEnd(DragSourceDropEvent dsde) {
-            }
-        };
-        DragGestureListener dgl = new DragGestureListener() {
-            @Override
-            public void dragGestureRecognized(DragGestureEvent dge) {
-                InputEvent ie = dge.getTriggerEvent();
-                if (ie instanceof java.awt.event.MouseEvent) {
-                    java.awt.event.MouseEvent e = (java.awt.event.MouseEvent) ie;
-                    Point2D controlPos = AWTMouseEventAdapter.getControlPosition(e);
-                    MouseDragBegin event = new MouseDragBegin(NodeEventHandler.this,
-                            e.getWhen(), 0,
-                            AWTMouseEventAdapter.getButtonStatus(e),
-                            AWTMouseEventAdapter.getStateMask(e),
-                            AWTMouseEventAdapter.getMouseButton(e),
-                            // TODO: fix canvas position if necessary
-                            new Point2D.Double(),
-                            controlPos,
-                            controlPos,
-                            AWTMouseEventAdapter.getScreenPosition(e));
-
-                    // Send MouseDragBegin to the scenegraph and see
-                    // if anyone sets event.transferable to start DnD.
-                    handleMouseDragBeginEvent(event, EventTypes.MouseDragBegin);
-                    if (event.transferable != null) {
-                        ds.startDrag(dge, null, event.transferable, dsl);
-                        if (DEBUG_EVENTS)
-                            debug("dragGestureRecognized: startDrag " + event.transferable);
-                    }
-                }
-            }
-        };
-        ds.createDefaultDragGestureRecognizer(
-                rootPane,
-                DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
-                dgl);
-        ds.addDragSourceListener(dsl);
-    }
-
     public boolean mousePressed(MouseButtonPressedEvent event) {
         G2DFocusManager.INSTANCE.clearFocus();
         try {
index bad131312a337ce33195346fde1d1a6c4888b145..e01876c6d0000dfa1049631cf9d766cf8fbc4713 100644 (file)
  */
 package org.simantics.scenegraph.g2d.events.adapter;
 
+import java.awt.Component;
+import java.awt.dnd.DnDConstants;
+import java.awt.dnd.DragGestureEvent;
+import java.awt.dnd.DragGestureListener;
+import java.awt.dnd.DragSource;
 import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
@@ -22,6 +27,7 @@ import java.awt.event.MouseMotionListener;
 import java.awt.event.MouseWheelEvent;
 import java.awt.event.MouseWheelListener;
 import java.awt.geom.Point2D;
+import java.util.function.UnaryOperator;
 
 import org.simantics.scenegraph.g2d.events.EventDebugPolicy;
 import org.simantics.scenegraph.g2d.events.IEventHandler;
@@ -29,6 +35,7 @@ import org.simantics.scenegraph.g2d.events.IEventQueue;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDoubleClickedEvent;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseDragBegin;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseEnterEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseExitEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
@@ -289,4 +296,38 @@ public class AWTMouseEventAdapter extends AbstractEventAdapter implements MouseL
             System.out.println("AWT mouse clicked: " + e);
     }
 
+    public void initDragGestureListener(Component rootPane, UnaryOperator<Point2D> controlToCanvas) {
+        final DragSource ds = new DragSource();
+        DragGestureListener dgl = new DragGestureListener() {
+            @Override
+            public void dragGestureRecognized(DragGestureEvent dge) {
+                InputEvent ie = dge.getTriggerEvent();
+                if (ie instanceof java.awt.event.MouseEvent) {
+                    java.awt.event.MouseEvent e = (java.awt.event.MouseEvent) ie;
+                    Point2D controlPos = getControlPosition(e);
+                    Point2D canvasPos = controlToCanvas.apply(controlPos);
+
+                    MouseDragBegin event = new MouseDragBegin(this,
+                            e.getWhen(), 0,
+                            getButtonStatus(e),
+                            getStateMask(e),
+                            getMouseButton(e),
+                            canvasPos,
+                            controlPos,
+                            controlPos,
+                            getScreenPosition(e));
+
+                    handleEvent(event);
+
+                    if (event.transferable != null) {
+                        ds.startDrag(dge, null, event.transferable, null);
+                    }
+                }
+            }
+        };
+        ds.createDefaultDragGestureRecognizer(
+                rootPane,
+                DnDConstants.ACTION_COPY_OR_MOVE | DnDConstants.ACTION_LINK,
+                dgl);
+    }
 }