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
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;
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;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
import org.simantics.scenegraph.g2d.events.command.CommandEvent;
import org.simantics.scenegraph.g2d.events.command.Commands;
if (me instanceof MouseButtonPressedEvent)
return processMouseButtonPress((MouseButtonPressedEvent) me);
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);
+
if (snapAdvisor != null)
snapAdvisor.snap(mouseCanvasPos);
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
return true;
} else {
// Finish connection in thin air only if the
+ 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) {
private void attachToConnection() {
ConnectionJudgement judgment = this.attachToConnectionJudgement;
if (judgment == null) {
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;
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;
import org.simantics.scenegraph.g2d.events.MouseEvent.MouseMovedEvent;
import org.simantics.scenegraph.g2d.events.command.CommandEvent;
import org.simantics.scenegraph.g2d.events.command.Commands;
if (me instanceof MouseButtonPressedEvent)
return processMouseButtonPress((MouseButtonPressedEvent) me);
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);
+
protected void disconnect(Point2D mouseCanvasPos) {
setEndTerminal(mouseCanvasPos.getX(), mouseCanvasPos.getY(), null, 0xf);
}
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.
// Do nothing before the mouse has moved at least a little.
// This prevents the user from ending the connection right where
// it started.
snapAdvisor.snap(mouseCanvasPos);
// Clicked on an allowed end terminal. End connection & end mode.
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
return true;
} else {
// Finish connection in thin air only if the
+ 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;
protected boolean cancelPreviousBend() {
if (!routePointsAllowed())
return false;