]> gerrit.simantics Code Review - simantics/platform.git/commitdiff
Simplified diagram connection creation 73/1273/2
authorTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 30 Nov 2017 17:26:55 +0000 (19:26 +0200)
committerTuukka Lehtonen <tuukka.lehtonen@semantum.fi>
Thu, 30 Nov 2017 17:27:16 +0000 (19:27 +0200)
With these changes diagram connections can be created with a single drag
operation when suitable by holding the first (left) mouse button down
until releasing it on top of the end terminal of the connection.

The same sequence also work for branching to/from an existing
connection.

refs #7653

Change-Id: I97579b86220d9ee1eacd9df5a1106524b35bf225

bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java
bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java

index b77a2894714b72512c5925ea7b6379fc6e17c382..7d3a5a4005078f314f96d49b931978eabb5ad4c5 100644 (file)
@@ -90,6 +90,7 @@ import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
 import org.simantics.scenegraph.g2d.events.command.Commands;
@@ -520,6 +521,10 @@ public class ConnectTool2 extends AbstractMode {
         if (me instanceof MouseButtonPressedEvent)
             return processMouseButtonPress((MouseButtonPressedEvent) me);
 
+        // #7653: Support creating connections between terminals without lifting mouse button in between.
+        if (me instanceof MouseButtonReleasedEvent)
+            return processMouseButtonRelease((MouseButtonReleasedEvent) me);
+
         return false;
     }
 
@@ -662,15 +667,7 @@ public class ConnectTool2 extends AbstractMode {
             if (snapAdvisor != null)
                 snapAdvisor.snap(mouseCanvasPos);
 
-            if (isEndTerminalDefined() && connectionJudgment != null) {
-                // Clicked on an allowed end terminal. End connection & end mode.
-                createConnection();
-                remove();
-                return true;
-            } else if (lastRouteGraphTarget != null && attachToConnectionJudgement != null) {
-                lastRouteGraphTarget.getNode().showBranchPoint(null);
-                attachToConnection();
-                remove();
+            if (tryEndConnection()) {
                 return true;
             } else {
                 // Finish connection in thin air only if the
@@ -710,6 +707,33 @@ public class ConnectTool2 extends AbstractMode {
         return false;
     }
 
+    private int mouseLeftReleaseCount = 0;
+
+    protected boolean processMouseButtonRelease(MouseButtonReleasedEvent me) {
+        if (me.button == MouseEvent.LEFT_BUTTON
+                && ++mouseLeftReleaseCount == 1) {
+            return tryEndConnection();
+        }
+        return false;
+    }
+
+    /**
+     * @return <code>true</code> if connection was successfully ended
+     */
+    private boolean tryEndConnection() {
+        if (isEndTerminalDefined() && connectionJudgment != null) {
+            createConnection();
+            remove();
+            return true;
+        } else if (lastRouteGraphTarget != null && attachToConnectionJudgement != null) {
+            lastRouteGraphTarget.getNode().showBranchPoint(null);
+            attachToConnection();
+            remove();
+            return true;
+        }
+        return false;
+    }
+
     private void attachToConnection() {
         ConnectionJudgement judgment = this.attachToConnectionJudgement;
         if (judgment == null) {
index 4cccea938270b6b8ac0b50baf6ac91d2b190528a..8f99207e19c77cb00f55288f8bd4d218aca06cdf 100644 (file)
@@ -85,6 +85,7 @@ import org.simantics.scenegraph.g2d.events.KeyEvent.KeyPressedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonPressedEvent;
+import org.simantics.scenegraph.g2d.events.MouseEvent.MouseButtonReleasedEvent;
 import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
 import org.simantics.scenegraph.g2d.events.command.CommandEvent;
 import org.simantics.scenegraph.g2d.events.command.Commands;
@@ -477,6 +478,10 @@ public class RouteGraphConnectTool extends AbstractMode {
         if (me instanceof MouseButtonPressedEvent)
             return processMouseButtonPress((MouseButtonPressedEvent) me);
 
+        // #7653: Support creating connections between terminals without lifting mouse button in between.
+        if (me instanceof MouseButtonReleasedEvent)
+            return processMouseButtonRelease((MouseButtonReleasedEvent) me);
+
         return false;
     }
 
@@ -566,10 +571,8 @@ public class RouteGraphConnectTool extends AbstractMode {
     protected void disconnect(Point2D mouseCanvasPos) {
         setEndTerminal(mouseCanvasPos.getX(), mouseCanvasPos.getY(), null, 0xf);
     }
-    
-    protected boolean processMouseButtonPress(MouseButtonPressedEvent e) {
-        MouseButtonEvent me = e;
 
+    protected boolean processMouseButtonPress(MouseButtonEvent me) {
         // Do nothing before the mouse has moved at least a little.
         // This prevents the user from ending the connection right where
         // it started.
@@ -585,9 +588,7 @@ public class RouteGraphConnectTool extends AbstractMode {
                 snapAdvisor.snap(mouseCanvasPos);
 
             // Clicked on an allowed end terminal. End connection & end mode.
-            if (isEndTerminalDefined()) {
-                createConnection();
-                remove();
+            if (tryEndConnection()) {
                 return true;
             } else {
                 // Finish connection in thin air only if the
@@ -617,6 +618,28 @@ public class RouteGraphConnectTool extends AbstractMode {
         return false;
     }
 
+    private int mouseLeftReleaseCount = 0;
+
+    protected boolean processMouseButtonRelease(MouseButtonReleasedEvent me) {
+        if (me.button == MouseEvent.LEFT_BUTTON
+                && ++mouseLeftReleaseCount == 1) {
+            return tryEndConnection();
+        }
+        return false;
+    }
+
+    /**
+     * @return <code>true</code> if connection was successfully ended
+     */
+    private boolean tryEndConnection() {
+        if (isEndTerminalDefined()) {
+            createConnection();
+            remove();
+            return true;
+        }
+        return false;
+    }
+
     protected boolean cancelPreviousBend() {
         if (!routePointsAllowed())
             return false;