1 19 20 package ca.mcgill.sable.soot.cfg; 21 22 import org.eclipse.ui.*; 23 import org.eclipse.jface.action.*; 24 import org.eclipse.jface.viewers.*; 25 import org.eclipse.swt.widgets.Shell; 26 import org.eclipse.swt.widgets.Display; 27 import org.eclipse.draw2d.*; 28 import org.eclipse.draw2d.graph.*; 29 import org.eclipse.draw2d.geometry.*; 30 import java.util.*; 31 32 33 public class CFGTests implements IWorkbenchWindowActionDelegate { 34 35 public void run(IAction action){ 36 Shell shell = new Shell(); 37 shell.open(); 38 shell.setText("CFG Test"); 39 40 LightweightSystem lws = new LightweightSystem(shell); 41 Panel p = new Panel(); 42 p.setBounds(new Rectangle(0,0,-1,-1)); 43 lws.setContents(p); 44 HashMap nodeMap = new HashMap(); 45 DirectedGraph dg = makeSimpleGraph(); 46 Iterator nIt = dg.nodes.iterator(); 47 while (nIt.hasNext()){ 48 Node nextNode = (Node)nIt.next(); 49 IFigure node = new RectangleFigure(); 50 IFigure label = new Label((String )nextNode.data); 51 label.setSize(nextNode.width, 36); 52 node.add(label); 53 int len = ((String )nextNode.data).length() * 5; 54 node.setLocation(new Point(nextNode.x, nextNode.y)); 55 node.setSize(nextNode.width, 36); 56 System.out.println("bounds: "+node.getBounds()); 57 p.add(node); 58 nodeMap.put(nextNode, node); 59 } 60 Iterator eIt = dg.edges.iterator(); 61 while (eIt.hasNext()){ 62 Edge nextEdge = (Edge)eIt.next(); 63 PolylineConnection edge = new PolylineConnection(); 64 ChopboxAnchor ca1 = new ChopboxAnchor((IFigure)nodeMap.get(nextEdge.source)); 65 ChopboxAnchor ca2 = new ChopboxAnchor((IFigure)nodeMap.get(nextEdge.target)); 66 67 edge.setSourceAnchor(ca1); 68 edge.setTargetAnchor(ca2); 69 edge.setTargetDecoration(new PolygonDecoration()); 70 p.add(edge); 71 } 72 lws.setContents(p); 73 Display display = Display.getDefault(); 74 while (!shell.isDisposed ()) { 75 if (!display.readAndDispatch ()) 76 display.sleep (); 77 } 78 } 79 80 public DirectedGraph makeSimpleGraph(){ 81 NodeList nl = new NodeList(); 82 Node n1 = new Node(); 83 String data = "y = 3"; 84 n1.data = data; 85 n1.width = data.length() * 7; 86 nl.add(n1); 87 Node n2 = new Node(); 88 data = "if i >= 10 goto L0"; 89 n2.data = data; 90 n2.width = data.length() * 7; 91 nl.add(n2); 92 Node n3 = new Node(); 93 data = "if i != 0 goto L1"; 94 n3.data = data; 95 n3.width = data.length() * 7; 96 nl.add(n3); 97 Node n4 = new Node(); 98 data = "x = 5"; 99 n4.data = data; 100 n4.width = data.length() * 7; 101 nl.add(n4); 102 EdgeList el = new EdgeList(); 103 Edge e1 = new Edge(n1, n2); 104 el.add(e1); 105 Edge e2 = new Edge(n2, n3); 106 el.add(e2); 107 Edge e3 = new Edge(n2, n4); 108 el.add(e3); 109 DirectedGraph dg = new DirectedGraph(); 110 dg.edges = el; 111 dg.nodes = nl; 112 DirectedGraphLayout dgl = new DirectedGraphLayout(); 113 dgl.visit(dg); 114 return dg; 115 } 116 117 public void selectionChanged(IAction action, ISelection selection){ 118 119 } 120 121 public void dispose(){ 122 123 } 124 125 public void init(IWorkbenchWindow window){ 126 127 } 128 129 132 public CFGTests() { 133 super(); 134 } 136 137 } 138 | Popular Tags |