KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > editors > JimpleEditor


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.editors;
21
22
23 import org.eclipse.jface.text.source.ISourceViewer;
24 import org.eclipse.jface.text.source.IVerticalRuler;
25 import org.eclipse.swt.widgets.Composite;
26 import org.eclipse.ui.IEditorInput;
27 import org.eclipse.ui.IFileEditorInput;
28 import org.eclipse.ui.editors.text.TextEditor;
29 import org.eclipse.ui.views.contentoutline.IContentOutlinePage;
30
31 import ca.mcgill.sable.soot.SootPlugin;
32
33
34 public class JimpleEditor extends TextEditor {
35
36     private ColorManager colorManager;
37     protected JimpleContentOutlinePage page;
38     private ISourceViewer viewer;
39     
40     /**
41      * Constructor for JimpleEditor.
42      */

43     public JimpleEditor() {
44         super();
45         colorManager = SootPlugin.getDefault().getColorManager();
46         setSourceViewerConfiguration(new JimpleConfiguration(colorManager, this));
47         setDocumentProvider(new JimpleDocumentProvider());
48         setViewer(this.getSourceViewer());
49     
50         
51     }
52     
53     /**
54      * This method is what creates the Jimple Content Outliner
55      */

56     public Object JavaDoc getAdapter(Class JavaDoc key) {
57         if (key.equals(IContentOutlinePage.class)) {
58             //System.out.println("in getAdapter of editor");
59
IEditorInput input = getEditorInput();
60             if (input instanceof IFileEditorInput) {
61                 setPage(new JimpleContentOutlinePage(((IFileEditorInput)input).getFile(), this));
62                 return getPage();
63             }
64         }
65         return super.getAdapter(key);
66     }
67         
68     public void dispose() {
69         super.dispose();
70     }
71     
72     /**
73      * @return
74      */

75     public JimpleContentOutlinePage getPage() {
76         return page;
77     }
78
79     /**
80      * @param page
81      */

82     public void setPage(JimpleContentOutlinePage page) {
83         this.page = page;
84     }
85
86     protected ISourceViewer createSourceViewer(Composite parent, IVerticalRuler ruler, int styles) {
87         setViewer(super.createSourceViewer(parent, ruler, styles));
88         SootPlugin.getDefault().addEditorViewer(getViewer());
89         return getViewer();
90     }
91     
92     /**
93      * @return
94      */

95     public ISourceViewer getViewer() {
96         return viewer;
97     }
98
99     /**
100      * @param viewer
101      */

102     public void setViewer(ISourceViewer viewer) {
103         this.viewer = viewer;
104     }
105
106 }
107
Popular Tags