Download
Getting Started
Members
Projects
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
More
Community
Marketplace
Events
Planet Eclipse
Newsletter
Videos
Participate
Report a Bug
Forums
Mailing Lists
Wiki
IRC
How to Contribute
Working Groups
Automotive
Internet of Things
LocationTech
Long-Term Support
PolarSys
Science
OpenMDM
Toggle navigation
Bugzilla – Attachment 91531 Details for
Bug 221214
Graph Layout should not modiy heights of nodes
Home
|
New
|
Browse
|
Search
|
[?]
|
Reports
|
Requests
|
Help
|
Log In
[x]
|
Terms of Use
|
Copyright Agent
Some Eclipse Foundation services are deprecated, or will be soon. Please ensure you've read
this important communication.
[patch]
cprrected patch
Layout_GEF_Mar04 (text/plain), 28.48 KB, created by
Alex Boyko
on 2008-03-04 11:24:44 EST
(
hide
)
Description:
cprrected patch
Filename:
MIME Type:
Creator:
Alex Boyko
Created:
2008-03-04 11:24:44 EST
Size:
28.48 KB
patch
obsolete
>### Eclipse Workspace Patch 1.0 >#P org.eclipse.draw2d >Index: src/org/eclipse/draw2d/graph/Node.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/Node.java,v >retrieving revision 1.11 >diff -u -r1.11 Node.java >--- src/org/eclipse/draw2d/graph/Node.java 15 Feb 2006 22:22:51 -0000 1.11 >+++ src/org/eclipse/draw2d/graph/Node.java 4 Mar 2008 16:21:56 -0000 >@@ -46,6 +46,8 @@ > * @since 2.1.2 > */ > public class Node { >+ >+Node left, right; > > Object workingData[] = new Object[3]; > int workingInts[] = new int[4]; >Index: src/org/eclipse/draw2d/graph/CompoundDirectedGraphLayout.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/CompoundDirectedGraphLayout.java,v >retrieving revision 1.17 >diff -u -r1.17 CompoundDirectedGraphLayout.java >--- src/org/eclipse/draw2d/graph/CompoundDirectedGraphLayout.java 15 Mar 2007 12:45:56 -0000 1.17 >+++ src/org/eclipse/draw2d/graph/CompoundDirectedGraphLayout.java 4 Mar 2008 16:21:56 -0000 >@@ -40,6 +40,7 @@ > void init() { > steps.add(new TransposeMetrics()); > steps.add(new CompoundBreakCycles()); >+ steps.add(new SpaceOutEdges()); > steps.add(new RouteEdges()); > steps.add(new ConvertCompoundGraph()); > steps.add(new InitialRankSolver()); >Index: src/org/eclipse/draw2d/graph/VirtualNode.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/VirtualNode.java,v >retrieving revision 1.13 >diff -u -r1.13 VirtualNode.java >--- src/org/eclipse/draw2d/graph/VirtualNode.java 14 Feb 2006 20:19:44 -0000 1.13 >+++ src/org/eclipse/draw2d/graph/VirtualNode.java 4 Mar 2008 16:21:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2003, 2005 IBM Corporation and others. >+ * Copyright (c) 2003, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -19,8 +19,6 @@ > */ > public class VirtualNode extends Node { > >-Node left, right; >- > /** > * The next node. > */ >Index: src/org/eclipse/draw2d/graph/DirectedGraphLayout.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/DirectedGraphLayout.java,v >retrieving revision 1.15 >diff -u -r1.15 DirectedGraphLayout.java >--- src/org/eclipse/draw2d/graph/DirectedGraphLayout.java 15 Mar 2007 12:45:56 -0000 1.15 >+++ src/org/eclipse/draw2d/graph/DirectedGraphLayout.java 4 Mar 2008 16:21:56 -0000 >@@ -75,6 +75,7 @@ > void init() { > steps.add(new TransposeMetrics()); > steps.add(new BreakCycles()); >+ steps.add(new SpaceOutEdges()); > steps.add(new RouteEdges()); > steps.add(new InitialRankSolver()); > steps.add(new TightSpanningTreeSolver()); >Index: src/org/eclipse/draw2d/graph/PopulateRanks.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/PopulateRanks.java,v >retrieving revision 1.1 >diff -u -r1.1 PopulateRanks.java >--- src/org/eclipse/draw2d/graph/PopulateRanks.java 14 Feb 2006 20:19:44 -0000 1.1 >+++ src/org/eclipse/draw2d/graph/PopulateRanks.java 4 Mar 2008 16:21:56 -0000 >@@ -61,10 +61,10 @@ > Node prev = null, cur; > for (int n = 0; n < rank.size(); n++) { > cur = rank.getNode(n); >- if (cur instanceof VirtualNode) >- ((VirtualNode)cur).left = prev; >- if (prev instanceof VirtualNode) >- ((VirtualNode)prev).right = cur; >+ cur.left = prev; >+ if (prev != null) { >+ prev.right = cur; >+ } > prev = cur; > } > } >Index: src/org/eclipse/draw2d/graph/Rank.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/Rank.java,v >retrieving revision 1.8 >diff -u -r1.8 Rank.java >--- src/org/eclipse/draw2d/graph/Rank.java 14 Feb 2006 20:19:44 -0000 1.8 >+++ src/org/eclipse/draw2d/graph/Rank.java 4 Mar 2008 16:21:56 -0000 >@@ -75,7 +75,9 @@ > for (int i = 0; i < size(); i++) { > Node n = getNode(i); > n.y = location; >- n.height = rowHeight; >+ if (n instanceof VirtualNode) { >+ n.height = rowHeight; >+ } > } > } > >Index: src/org/eclipse/draw2d/graph/RouteEdges.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/RouteEdges.java,v >retrieving revision 1.1 >diff -u -r1.1 RouteEdges.java >--- src/org/eclipse/draw2d/graph/RouteEdges.java 14 Feb 2006 20:19:44 -0000 1.1 >+++ src/org/eclipse/draw2d/graph/RouteEdges.java 4 Mar 2008 16:21:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2003, 2005 IBM Corporation and others. >+ * Copyright (c) 2003, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -10,7 +10,6 @@ > *******************************************************************************/ > package org.eclipse.draw2d.graph; > >-import org.eclipse.draw2d.geometry.Insets; > import org.eclipse.draw2d.geometry.Point; > import org.eclipse.draw2d.geometry.PointList; > import org.eclipse.draw2d.geometry.Rectangle; >@@ -19,6 +18,8 @@ > * @author Randy Hudson > */ > class RouteEdges extends GraphVisitor { >+ >+private static int OBSTACLE_WIDTH = 10000; > > /** > * @see GraphVisitor#visit(DirectedGraph) >@@ -38,45 +39,34 @@ > edge.getTargetOffset() + edge.target.x, > edge.target.y); > >- if (edge.vNodes != null) >- routeLongEdge(edge, g); >- else { >- PointList list = new PointList(); >- list.addPoint(edge.start); >- list.addPoint(edge.end); >- edge.setPoints(list); >+ if (edge.getRoutingStyle() == Edge.ORTHOGONAL_ROUTING_STYLE) { >+ routeOrthogonalEdge(edge, g); >+ } else { >+ routeEdge(edge, g); > } > } > } > >-static void routeLongEdge(Edge edge, DirectedGraph g) { >+void routeEdge(Edge edge, DirectedGraph g) { > ShortestPathRouter router = new ShortestPathRouter(); > Path path = new Path(edge.start, edge.end); > router.addPath(path); >- Rectangle o; >- Insets padding; >- for (int i = 0; i < edge.vNodes.size(); i++) { >- VirtualNode node = (VirtualNode)edge.vNodes.get(i); >- Node neighbor; >- if (node.left != null) { >- neighbor = node.left; >- o = new Rectangle(neighbor.x, neighbor.y, neighbor.width, neighbor.height); >- padding = g.getPadding(neighbor); >- o.width += padding.right + padding.left; >- o.width += (edge.getPadding() * 2); >- o.x -= (padding.left + edge.getPadding()); >- o.union(o.getLocation().translate(-100000, 2)); >- router.addObstacle(o); >- } >- if (node.right != null) { >- neighbor = node.right; >- o = new Rectangle(neighbor.x, neighbor.y, neighbor.width, neighbor.height); >- padding = g.getPadding(neighbor); >- o.width += padding.right + padding.left; >- o.width += (edge.getPadding() * 2); >- o.x -= (padding.left + edge.getPadding()); >- o.union(o.getLocation().translate(100000, 2)); >- router.addObstacle(o); >+ if (edge.vNodes != null) { >+ for (int i = 0; i < edge.vNodes.size(); i++) { >+ Node node = edge.vNodes.getNode(i); >+ Rank r = g.ranks.getRank(node.rank); >+ if (node.left != null) { >+ int right = node.left.x + node.left.width + g.getPadding(node.left).right + edge.getPadding(); >+ int width = Math.max(right, OBSTACLE_WIDTH); >+ int height = Math.max(r.height, 2); >+ router.addObstacle(new Rectangle(right - width, node.left.y, width, height)); >+ } >+ if (node.right != null) { >+ int left = node.right.x - g.getPadding(node.right).left - edge.getPadding(); >+ int width = Math.max(g.size.width - left, OBSTACLE_WIDTH); >+ int height = Math.max(r.height, 2); >+ router.addObstacle(new Rectangle(left, node.right.y, width, height)); >+ } > } > } > router.setSpacing(0); >@@ -84,4 +74,36 @@ > edge.setPoints(path.getPoints()); > } > >+void routeOrthogonalEdge(Edge edge, DirectedGraph g) { >+ PointList points = new PointList(); >+ points.addPoint(edge.start); >+ Node previousNode = edge.source instanceof Subgraph ? ((Subgraph)edge.source).tail : edge.source; >+ if (edge.vNodes != null) { >+ for (int i = 0; i < edge.vNodes.size(); i++) { >+ Node vNode = edge.vNodes.getNode(i); >+ int nextPtX = vNode.x + vNode.width / 2; >+ int prevPtX = points.getLastPoint().x; >+ if (prevPtX != nextPtX) { >+ Rank previousRank = g.ranks.getRank(previousNode.rank); >+ int rankBottomY = previousRank.location + previousRank.height; >+ int midY = rankBottomY + (vNode.y - rankBottomY) / 2; >+ points.addPoint(prevPtX, midY); >+ points.addPoint(nextPtX, midY); >+ } >+ previousNode = vNode; >+ } >+ } >+ Point prevPt = points.getLastPoint(); >+ Point lastPt = edge.end; >+ if (prevPt.x != lastPt.x) { >+ Rank previousRank = g.ranks.getRank(previousNode.rank); >+ int rankBottomY = previousRank.location + previousRank.height; >+ int midY = rankBottomY + (lastPt.y - rankBottomY) / 2; >+ points.addPoint(prevPt.x, midY); >+ points.addPoint(lastPt.x, midY); >+ } >+ points.addPoint(edge.end); >+ edge.setPoints(points); >+} >+ > } >Index: src/org/eclipse/draw2d/graph/Edge.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/graph/Edge.java,v >retrieving revision 1.13 >diff -u -r1.13 Edge.java >--- src/org/eclipse/draw2d/graph/Edge.java 24 Feb 2006 17:16:19 -0000 1.13 >+++ src/org/eclipse/draw2d/graph/Edge.java 4 Mar 2008 16:21:56 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2003, 2005 IBM Corporation and others. >+ * Copyright (c) 2003, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -39,6 +39,9 @@ > * @since 2.1.2 > */ > public class Edge { >+ >+public static final int DEFAULT_ROUTING_STYLE = 0; >+public static final int ORTHOGONAL_ROUTING_STYLE = 1; > > int cut; > >@@ -92,6 +95,8 @@ > > private PointList points; > >+private int routingStyle = DEFAULT_ROUTING_STYLE; >+ > /** > * The source Node. > */ >@@ -377,4 +382,22 @@ > this.width = width; > } > >+/** >+ * Gets the routing style constant >+ * @return the routing style >+ * @since 3.4 >+ */ >+public int getRoutingStyle() { >+ return routingStyle; >+} >+ >+/** >+ * Sets the routing style constant >+ * @param style the style >+ * @since 3.4 >+ */ >+public void setRoutingStyle(int style) { >+ this.routingStyle = style; >+} >+ > } >Index: src/org/eclipse/draw2d/geometry/Geometry.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/Geometry.java,v >retrieving revision 1.3 >diff -u -r1.3 Geometry.java >--- src/org/eclipse/draw2d/geometry/Geometry.java 24 May 2005 22:47:57 -0000 1.3 >+++ src/org/eclipse/draw2d/geometry/Geometry.java 4 Mar 2008 16:21:55 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -41,26 +41,33 @@ > * Given the segments: u-------v. s-------t. If s->t is inside the triangle u-v-s, > * then check whether the line u->u splits the line s->t. > */ >- int usX = ux - sx; >- int usY = uy - sy; >- int vsX = vx - sx; >- int vsY = vy - sy; >- int stX = sx - tx; >- int stY = sy - ty; >- long product = cross(vsX, vsY, stX, stY) * cross(stX, stY, usX, usY); >- if (product >= 0) { >- int vuX = vx - ux; >- int vuY = vy - uy; >- int utX = ux - tx; >- int utY = uy - ty; >- product = cross(-usX, -usY, vuX, vuY) * cross(vuX, vuY, utX, utY); >- boolean intersects = product <= 0; >- return intersects; >+ /* Values are casted to long to avoid integer overflows */ >+ long usX = (long) ux - sx; >+ long usY = (long) uy - sy; >+ long vsX = (long) vx - sx; >+ long vsY = (long) vy - sy; >+ long stX = (long) sx - tx; >+ long stY = (long) sy - ty; >+ if (productSign(cross(vsX, vsY, stX, stY), cross(stX, stY, usX, usY)) >= 0) { >+ long vuX = (long) vx - ux; >+ long vuY = (long) vy - uy; >+ long utX = (long) ux - tx; >+ long utY = (long) uy - ty; >+ return productSign(cross(-usX, -usY, vuX, vuY), cross(vuX, vuY, utX, utY)) <= 0; > } > return false; > } > >-private static long cross(int x1, int y1, int x2, int y2) { >+private static int productSign(long x, long y) { >+ if (x == 0 || y == 0) { >+ return 0; >+ } else if (x < 0 ^ y < 0) { >+ return -1; >+ } >+ return 1; >+} >+ >+private static long cross(long x1, long y1, long x2, long y2) { > return x1 * y2 - x2 * y1; > } > >Index: src/org/eclipse/draw2d/geometry/Point.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/Point.java,v >retrieving revision 1.10 >diff -u -r1.10 Point.java >--- src/org/eclipse/draw2d/geometry/Point.java 2 Jan 2008 18:51:55 -0000 1.10 >+++ src/org/eclipse/draw2d/geometry/Point.java 4 Mar 2008 16:21:55 -0000 >@@ -118,7 +118,7 @@ > * @since 2.0 > */ > public double getDistance(Point pt) { >- return Math.sqrt(getDistance2(pt)); >+ return Math.sqrt(getPreciseDistance2(pt)); > } > > /** >@@ -138,6 +138,12 @@ > return (int)result; > } > >+private double getPreciseDistance2(Point pt) { >+ double i = pt.preciseX() - preciseX(); >+ double j = pt.preciseY() - preciseY(); >+ return i * i + j * j; >+} >+ > /** > * Calculates the orthogonal distance to the specified point. The orthogonal distance is > * the sum of the horizontal and vertical differences. >Index: src/org/eclipse/draw2d/geometry/PrecisionRectangle.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/geometry/PrecisionRectangle.java,v >retrieving revision 1.18 >diff -u -r1.18 PrecisionRectangle.java >--- src/org/eclipse/draw2d/geometry/PrecisionRectangle.java 2 Jan 2008 18:51:55 -0000 1.18 >+++ src/org/eclipse/draw2d/geometry/PrecisionRectangle.java 4 Mar 2008 16:21:56 -0000 >@@ -376,4 +376,13 @@ > return preciseHeight; > } > >+/** >+ * @see org.eclipse.draw2d.geometry.Rectangle#setSize(org.eclipse.draw2d.geometry.Dimension) >+ */ >+public Rectangle setSize(Dimension d) { >+ preciseWidth = d.preciseWidth(); >+ preciseHeight = d.preciseHeight(); >+ return super.setSize(d); >+} >+ > } >Index: src/org/eclipse/draw2d/RelativeBendpoint.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/plugins/org.eclipse.draw2d/src/org/eclipse/draw2d/RelativeBendpoint.java,v >retrieving revision 1.8 >diff -u -r1.8 RelativeBendpoint.java >--- src/org/eclipse/draw2d/RelativeBendpoint.java 30 Mar 2005 21:27:45 -0000 1.8 >+++ src/org/eclipse/draw2d/RelativeBendpoint.java 4 Mar 2008 16:21:55 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2000, 2005 IBM Corporation and others. >+ * Copyright (c) 2000, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -12,6 +12,7 @@ > > import org.eclipse.draw2d.geometry.Dimension; > import org.eclipse.draw2d.geometry.Point; >+import org.eclipse.draw2d.geometry.PrecisionPoint; > > /** > * RelativeBendpoint is a Bendpoint that calculates its location based on its distance >@@ -58,20 +59,17 @@ > * @since 2.0 > */ > public Point getLocation() { >- Point a1 = getConnection().getSourceAnchor().getReferencePoint(); >- Point a2 = getConnection().getTargetAnchor().getReferencePoint(); >+ PrecisionPoint a1 = new PrecisionPoint(getConnection().getSourceAnchor().getReferencePoint()); >+ PrecisionPoint a2 = new PrecisionPoint(getConnection().getTargetAnchor().getReferencePoint()); > >- Point p = new Point(); >- Dimension dim1 = d1.getCopy(), dim2 = d2.getCopy(); >+ getConnection().translateToRelative(a1); >+ getConnection().translateToRelative(a2); > >- getConnection().translateToAbsolute(dim1); >- getConnection().translateToAbsolute(dim2); >- >- p.x = (int)((a1.x + dim1.width) * (1f - weight) + weight * (a2.x + dim2.width)); >- p.y = (int)((a1.y + dim1.height) * (1f - weight) + weight * (a2.y + dim2.height)); >- getConnection().translateToRelative(p); >- return p; >-} >+ return new PrecisionPoint((a1.preciseX() + d1.preciseWidth()) >+ * (1f - weight) + weight * (a2.preciseX() + d2.preciseWidth()), >+ (a1.preciseY() + d1.preciseHeight()) * (1f - weight) + weight >+ * (a2.preciseY() + d2.preciseHeight())); >+ } > > /** > * Sets the Connection this bendpoint should be associated with. >Index: src/org/eclipse/draw2d/graph/SpaceOutEdges.java >=================================================================== >RCS file: src/org/eclipse/draw2d/graph/SpaceOutEdges.java >diff -N src/org/eclipse/draw2d/graph/SpaceOutEdges.java >--- /dev/null 1 Jan 1970 00:00:00 -0000 >+++ src/org/eclipse/draw2d/graph/SpaceOutEdges.java 1 Jan 1970 00:00:00 -0000 >@@ -0,0 +1,120 @@ >+/******************************************************************************* >+ * Copyright (c) 2008 IBM Corporation and others. >+ * All rights reserved. This program and the accompanying materials >+ * are made available under the terms of the Eclipse Public License v1.0 >+ * which accompanies this distribution, and is available at >+ * http://www.eclipse.org/legal/epl-v10.html >+ * >+ * Contributors: >+ * IBM Corporation - initial API and implementation >+ *******************************************************************************/ >+ >+package org.eclipse.draw2d.graph; >+ >+import java.util.Collections; >+import java.util.Comparator; >+import java.util.Iterator; >+ >+import org.eclipse.draw2d.geometry.Geometry; >+import org.eclipse.draw2d.geometry.Point; >+ >+/** >+ * Graph visitor in charge of spacing out edges such that they don't overlap. >+ * Currently the graph visitor insures that outgoing edges don't overlap for nodes, >+ * the height of which is different from the rank height. >+ * @since 3.4 >+ */ >+class SpaceOutEdges extends GraphVisitor { >+ >+ void revisit(DirectedGraph g) { >+ for (int i = 0; i < g.nodes.size(); i++) { >+ Node n = g.nodes.getNode(i); >+ Rank rank = g.ranks.getRank(n.rank); >+ if (!n.outgoing.isEmpty() && n.height != rank.height) { >+ Collections.sort(n.outgoing, new EdgeComparator()); >+ EdgeList leftEdges = new EdgeList(); >+ EdgeList rightEdges = new EdgeList(); >+ for (Iterator itr = n.outgoing.iterator(); itr.hasNext();) { >+ Edge e = (Edge) itr.next(); >+ if (e.getRoutingStyle() == Edge.DEFAULT_ROUTING_STYLE) { >+ /* >+ * Filtering of edges on left and right edges is done >+ * based on the default source end point. Hence, edge#offsetSource >+ * is ignored. >+ */ >+ int startX = n.x + n.getOffsetOutgoing(); >+ int endX = e.getPoints().getPoint(1).x; >+ if (endX > startX && n.right != null) { >+ rightEdges.add(e); >+ } else if (endX < startX && n.left != null) { >+ leftEdges.add(e); >+ } >+ } >+ } >+ >+ if (!leftEdges.isEmpty()) { >+ int obstructionX; >+ int initialObstructionX = obstructionX = n.left.x + n.left.width + g.getPadding(n.left).right; >+ int increment = (n.x + n.getOffsetOutgoing() - initialObstructionX) / leftEdges.size(); >+ for (int j = 0; j < leftEdges.size(); j++) { >+ Edge e = leftEdges.getEdge(j); >+ Point first = e.getPoints().getFirstPoint(); >+ Point second = e.getPoints().getPoint(1); >+ if (Geometry.linesIntersect(first.x, first.y, second.x, second.y, obstructionX, n.y, obstructionX, n.y + rank.height)) { >+ e.getPoints().insertPoint(new Point(obstructionX, n.y + rank.height), 1); >+ obstructionX += increment; >+ } else { >+ /* >+ * If edge segment doesn't intersect the obstruction line then the rest of them >+ * won't intersect it either. >+ */ >+ break; >+ } >+ } >+ } >+ >+ if (!rightEdges.isEmpty()) { >+ int obstructionX; >+ int initialObstructionX = obstructionX = n.right.x - g.getPadding(n.right).left; >+ int decrement = (initialObstructionX - n.x - n.getOffsetOutgoing()) / rightEdges.size(); >+ for (int j = rightEdges.size(); j > 0; j--) { >+ Edge e = rightEdges.getEdge(j - 1); >+ Point first = e.getPoints().getFirstPoint(); >+ Point second = e.getPoints().getPoint(1); >+ if (Geometry.linesIntersect(first.x, first.y, second.x, second.y, obstructionX, n.y, obstructionX, n.y + rank.height)) { >+ e.getPoints().insertPoint(new Point(obstructionX, n.y + rank.height), 1); >+ obstructionX -= decrement; >+ } else { >+ /* >+ * If edge segment doesn't intersect the obstruction line then the rest of them >+ * won't intersect it either. >+ */ >+ break; >+ } >+ } >+ } >+ >+ } >+ } >+ } >+ >+ /** >+ * Sorts outgoing edges in ascending order based on their direction (left-most to right-most) >+ * @since 3.4 >+ */ >+ private class EdgeComparator implements Comparator { >+ public int compare(Object arg0, Object arg1) { >+ Edge e1 = (Edge) arg0; >+ Edge e2 = (Edge) arg1; >+ int x1 = e1.getPoints().getPoint(1).x; >+ int x2 = e2.getPoints().getPoint(1).x; >+ if (x1 == x2) { >+ return 0; >+ } else if (x1 > x2) { >+ return 1; >+ } else { >+ return -1; >+ } >+ } >+ } >+} >#P org.eclipse.draw2d.examples >Index: src/org/eclipse/draw2d/examples/graph/GraphTests.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/examples/org.eclipse.draw2d.examples/src/org/eclipse/draw2d/examples/graph/GraphTests.java,v >retrieving revision 1.5 >diff -u -r1.5 GraphTests.java >--- src/org/eclipse/draw2d/examples/graph/GraphTests.java 14 Feb 2006 20:20:25 -0000 1.5 >+++ src/org/eclipse/draw2d/examples/graph/GraphTests.java 4 Mar 2008 16:22:01 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005 IBM Corporation and others. >+ * Copyright (c) 2005, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -779,4 +779,83 @@ > > } > >+public static DirectedGraph fourLevelOrthogonalBinaryTree() { >+ NodeList nodes = new NodeList(); >+ EdgeList edges = new EdgeList(); >+ >+ Node row[], firstRow[]; >+ firstRow = new Node[2]; >+ firstRow[1] = new Node("root"); >+ addNodes(nodes, firstRow); >+ >+ row = joinRows(nodes, edges, firstRow, new int[] {1,1, 1, 2}); >+ >+ row = joinRows(nodes, edges, row, new int[] {1,1,1,2,2,3,2,4}); >+ >+ row = joinRows(nodes, edges, row, new int[] {1,1,1,2,2,3,2,4,3,5,3,6,4,7,4,8}); >+ >+ for (int i = 0; i < edges.size(); i++) { >+ edges.getEdge(i).setRoutingStyle(Edge.ORTHOGONAL_ROUTING_STYLE); >+ } >+ >+ DirectedGraph graph = new DirectedGraph(); >+ graph.nodes = nodes; >+ graph.edges = edges; >+ >+ new DirectedGraphLayout() >+ .visit(graph); >+ >+ return graph; >+} >+ >+public static DirectedGraph variousHeightNodesGraph_Test() { >+ Node n1, n2, n3; >+ Node n4, n5, n6, n7, n8, n9; >+ NodeList nodes = new NodeList(); >+ EdgeList edges = new EdgeList(); >+ >+ >+ nodes.add(n1 = new Node("1")); >+ nodes.add(n2 = new Node("2")); >+ nodes.add(n3 = new Node("3")); >+ nodes.add(n4 = new Node("4")); >+ nodes.add(n5 = new Node("5")); >+ nodes.add(n6 = new Node("6")); >+ nodes.add(n7 = new Node("7")); >+ nodes.add(n8 = new Node("8")); >+ nodes.add(n9 = new Node("9")); >+ >+ n2.width = 200; >+ n2.height = 350; >+ >+ edges.add(new Edge(n1, n4)); >+ edges.add(new Edge(n1, n5)); >+ edges.add(new Edge(n1, n6)); >+ edges.add(new Edge(n1, n7)); >+ edges.add(new Edge(n1, n8)); >+ edges.add(new Edge(n1, n9)); >+ >+ edges.add(new Edge(n2, n4)); >+ edges.add(new Edge(n2, n5)); >+ edges.add(new Edge(n2, n6)); >+ edges.add(new Edge(n2, n7)); >+ edges.add(new Edge(n2, n8)); >+ edges.add(new Edge(n2, n9)); >+ >+ edges.add(new Edge(n3, n4)); >+ edges.add(new Edge(n3, n5)); >+ edges.add(new Edge(n3, n6)); >+ edges.add(new Edge(n3, n7)); >+ edges.add(new Edge(n3, n8)); >+ edges.add(new Edge(n3, n9)); >+ >+ DirectedGraph graph = new DirectedGraph(); >+ graph.nodes = nodes; >+ graph.edges = edges; >+ >+ new DirectedGraphLayout() >+ .visit(graph); >+ return graph; >+} >+ > } >Index: src/org/eclipse/draw2d/examples/graph/CompoundGraphTests.java >=================================================================== >RCS file: /cvsroot/tools/org.eclipse.gef/examples/org.eclipse.draw2d.examples/src/org/eclipse/draw2d/examples/graph/CompoundGraphTests.java,v >retrieving revision 1.9 >diff -u -r1.9 CompoundGraphTests.java >--- src/org/eclipse/draw2d/examples/graph/CompoundGraphTests.java 15 Mar 2007 12:32:15 -0000 1.9 >+++ src/org/eclipse/draw2d/examples/graph/CompoundGraphTests.java 4 Mar 2008 16:22:01 -0000 >@@ -1,5 +1,5 @@ > /******************************************************************************* >- * Copyright (c) 2005, 2007 IBM Corporation and others. >+ * Copyright (c) 2005, 2008 IBM Corporation and others. > * All rights reserved. This program and the accompanying materials > * are made available under the terms of the Eclipse Public License v1.0 > * which accompanies this distribution, and is available at >@@ -158,6 +158,23 @@ > } > > public static CompoundDirectedGraph flowChart() { >+ CompoundDirectedGraph graph = createFlowChartGraph(); >+ new CompoundDirectedGraphLayout() >+ .visit(graph); >+ return graph; >+} >+ >+public static CompoundDirectedGraph flowChartOrthogonalEdges() { >+ CompoundDirectedGraph graph = createFlowChartGraph(); >+ for (int i = 0; i < graph.edges.size(); i++) { >+ graph.edges.getEdge(i).setRoutingStyle(Edge.ORTHOGONAL_ROUTING_STYLE); >+ } >+ new CompoundDirectedGraphLayout() >+ .visit(graph); >+ return graph; >+} >+ >+private static CompoundDirectedGraph createFlowChartGraph() { > NodeList nodes = new NodeList(); > EdgeList edges = new EdgeList(); > >@@ -272,9 +289,6 @@ > CompoundDirectedGraph graph = new CompoundDirectedGraph(); > graph.nodes = nodes; > graph.edges = edges; >- >- new CompoundDirectedGraphLayout() >- .visit(graph); > return graph; > } > >@@ -516,4 +530,45 @@ > return graph; > } > >+public static CompoundDirectedGraph variousHeightNodesGraph() { >+ Subgraph s, s1, s2; >+ Node n1, n2, n3, n4, n5; >+ Node n6, n7; >+ NodeList nodes = new NodeList(); >+ EdgeList edges = new EdgeList(); >+ >+ nodes.add(s = new Subgraph("diagram")); >+ nodes.add(s1 = new Subgraph("subgraph 1", s)); >+ nodes.add(s2 = new Subgraph("subgraph 2", s)); >+ >+ nodes.add(n1 = new Node("1", s1)); >+ nodes.add(n2 = new Node("2", s1)); >+ nodes.add(n3 = new Node("3", s1)); >+ nodes.add(n4 = new Node("4", s1)); >+ nodes.add(n5 = new Node("5", s1)); >+ nodes.add(n6 = new Node("6", s2)); >+ nodes.add(n7 = new Node("7", s2)); >+ >+ n1.width = n4.width = n5.width = n6.width = n6.height = n7.width = n7.height = 50; >+ n2.width = n3.width = 120; >+ n1.height = n4.height = n5.height = 30; >+ n2.height = n3.height = 400; >+ >+ edges.add(new Edge(n1, n5)); >+ edges.add(new Edge(n2, n5)); >+ edges.add(new Edge(n3, n5)); >+ edges.add(new Edge(n4, n5)); >+ edges.add(new Edge(n2, n7)); >+ edges.add(new Edge(n4, n6)); >+ edges.add(new Edge(s1, s2)); >+ >+ CompoundDirectedGraph graph = new CompoundDirectedGraph(); >+ graph.nodes = nodes; >+ graph.edges = edges; >+ >+ new CompoundDirectedGraphLayout() >+ .visit(graph); >+ return graph; >+} >+ > }
You cannot view the attachment while viewing its details because your browser does not support IFRAMEs.
View the attachment on a separate page
.
View Attachment As Diff
View Attachment As Raw
Actions:
View
|
Diff
Attachments on
bug 221214
:
91437
|
91531
|
91537