From 13ff25bbcaaf3f36293a931403486ccc3897c9a6 Mon Sep 17 00:00:00 2001 From: Tuukka Lehtonen Date: Thu, 30 Nov 2017 19:26:55 +0200 Subject: [PATCH] Simplified diagram connection creation 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 --- .../diagram/participant/ConnectTool2.java | 42 +++++++++++++++---- .../participant/RouteGraphConnectTool.java | 35 +++++++++++++--- 2 files changed, 62 insertions(+), 15 deletions(-) diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java index b77a28947..7d3a5a400 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/ConnectTool2.java @@ -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 true 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) { diff --git a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java index 4cccea938..8f99207e1 100644 --- a/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java +++ b/bundles/org.simantics.diagram/src/org/simantics/diagram/participant/RouteGraphConnectTool.java @@ -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 true if connection was successfully ended + */ + private boolean tryEndConnection() { + if (isEndTerminalDefined()) { + createConnection(); + remove(); + return true; + } + return false; + } + protected boolean cancelPreviousBend() { if (!routePointsAllowed()) return false; -- 2.47.1