KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > cfg > figures > CFGNodeDataFigure


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 package ca.mcgill.sable.soot.cfg.figures;
21
22 import org.eclipse.draw2d.*;
23 import java.util.*;
24 import org.eclipse.swt.*;
25 import org.eclipse.swt.graphics.*;
26 import ca.mcgill.sable.soot.*;
27 import org.eclipse.draw2d.text.*;
28 import ca.mcgill.sable.soot.editors.*;
29 import org.eclipse.draw2d.geometry.*;
30 import org.eclipse.jface.resource.*;
31
32 public class CFGNodeDataFigure extends Figure {
33
34     private Panel nodeFigure;//RectangleFigure rect;
35
private RectangleFigure rect;
36     
37     private ArrayList data;
38     
39     
40     Font f = new Font(null, "Arial", 8, SWT.NORMAL);
41         
42
43     public CFGNodeDataFigure() {
44         super();
45         setRect(new RectangleFigure());
46     
47         this.add(getRect());
48         
49         getRect().setBackgroundColor(SootPlugin.getDefault().getColorManager().getColor(new RGB(255, 255 ,255)));
50         ToolbarLayout layout = new ToolbarLayout();
51         layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
52         layout.setVertical(false);
53         
54         this.setLayoutManager(layout);
55         
56         getRect().setLayoutManager(layout);
57     }
58     
59
60     private soot.Unit unit;
61     
62     public void updateFigure(){
63         if (getData() == null) return;
64         
65         int height = 0;
66         int width = 0;
67         Iterator it = getData().iterator();
68         while (it.hasNext()){
69             unit = (soot.Unit)it.next();
70             String JavaDoc next = unit.toString();
71             
72             Label l = new Label(next);
73             l.setFont(f);
74             l.getInsets().top = 1;
75             l.getInsets().bottom = 1;
76             l.getInsets().right = 1;
77             l.getInsets().left = 1;
78             height = height + l.getSize().height/2;
79             int length = next.length()*7;
80             width = length > width ? length : width;
81             getRect().add(l);
82             
83         }
84             
85         getRect().setSize(width+10, height+10);
86         this.setSize(width+10, height+10);
87         
88     }
89
90     
91     /**
92      * @return
93      */

94     public RectangleFigure getRect() {
95         return rect;
96     }
97
98     Image stopImage = null;
99     Image highlightImage = null;
100     
101     public void addStopIcon(){
102         if (stopImage == null){
103             ImageDescriptor desc = SootPlugin.getImageDescriptor("stop_icon.gif");
104             stopImage = desc.createImage();
105         }
106         ((Label)getRect().getChildren().get(0)).setIcon(stopImage);
107     }
108     
109     Label indicatorLabel;
110     
111     public void addIndicator(){
112         if (highlightImage == null){
113             ImageDescriptor desc = SootPlugin.getImageDescriptor("indicator.gif");
114             highlightImage = desc.createImage();
115         }
116         
117         indicatorLabel = new Label(highlightImage);
118         this.add(indicatorLabel, 0);
119     }
120     
121     public void removeIndicator(){
122         if (this.getChildren().get(0).equals(indicatorLabel)){
123             this.remove(indicatorLabel);
124         }
125     }
126     
127     public void removeStopIcon(){
128         ((Label)getRect().getChildren().get(0)).setIcon(null);
129     }
130     
131     
132
133     /**
134      * @return
135      */

136     public ArrayList getData() {
137         return data;
138     }
139
140     /**
141      * @param list
142      */

143     public void setData(ArrayList list) {
144         data = list;
145     }
146
147
148     /**
149      * @param figure
150      */

151     public void setRect(RectangleFigure figure) {
152         rect = figure;
153     }
154
155     
156     /**
157      * @return
158      */

159     public soot.Unit getUnit() {
160         return unit;
161     }
162
163     /**
164      * @param unit
165      */

166     public void setUnit(soot.Unit unit) {
167         this.unit = unit;
168     }
169
170 }
171
Popular Tags