[jboss-cvs] JBossAS SVN: r91053 - in projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher: graph and 1 other directories.

jboss-cvs-commits at lists.jboss.org jboss-cvs-commits at lists.jboss.org
Fri Jul 10 05:24:13 EDT 2009


Author: alesj
Date: 2009-07-10 05:24:13 -0400 (Fri, 10 Jul 2009)
New Revision: 91053

Added:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/routing/
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/routing/ParallelSplineRouter.java
Modified:
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java
   projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
Log:
Edge routing.

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java	2009-07-10 09:05:25 UTC (rev 91052)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/GrapherConstants.java	2009-07-10 09:24:13 UTC (rev 91053)
@@ -25,6 +25,8 @@
 import org.jboss.mctools.grapher.layout.ReflectionGraphLayout;
 import org.jboss.mctools.grapher.map.DefaultGraphCreatorMapper;
 import org.jboss.mctools.grapher.map.GraphCreatorMapper;
+import org.jboss.mctools.grapher.routing.ParallelSplineRouter;
+import org.jgraph.graph.Edge;
 
 /**
  * Grapher constants.
@@ -45,4 +47,7 @@
 
    /** The default layout */
    public static final GraphLayout LAYOUT = new ReflectionGraphLayout("com.jgraph.layout.graph.JGraphFRLayout");
+
+   /** The edge routing */
+   public static final Edge.Routing ROUTING = ParallelSplineRouter.getInstance(); 
 }
\ No newline at end of file

Modified: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java	2009-07-10 09:05:25 UTC (rev 91052)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/graph/AbstractGraphCreator.java	2009-07-10 09:24:13 UTC (rev 91053)
@@ -35,6 +35,7 @@
 import org.jboss.dependency.spi.DependencyItem;
 import org.jboss.kernel.spi.dependency.KernelController;
 import org.jboss.logging.Logger;
+import org.jboss.mctools.grapher.GrapherConstants;
 import org.jgraph.JGraph;
 import org.jgraph.graph.AttributeMap;
 import org.jgraph.graph.ConnectionSet;
@@ -187,6 +188,7 @@
             int arrow = GraphConstants.ARROW_CLASSIC;
             GraphConstants.setLineEnd(edge.getAttributes(), arrow);
             GraphConstants.setEndFill(edge.getAttributes(), true);
+            GraphConstants.setRouting(edge.getAttributes(), GrapherConstants.ROUTING);
 
             objects.add(edge);
 

Added: projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/routing/ParallelSplineRouter.java
===================================================================
--- projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/routing/ParallelSplineRouter.java	                        (rev 0)
+++ projects/mc-tools/grapher/trunk/src/main/java/org/jboss/mctools/grapher/routing/ParallelSplineRouter.java	2009-07-10 09:24:13 UTC (rev 91053)
@@ -0,0 +1,163 @@
+/**
+ * User: alesj
+ * Date: 2004.12.1
+ * Time: 9:31:22
+ */
+
+package org.jboss.mctools.grapher.routing;
+
+import java.awt.geom.Point2D;
+import java.util.ArrayList;
+import java.util.List;
+
+import org.jgraph.graph.DefaultEdge;
+import org.jgraph.graph.DefaultGraphModel;
+import org.jgraph.graph.Edge;
+import org.jgraph.graph.EdgeView;
+import org.jgraph.graph.GraphConstants;
+import org.jgraph.graph.GraphLayoutCache;
+import org.jgraph.graph.GraphModel;
+import org.jgraph.graph.PortView;
+
+/**
+ * Paralled edge routing.
+ * Taken from JGraphPad.
+ *
+ * @author <a href="mailto:ales.justin at jboss.org">Ales Justin</a>
+ */
+public class ParallelSplineRouter extends DefaultEdge.LoopRouting
+{
+   protected static GraphModel emptyModel = new DefaultGraphModel();
+
+   private static Edge.Routing instance = new ParallelSplineRouter();
+
+   /**
+    * The distance between the control point and the middle line. A larger
+    * number will lead to a more "bubbly" appearance of the bezier edges.
+    */
+   private double edgeSeparation = 25;
+
+   private ParallelSplineRouter()
+   {
+   }
+
+   /**
+    * @return Returns the sharedInstance.
+    */
+   public static Edge.Routing getInstance()
+   {
+      return instance;
+	}
+
+   /**
+    * Returns the array of parallel edges.
+    *
+    * @param edge the edge view
+    * @return cells
+    */
+   public Object[] getParallelEdges(EdgeView edge)
+   {
+      // FIXME: The model is stored in the cells only in the default
+      // implementations. Otherwise we must use the real model here.
+      return DefaultGraphModel.getEdgesBetween(emptyModel, edge.getSource()
+            .getParentView().getCell(), edge.getTarget().getParentView()
+            .getCell(), false);
+   }
+
+   @SuppressWarnings("unchecked")
+   public List routeEdge(GraphLayoutCache cache, EdgeView edge)
+   {
+      List newPoints = new ArrayList();
+
+      // Check presence of source/target nodes
+      if ((null == edge.getSource()) || (null == edge.getTarget())
+            || (null == edge.getSource().getParentView())
+            || (null == edge.getTarget().getParentView()))
+      {
+         return null;
+      }
+      newPoints.add(edge.getSource());
+
+      Object[] edges = getParallelEdges(edge);
+      // Find the position of the current edge that we are currently routing
+      if (edges == null)
+         return null;
+      int position = 0;
+      for (int i = 0; i < edges.length; i++)
+      {
+         Object e = edges[i];
+         if (e == edge.getCell())
+         {
+            position = i;
+         }
+      }
+
+      // If there is only 1 edge between the two vertices, we don't need this
+      // special routing
+      if (edges.length >= 2)
+      {
+
+         // Find the end point positions
+         Point2D from = ((PortView)edge.getSource()).getLocation();
+         Point2D to = ((PortView)edge.getTarget()).getLocation();
+
+         if (from != null && to != null)
+         {
+            // calculate mid-point of the main edge
+            double midX = Math.min(from.getX(), to.getX())
+                  + Math.abs((from.getX() - to.getX()) / 2);
+            double midY = Math.min(from.getY(), to.getY())
+                  + Math.abs((from.getY() - to.getY()) / 2);
+
+            // compute the normal slope. The normal of a slope is the
+            // negative
+            // inverse of the original slope.
+            double m = (from.getY() - to.getY())
+                  / (from.getX() - to.getX());
+            double theta = Math.atan(-1 / m);
+
+            // modify the location of the control point along the axis of
+            // the
+            // normal using the edge position
+            double r = edgeSeparation * (Math.floor(position / 2) + 1);
+            if ((position % 2) == 0)
+            {
+               r = -r;
+            }
+
+            // convert polar coordinates to cartesian and translate axis to
+            // the
+            // mid-point
+            double ex = r * Math.cos(theta) + midX;
+            double ey = r * Math.sin(theta) + midY;
+            Point2D controlPoint = new Point2D.Double(ex, ey);
+
+            // add the control point to the points list
+            newPoints.add(controlPoint);
+         }
+      }
+      newPoints.add(edge.getTarget());
+      return newPoints;
+   }
+
+   public int getEdgeStyle()
+   {
+      return GraphConstants.STYLE_SPLINE;
+   }
+
+   /**
+    * @return Returns the edgeSeparation.
+    */
+   public double getEdgeSeparation()
+   {
+      return edgeSeparation;
+   }
+
+   /**
+    * @param edgeSeparation The edgeSeparation to set.
+    */
+   public void setEdgeSeparation(double edgeSeparation)
+   {
+      this.edgeSeparation = edgeSeparation;
+   }
+}
\ No newline at end of file




More information about the jboss-cvs-commits mailing list