Permalink
Browse files

Added support for setting connection routers for graph connections

  • Loading branch information...
ujhelyiz committed Jun 28, 2011
1 parent 66581d1 commit c1a69026477f0852727a2132233e9e61c14b4d8d
@@ -18,6 +18,7 @@
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 @@
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 DisplayIndependentRectangle getLayoutBounds() {
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();
}
}
@@ -13,6 +13,7 @@
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 @@
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 @@ private void doUpdateFigure(Connection connection) {
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 @@ protected Point getReferencePoint() {
} else {
connectionFigure = new PolylineConnection();
}
applyConnectionRouter(connectionFigure);
sourceAnchor = new RoundedChopboxAnchor(
getSource().getNodeFigure(), 8);
targetAnchor = new RoundedChopboxAnchor(getDestination()
@@ -736,4 +743,17 @@ void applyLayoutChanges() {
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());
}
}
}

0 comments on commit c1a6902

Please sign in to comment.