KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > cfg > editParts > CFGEdgeEditPart


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2004 Jennifer Lhotak
3  *
4  * This library is free software; you can redistribute it and/or
5  * modify it under the terms of the GNU Lesser General Public
6  * License as published by the Free Software Foundation; either
7  * version 2.1 of the License, or (at your option) any later version.
8  *
9  * This library is distributed in the hope that it will be useful,
10  * but WITHOUT ANY WARRANTY; without even the implied warranty of
11  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12  * Lesser General Public License for more details.
13  *
14  * You should have received a copy of the GNU Lesser General Public
15  * License along with this library; if not, write to the
16  * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
17  * Boston, MA 02111-1307, USA.
18  */

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     /* (non-Javadoc)
39      * @see org.eclipse.gef.editparts.AbstractEditPart#createEditPolicies()
40      */

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