KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > SootPlugin


1 /* Soot - a J*va Optimization Framework
2  * Copyright (C) 2003 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;
21
22 import org.eclipse.ui.PlatformUI;
23 import org.eclipse.ui.plugin.*;
24 import org.eclipse.core.runtime.*;
25 import org.eclipse.core.resources.*;
26 import org.eclipse.jface.preference.*;
27 import org.eclipse.jface.resource.*;
28 import org.eclipse.jface.text.source.ISourceViewer;
29 import org.eclipse.swt.graphics.*;
30 import org.eclipse.swt.*;
31
32 import java.net.*;
33 import java.util.*;
34
35 import ca.mcgill.sable.soot.editors.ColorManager;
36 import ca.mcgill.sable.soot.launching.*;
37 import ca.mcgill.sable.soot.resources.*;
38 import ca.mcgill.sable.soot.interaction.*;
39
40
41
42 /**
43  * The main plugin class to be used in the desktop.
44  */

45 public class SootPlugin extends AbstractUIPlugin {
46     //The shared instance.
47
private static SootPlugin plugin;
48     //Resource bundle.
49
private ResourceBundle resourceBundle;
50     
51     // used for showing soot ouptut
52
private SootDocument soot_output_doc;
53     
54     // listeners for soot output events
55
private Vector sootOutputEventListeners = new Vector();
56     
57     // list of jimple editor viewers
58
private ArrayList editorViewers = new ArrayList();
59     
60     private SootPartManager partManager;
61     
62     private ColorManager colorManager;
63     
64     private DataKeeper dataKeeper;
65     
66     private Font sootFont = new Font(null, "Arial", 8, SWT.NORMAL);
67     
68     private IProject currentProject;
69     
70     /**
71      * Method addSootOutputEventListener.
72      * @param listener
73      */

74     public void addSootOutputEventListener(ISootOutputEventListener listener) {
75         sootOutputEventListeners.add(listener);
76     }
77     
78     /**
79      * Method removeSootOutputEventListener.
80      * @param listener
81      */

82     public void removeSootOutputEventListener(ISootOutputEventListener listener) {
83         sootOutputEventListeners.remove(listener);
84     }
85     
86     /**
87      * Method fireSootOutputEvent.
88      * @param event
89      */

90     public void fireSootOutputEvent(SootOutputEvent event) {
91         Iterator it = sootOutputEventListeners.iterator();
92         while (it.hasNext()) {
93             ((ISootOutputEventListener)it.next()).handleSootOutputEvent(event);
94         }
95     }
96     
97     /**
98      * The constructor.
99      */

100     public SootPlugin(IPluginDescriptor descriptor) {
101         super(descriptor);
102         plugin = this;
103         // should work from startUp method
104
soot_output_doc = new SootDocument();
105         soot_output_doc.startUp();
106     
107         try {
108             resourceBundle= ResourceBundle.getBundle(ISootConstants.SOOT_PLUGIN_RESOURCES_ID);
109         } catch (MissingResourceException x) {
110             resourceBundle = null;
111         }
112         
113         // maybe should go in startUp method
114
// resource manager
115
setManager(new SootResourceManager());
116         
117         PlatformUI.getWorkbench().addWindowListener(new SootWorkbenchListener());
118         setPartManager(new SootPartManager());
119     }
120     
121     // used for getting any needed images for content outline
122
// and possibly for attribute markers
123
public static ImageDescriptor getImageDescriptor(String JavaDoc name){
124         try {
125             URL installURL = getDefault().getDescriptor().getInstallURL();
126             URL iconURL = new URL(installURL, ISootConstants.ICON_PATH + name);
127             return ImageDescriptor.createFromURL(iconURL);
128         }
129         catch (MalformedURLException e){
130             return ImageDescriptor.getMissingImageDescriptor();
131         }
132     }
133     
134     
135     protected void initializeDefaultPreferences(IPreferenceStore store) {
136         // These settings will show up when Preference dialog
137
// opens up for the first time.
138
store.setDefault(Messages.getString("SootPlugin.classes"), "soot.Main"); //$NON-NLS-1$ //$NON-NLS-2$
139
store.setDefault(Messages.getString("SootPlugin.selected"), "soot.Main"); //$NON-NLS-1$ //$NON-NLS-2$
140
}
141
142     private SootResourceManager manager;
143
144     /**
145      * Returns the shared instance.
146      */

147     public static SootPlugin getDefault() {
148         return plugin;
149     }
150
151     /**
152      * Returns the workspace instance.
153      */

154     public static IWorkspace getWorkspace() {
155         return ResourcesPlugin.getWorkspace();
156     }
157
158     /**
159      * Returns the string from the plugin's resource bundle,
160      * or 'key' if not found.
161      */

162     public static String JavaDoc getResourceString(String JavaDoc key) {
163         ResourceBundle bundle= SootPlugin.getDefault().getResourceBundle();
164         try {
165             return bundle.getString(key);
166         } catch (MissingResourceException e) {
167             return key;
168         }
169     }
170
171     /**
172      * Returns the plugin's resource bundle,
173      */

174     public ResourceBundle getResourceBundle() {
175         return resourceBundle;
176     }
177     
178     
179     /**
180      * Method startUp.
181      * @throws CoreException
182      */

183     public void startUp() throws CoreException {
184         super.startup();
185         soot_output_doc = new SootDocument();
186         soot_output_doc.startUp();
187     }
188     
189     /**
190      * @see org.eclipse.core.runtime.Plugin#shutdown()
191      */

192     public void shutdown() throws CoreException {
193         super.shutdown();
194         sootOutputEventListeners.removeAllElements();
195     }
196     
197
198     /**
199      * @return
200      */

201     public SootResourceManager getManager() {
202         return manager;
203     }
204
205     /**
206      * @param manager
207      */

208     public void setManager(SootResourceManager manager) {
209         this.manager = manager;
210     }
211     
212     public void addEditorViewer(ISourceViewer viewer) {
213         viewer.addTextListener(getManager());
214         getEditorViewers().add(viewer);
215     }
216
217     /**
218      * @return
219      */

220     public ArrayList getEditorViewers() {
221         return editorViewers;
222     }
223
224     /**
225      * @param list
226      */

227     public void setEditorViewers(ArrayList list) {
228         editorViewers = list;
229     }
230
231     /**
232      * @return
233      */

234     public SootPartManager getPartManager() {
235         return partManager;
236     }
237
238     /**
239      * @param manager
240      */

241     public void setPartManager(SootPartManager manager) {
242         partManager = manager;
243     }
244
245     /**
246      * @return
247      */

248     public ColorManager getColorManager() {
249         if (colorManager == null ){
250             colorManager = new ColorManager();
251         }
252         return colorManager;
253     }
254
255     /**
256      * @param manager
257      */

258     public void setColorManager(ColorManager manager) {
259         colorManager = manager;
260     }
261
262     /**
263      * @return
264      */

265     public DataKeeper getDataKeeper() {
266         return dataKeeper;
267     }
268
269     /**
270      * @param keeper
271      */

272     public void setDataKeeper(DataKeeper keeper) {
273         dataKeeper = keeper;
274     }
275
276     /**
277      * @return
278      */

279     public Font getSootFont() {
280         return sootFont;
281     }
282
283     /**
284      * @param font
285      */

286     public void setSootFont(Font font) {
287         sootFont = font;
288     }
289
290     /**
291      * @return
292      */

293     public IProject getCurrentProject() {
294         return currentProject;
295     }
296
297     /**
298      * @param project
299      */

300     public void setCurrentProject(IProject project) {
301         currentProject = project;
302     }
303
304 }
305
Popular Tags