1 19 20 21 package ca.mcgill.sable.soot.cfg.editParts; 22 23 import org.eclipse.gef.editparts.AbstractConnectionEditPart; 24 import org.eclipse.draw2d.*; 25 import org.eclipse.draw2d.graph.*; 26 import java.util.*; 27 import ca.mcgill.sable.soot.cfg.model.*; 28 import java.beans.*; 29 30 public class CFGEdgeEditPart extends AbstractConnectionEditPart 31 { 32 33 34 public CFGEdgeEditPart() { 35 super(); 36 } 37 38 41 protected void createEditPolicies() { 42 } 43 44 protected IFigure createFigure(){ 45 PolylineConnection conn = new PolylineConnection(); 46 47 conn.setTargetDecoration(new PolygonDecoration()); 48 conn.setConnectionRouter(new BendpointConnectionRouter()); 49 return conn; 50 } 51 52 public void contributeToGraph(DirectedGraph graph, HashMap map){ 53 Node source = (Node)map.get(getSource()); 54 Node target = (Node)map.get(getTarget()); 55 if (!source.equals(target)){ 56 Edge e = new Edge(this, source, target); 57 graph.edges.add(e); 58 map.put(this, e); 59 } 60 } 61 62 public void applyGraphResults(DirectedGraph graph, HashMap map){ 63 Edge e = (Edge)map.get(this); 64 if (e != null) { 65 NodeList nl = e.vNodes; 66 PolylineConnection conn = (PolylineConnection)getConnectionFigure(); 67 if (nl != null){ 68 ArrayList bends = new ArrayList(); 69 for (int i = 0; i < nl.size(); i++){ 70 Node n = nl.getNode(i); 71 int x = n.x; 72 int y = n.y; 73 if (e.isFeedback){ 74 bends.add(new AbsoluteBendpoint(x, y + n.height)); 75 bends.add(new AbsoluteBendpoint(x, y)); 76 } 77 else { 78 bends.add(new AbsoluteBendpoint(x, y)); 79 bends.add(new AbsoluteBendpoint(x, y + n.height)); 80 } 81 } 82 conn.setRoutingConstraint(bends); 83 } 84 else { 85 conn.setRoutingConstraint(Collections.EMPTY_LIST); 86 } 87 } 88 else { 89 PolylineConnection conn = (PolylineConnection)getConnectionFigure(); 90 Node n = (Node)map.get(getSource()); 91 ArrayList bends = new ArrayList(); 92 bends.add(new AbsoluteBendpoint(n.width/2 + n.x + 8, n.y + n.height + 8)); 93 bends.add(new AbsoluteBendpoint(n.width + n.x + 8, n.y + n.height + 8)); 94 bends.add(new AbsoluteBendpoint(n.x + n.width + 8, n.y - 16)); 95 bends.add(new AbsoluteBendpoint(n.x + n.width/2 + 16, n.y - 16)); 96 97 conn.setRoutingConstraint(bends); 98 } 99 } 100 101 102 public CFGEdge getEdge(){ 103 return (CFGEdge)getModel(); 104 } 105 106 107 } 108 | Popular Tags |