KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > callgraph > CallGraphNodeEditPart


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.callgraph;
21
22 import ca.mcgill.sable.graph.editparts.SimpleNodeEditPart;
23 import org.eclipse.draw2d.*;
24 import org.eclipse.draw2d.geometry.*;
25 import java.util.*;
26 import org.eclipse.swt.*;
27 import org.eclipse.swt.graphics.*;
28 import soot.*;
29 import org.eclipse.jface.resource.*;
30 import ca.mcgill.sable.soot.*;
31
32
33 public class CallGraphNodeEditPart extends SimpleNodeEditPart {
34
35     
36     public CallGraphNodeEditPart() {
37         super();
38     }
39     Font f = new Font(null, "Arial", 8, SWT.NORMAL);
40     
41     
42     /* (non-Javadoc)
43      * @see org.eclipse.gef.editparts.AbstractGraphicalEditPart#createFigure()
44      */

45     protected IFigure createFigure() {
46         RectangleFigure rect = new RectangleFigure();
47         ToolbarLayout layout = new ToolbarLayout();
48         layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER);
49         rect.setLayoutManager(layout);
50         
51         Label cLabel = new Label();
52         cLabel.setFont(f);
53         cLabel.getInsets().bottom = 1;
54         cLabel.getInsets().top = 1;
55         cLabel.getInsets().left = 1;
56         cLabel.getInsets().right = 1;
57
58         rect.add(cLabel);
59         
60         Label mLabel = new Label();
61         mLabel.setFont(f);
62         mLabel.getInsets().bottom = 1;
63         mLabel.getInsets().top = 1;
64         mLabel.getInsets().left = 1;
65         mLabel.getInsets().right = 1;
66         
67         
68         rect.add(mLabel);
69         
70         return rect;
71     }
72     
73     Image publicImage = null;
74     Image privateImage = null;
75     Image protectedImage = null;
76     
77     protected void loadImages(){
78         if (publicImage == null){
79             ImageDescriptor desc = SootPlugin.getImageDescriptor("public_co.gif");
80             publicImage = desc.createImage();
81         }
82         if (protectedImage == null){
83             ImageDescriptor desc = SootPlugin.getImageDescriptor("protected_co.gif");
84             protectedImage = desc.createImage();
85         }
86         if (privateImage == null){
87             ImageDescriptor desc = SootPlugin.getImageDescriptor("private_co.gif");
88             privateImage = desc.createImage();
89         }
90     }
91     
92     protected void refreshVisuals(){
93     
94         Label cLabel = (Label)getFigure().getChildren().get(0);
95         Label mLabel = (Label)getFigure().getChildren().get(1);
96         if (getData() != null){
97             SootMethod currMeth = (SootMethod)getData();
98             String JavaDoc c = currMeth.getSignature().substring(0, currMeth.getSignature().indexOf(":")+1);
99             String JavaDoc m = currMeth.getSignature().substring(currMeth.getSignature().indexOf(":")+1);
100             cLabel.setText(c);
101             mLabel.setText(m);
102             int len = m.length() > c.length() ? m.length() : c.length();
103             getFigure().setSize(len*7-6, 38);
104             loadImages();
105             Image image = null;
106             if (currMeth.isPublic()){
107                 image = publicImage;
108             }
109             else if (currMeth.isProtected()){
110                 image = protectedImage;
111             }
112             else {
113                 image = privateImage;
114             }
115             ((Label)getFigure().getChildren().get(0)).setIcon(image);
116             getFigure().revalidate();
117             
118         }
119         
120     }
121
122     
123     
124     public void expandGraph(){
125         ((CallGraphNode)getNode()).getGenerator().expandGraph((CallGraphNode)getNode());
126     }
127     
128     public void collapseGraph(){
129         ((CallGraphNode)getNode()).getGenerator().collapseGraph((CallGraphNode)getNode());
130     }
131     
132     public void showInCode(){
133         ((CallGraphNode)getNode()).getGenerator().showInCode((CallGraphNode)getNode());
134     }
135 }
136
137
Popular Tags