KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > cfg > CFGEditor


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;
22
23 import org.eclipse.core.resources.*;
24 import org.eclipse.core.runtime.IProgressMonitor;
25 import org.eclipse.ui.*;
26 import org.eclipse.gef.ui.parts.*;
27 import org.eclipse.gef.*;
28 import org.eclipse.gef.editparts.*;
29 import ca.mcgill.sable.soot.cfg.model.*;
30 import ca.mcgill.sable.soot.cfg.editParts.*;
31 //import org.eclipse.gef.palette.*;
32
import org.eclipse.jface.action.*;
33 import org.eclipse.gef.ui.actions.*;
34
35 public class CFGEditor extends GraphicalEditor {
36
37     private CFGGraph cfgGraph;
38     
39     public CFGEditor() {
40         DefaultEditDomain defaultEditDomain = new DefaultEditDomain(this);
41         setEditDomain(defaultEditDomain);
42         
43     }
44
45     /* (non-Javadoc)
46      * @see org.eclipse.gef.ui.parts.GraphicalEditor#initializeGraphicalViewer()
47      */

48     protected void initializeGraphicalViewer() {
49         getGraphicalViewer().setContents(cfgGraph);
50
51     }
52     
53     protected void configureGraphicalViewer() {
54         super.configureGraphicalViewer();
55         ScalableRootEditPart root = new ScalableRootEditPart();
56         getGraphicalViewer().setRootEditPart(root);
57         
58         ZoomManager zManager = root.getZoomManager();
59         double [] zoomLevels = new double[10];
60         for (int i = 0; i < zoomLevels.length; i++){
61             zoomLevels[i] = (i + 1) * 0.25;
62         }
63         zManager.setZoomLevels(zoomLevels);
64         IAction zoomIn = new ZoomInAction(zManager);
65         IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager());
66
67         getActionRegistry().registerAction(zoomIn);
68         getActionRegistry().registerAction(zoomOut);
69         
70         getSite().getKeyBindingService().registerAction(zoomIn);
71         getSite().getKeyBindingService().registerAction(zoomOut);
72     
73     
74         getGraphicalViewer().setEditPartFactory(new CFGPartFactory());
75         getGraphicalViewer().setKeyHandler(new GraphicalViewerKeyHandler(getGraphicalViewer()));
76         
77         StopAction stop = new StopAction(this);
78         getActionRegistry().registerAction(stop);
79         this.getSelectionActions().add(stop.getId());
80         
81         UnStopAction unStop = new UnStopAction(this);
82         getActionRegistry().registerAction(unStop);
83         this.getSelectionActions().add(unStop.getId());
84         
85         
86         CFGMenuProvider menuProvider = new CFGMenuProvider(getGraphicalViewer(), getActionRegistry(), this);
87         getGraphicalViewer().setContextMenu(menuProvider);
88         getSite().registerContextMenu(menuProvider, getGraphicalViewer());
89     
90     }
91     
92     // this is for zoom
93
protected void createActions(){
94     
95         super.createActions();
96         
97     /* System.out.println("creating actions");
98         ScrollingGraphicalViewer viewer = (ScrollingGraphicalViewer)getGraphicalViewer();
99         ScalableRootEditPart root = ((ScalableRootEditPart)viewer.getRootEditPart());
100         ZoomManager zManager = root.getZoomManager();
101         
102         IAction zoomIn = new ZoomInAction(zManager);
103         IAction zoomOut = new ZoomOutAction(((ScalableRootEditPart)getGraphicalViewer().getRootEditPart()).getZoomManager());
104
105         getActionRegistry().registerAction(zoomIn);
106         getActionRegistry().registerAction(zoomOut);
107         
108         getSite().getKeyBindingService().registerAction(zoomIn);
109         getSite().getKeyBindingService().registerAction(zoomOut);
110     */

111     
112     }
113
114     protected void setInput(IEditorInput input){
115         super.setInput(input);
116         if (input instanceof CFGGraph){
117             setCfgGraph((CFGGraph)input);
118         }
119         // could also read from a dot file
120

121     }
122     
123     /* (non-Javadoc)
124      * @see org.eclipse.ui.ISaveablePart#doSave(org.eclipse.core.runtime.IProgressMonitor)
125      */

126     public void doSave(IProgressMonitor monitor) {
127         // TODO Auto-generated method stub
128
/*System.out.println("saving cfgs");
129         // idea is to save to dot file
130         String fileNameBase = SootPlugin.getDefault().getCurrentProject().getFolder("sootOutput").getLocation().toOSString();
131         
132         AnnotatedCFGSaver saver = new AnnotatedCFGSaver(getCfgGraph(), fileNameBase, this.getTitle());
133         saver.saveGraph();
134         isSaved = true;
135         firePropertyChange(IEditorPart.PROP_DIRTY);
136     */

137     }
138
139     /*public void setContentsChanged(){
140         isSaved = false;
141         firePropertyChange(IEditorPart.PROP_DIRTY);
142     }*/

143     /* (non-Javadoc)
144      * @see org.eclipse.ui.ISaveablePart#doSaveAs()
145      */

146     public void doSaveAs() {
147         // TODO Auto-generated method stub
148

149     }
150
151     /* (non-Javadoc)
152      * @see org.eclipse.ui.IEditorPart#gotoMarker(org.eclipse.core.resources.IMarker)
153      */

154     public void gotoMarker(IMarker marker) {
155         // TODO Auto-generated method stub
156

157     }
158
159     /* (non-Javadoc)
160      * @see org.eclipse.ui.ISaveablePart#isDirty()
161      */

162     public boolean isDirty() {
163         // TODO Auto-generated method stub
164
//return !isSaved;
165
return false;
166     }
167
168     /* (non-Javadoc)
169      * @see org.eclipse.ui.ISaveablePart#isSaveAsAllowed()
170      */

171     public boolean isSaveAsAllowed() {
172         // TODO Auto-generated method stub
173
return false;
174     }
175
176
177     /**
178      * @return
179      */

180     public CFGGraph getCfgGraph() {
181         return cfgGraph;
182     }
183
184     /**
185      * @param graph
186      */

187     public void setCfgGraph(CFGGraph graph) {
188         cfgGraph = graph;
189     }
190
191     public void setTitle(String JavaDoc name){
192         super.setTitle(name);
193     }
194     
195     public void setTitleTooltip(String JavaDoc text){
196         super.setTitleToolTip(text);
197     }
198     
199     public String JavaDoc getToolTipText(){
200         return "cfg editor";
201     }
202     
203
204     
205     
206 }
207
Popular Tags