| author | ujhelyiz | 2011-06-28 16:33:38 (EDT) |
|---|---|---|
| committer | Fabian Steeg | 2011-06-28 16:33:38 (EDT) |
| commit | ccdee1a754418c779771e4cd1c3ed59d799d6546 (patch) (side-by-side diff) | |
| tree | ae789e34a020d59264ee181e7e0a79233e700305 | |
| parent | 9ea299731d874b229af0c0dab6a95e2ba56b09f6 (diff) | |
| download | org.eclipse.gef4-ccdee1a754418c779771e4cd1c3ed59d799d6546.zip org.eclipse.gef4-ccdee1a754418c779771e4cd1c3ed59d799d6546.tar.gz org.eclipse.gef4-ccdee1a754418c779771e4cd1c3ed59d799d6546.tar.bz2 | |
Support for setting connection routers globally for the graph and
locally for the single connections
| -rw-r--r-- | org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java | 54 | ||||
| -rw-r--r-- | org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/GraphConnection.java | 20 |
2 files changed, 74 insertions, 0 deletions
diff --git a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java index 1802f56..aba972a 100644 --- a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java +++ b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/Graph.java @@ -18,6 +18,7 @@ import java.util.List; import org.eclipse.draw2d.Animation; import org.eclipse.draw2d.ColorConstants; +import org.eclipse.draw2d.ConnectionRouter; import org.eclipse.draw2d.CoordinateListener; import org.eclipse.draw2d.FigureCanvas; import org.eclipse.draw2d.FreeformLayer; @@ -103,6 +104,8 @@ public class Graph extends FigureCanvas implements IContainer { private ScalableFreeformLayeredPane rootlayer; private ZestRootLayer zestRootLayer; + private ConnectionRouter defaultConnectionRouter; + /** * Constructor for a Graph. This widget represents the root of the graph, * and can contain graph items such as graph nodes and graph connections. @@ -1255,4 +1258,55 @@ public class Graph extends FigureCanvas implements IContainer { return new DisplayIndependentRectangle(0, 0, preferredSize.width, preferredSize.height); } + + /** + * Sets the default connection router for the graph view, but does not apply + * it retroactively. + * + * @param defaultConnectionRouter + * @since 2.0 + */ + public void setDefaultConnectionRouter( + ConnectionRouter defaultConnectionRouter) { + this.defaultConnectionRouter = defaultConnectionRouter; + } + + /** + * Returns the default connection router for the graph view. + * + * @return the default connection router; may be null. + * @since 2.0 + */ + public ConnectionRouter getDefaultConnectionRouter() { + return defaultConnectionRouter; + } + + /** + * Sets the default connection router for all connections that have no + * connection routers attached to them. + * + * @since 2.0 + */ + public void applyConnectionRouter() { + // for (GraphConnection conn : getConnections()){ + Iterator iterator = getConnections().iterator(); + while (iterator.hasNext()) { + GraphConnection conn = (GraphConnection) iterator.next(); + conn.getConnectionFigure().setConnectionRouter( + defaultConnectionRouter); + } + this.getRootLayer().getUpdateManager().performUpdate(); + } + + /** + * Updates the deafult connection router and applies to to all existing + * connections that have no connection routers set to them. + * + * @param defaultConnectionRouter + * @since 2.0 + */ + public void applyConnectionRouter(ConnectionRouter defaultConnectionRouter) { + setDefaultConnectionRouter(defaultConnectionRouter); + applyConnectionRouter(); + } } diff --git a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/GraphConnection.java b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/GraphConnection.java index aa9c125..c5389c7 100644 --- a/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/GraphConnection.java +++ b/org.eclipse.zest.core/src/org/eclipse/zest/core/widgets/GraphConnection.java @@ -13,6 +13,7 @@ package org.eclipse.zest.core.widgets; import org.eclipse.draw2d.ChopboxAnchor; import org.eclipse.draw2d.ColorConstants; import org.eclipse.draw2d.Connection; +import org.eclipse.draw2d.ConnectionRouter; import org.eclipse.draw2d.Graphics; import org.eclipse.draw2d.IFigure; import org.eclipse.draw2d.Label; @@ -73,6 +74,8 @@ public class GraphConnection extends GraphItem { private boolean highlighted; private boolean hasCustomTooltip; + private ConnectionRouter router = null; + public GraphConnection(Graph graphModel, int style, GraphNode source, GraphNode destination) { super(graphModel, style); @@ -614,6 +617,9 @@ public class GraphConnection extends GraphItem { PolylineArcConnection arcConnection = (PolylineArcConnection) connection; arcConnection.setDepth(curveDepth); } + if (connectionFigure != null) { + applyConnectionRouter(connectionFigure); + } if ((connectionStyle & ZestStyles.CONNECTIONS_DIRECTED) > 0) { PolygonDecoration decoration = new PolygonDecoration(); if (getLineWidth() < 3) { @@ -667,6 +673,7 @@ public class GraphConnection extends GraphItem { } else { connectionFigure = new PolylineConnection(); } + applyConnectionRouter(connectionFigure); sourceAnchor = new RoundedChopboxAnchor( getSource().getNodeFigure(), 8); targetAnchor = new RoundedChopboxAnchor(getDestination() @@ -736,4 +743,17 @@ public class GraphConnection extends GraphItem { layout.applyLayout(); } } + + /** + * Sets the connection router + * + * @param conn + */ + void applyConnectionRouter(Connection conn) { + if (router != null) { + conn.setConnectionRouter(router); + } else if (graph.getDefaultConnectionRouter() != null) { + conn.setConnectionRouter(graph.getDefaultConnectionRouter()); + } + } } |

