1 package com.opensymphony.workflow.designer.views; 2 3 import java.awt.Point ; 4 import java.awt.geom.Point2D ; 5 import java.awt.geom.Rectangle2D ; 6 7 import org.jgraph.graph.Edge; 8 import org.jgraph.graph.EdgeView; 9 import org.jgraph.graph.PortView; 10 11 import com.opensymphony.workflow.designer.WorkflowPort; 12 13 18 public class EdgeRouter implements Edge.Routing 19 { 20 public void route(EdgeView edge, java.util.List points) 21 { 22 PortView sourceView = (PortView)edge.getSource(); 23 PortView targetView = (PortView)edge.getTarget(); 24 if(sourceView==null || targetView==null) return; 25 26 WorkflowPort sourcePort = (WorkflowPort)sourceView.getCell(); 27 WorkflowPort targetPort = (WorkflowPort)targetView.getCell(); 28 Point2D from = sourceView.getLocation(null); 29 Point2D to = targetView.getLocation(null); 30 if(from != null && to != null) 46 { 47 Point [] routed; 48 if(sourcePort == targetPort) 50 { 51 Rectangle2D bounds = sourceView.getParentView().getBounds(); 52 int size = 35; 53 routed = new Point [4]; 54 routed[0] = new Point ((int)(bounds.getX() + bounds.getWidth()), (int)(bounds.getY() + bounds.getHeight())); 55 routed[1] = new Point ((int)(bounds.getX() + bounds.getWidth()), (int)(bounds.getY() + bounds.getHeight() + size)); 56 routed[2] = new Point ((int)(bounds.getX() + size + bounds.getWidth()), (int)(bounds.getY() + bounds.getHeight() + size)); 57 routed[3] = new Point ((int)(bounds.getX() + size + bounds.getWidth()), (int)(bounds.getY() + bounds.getHeight())); 58 } 59 else 60 { 61 double dx = Math.abs(from.getX() - to.getX()); 62 double dy = Math.abs(from.getY() - to.getY()); 63 double x2 = from.getX() + ((to.getX() - from.getX()) / 2); 64 double y2 = from.getY() + ((to.getY() - from.getY()) / 2); 65 routed = new Point [2]; 66 if(dx > dy) 67 { 68 routed[0] = new Point ((int)x2, (int)from.getY()); 69 routed[1] = new Point ((int)x2, (int)to.getY()); 70 } 71 else 72 { 73 routed[0] = new Point ((int)from.getX(), (int)y2); 74 routed[1] = new Point ((int)to.getX(), (int)y2); 75 } 76 } 77 for(int i = 0; i < routed.length; i++) 79 if(points.size() > i + 2) 80 points.set(i + 1, routed[i]); 81 else 82 points.add(i + 1, routed[i]); 83 while(points.size() > routed.length + 2) 85 { 86 points.remove(points.size() - 2); 87 } 88 } 89 } 90 91 } 92 | Popular Tags |