KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > ca > mcgill > sable > soot > attributes > AbstractSootAttributesHover


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.attributes;
21
22
23 import java.util.ArrayList JavaDoc;
24
25 import org.eclipse.jface.text.*;
26 import org.eclipse.jface.text.source.SourceViewer;
27 import org.eclipse.ui.*;
28 import org.eclipse.ui.texteditor.AbstractTextEditor;
29 import org.eclipse.core.resources.*;
30 import org.eclipse.core.runtime.CoreException;
31 import ca.mcgill.sable.soot.SootPlugin;
32
33 public abstract class AbstractSootAttributesHover implements ITextHover {
34
35     private IEditorPart editor;
36     private int lineNum;
37     private String JavaDoc fileName;
38     private String JavaDoc packFileName;
39     private ArrayList JavaDoc packFileNames;
40     private boolean editorHasChanged;
41     private String JavaDoc selectedProj;
42     private SootAttributesHandler attrsHandler;
43     private IResource rec;
44     private ITextViewer viewer;
45     private IDocument document;
46     public static final String JavaDoc sep = System.getProperty("file.separator");
47     
48     /**
49      * Method setEditor.
50      * @param ed
51      */

52     public void setEditor(IEditorPart ed) {
53         editor = ed;
54     }
55     
56
57     
58     /**
59      * Method getAttributes.
60      * @return String
61      * sub classes must implement this method
62      * if more then one attribute return
63      * each attribute separated by newlines
64      */

65     protected abstract String JavaDoc getAttributes(AbstractTextEditor editor);
66     
67     /**
68      * @see org.eclipse.jface.text.ITextHover#getHoverInfo(ITextViewer, IRegion)
69      */

70     public String JavaDoc getHoverInfo(ITextViewer textViewer, org.eclipse.jface.text.IRegion hoverRegion) {
71         
72         // this prevents showing incorrect tags - at least temporaily
73
// and hopefully if the editor has ever changed
74

75                     
76         getHoverRegion(textViewer, hoverRegion.getOffset());
77         String JavaDoc attr = null;
78         attr = getAttributes((AbstractTextEditor)getEditor());
79     
80         return attr;
81         
82     }
83
84     /**
85      * @see org.eclipse.jface.text.ITextHover#getHoverRegion(ITextViewer, int)
86      */

87     public org.eclipse.jface.text.IRegion getHoverRegion(ITextViewer textViewer, int offset) {
88         try {
89             setLineNum(textViewer.getDocument().getLineOfOffset(offset)+1);
90             setDocument(textViewer.getDocument());
91             return textViewer.getDocument().getLineInformationOfOffset(offset);
92         } catch (BadLocationException e) {
93             return null;
94         }
95
96     }
97     
98     
99     /**
100      * Returns the lineNum.
101      * @return int
102      */

103     public int getLineNum() {
104         return lineNum;
105     }
106
107     /**
108      * Sets the lineNum.
109      * @param lineNum The lineNum to set
110      */

111     public void setLineNum(int lineNum) {
112         this.lineNum = lineNum;
113     }
114
115     /**
116      * Returns the fileName.
117      * @return String
118      */

119     public String JavaDoc getFileName() {
120         return fileName;
121     }
122
123     /**
124      * Sets the fileName.
125      * @param fileName The fileName to set
126      */

127     public void setFileName(String JavaDoc fileName) {
128         this.fileName = fileName;
129     }
130
131     /**
132      * Returns the packFileName.
133      * @return String
134      */

135     public String JavaDoc getPackFileName() {
136         return packFileName;
137     }
138
139     /**
140      * Sets the packFileName.
141      * @param packFileName The packFileName to set
142      */

143     public void setPackFileName(String JavaDoc packFileName) {
144         this.packFileName = packFileName;
145     }
146
147     /**
148      * Returns the editorHasChanged.
149      * @return boolean
150      */

151     public boolean isEditorHasChanged() {
152         return editorHasChanged;
153     }
154
155     /**
156      * Sets the editorHasChanged.
157      * @param editorHasChanged The editorHasChanged to set
158      */

159     public void setEditorHasChanged(boolean editorHasChanged) {
160         this.editorHasChanged = editorHasChanged;
161     }
162
163     /**
164      * Returns the selectedProj.
165      * @return String
166      */

167     public String JavaDoc getSelectedProj() {
168         return selectedProj;
169     }
170
171     /**
172      * Sets the selectedProj.
173      * @param selectedProj The selectedProj to set
174      */

175     public void setSelectedProj(String JavaDoc selectedProj) {
176         this.selectedProj = selectedProj;
177     }
178
179     /**
180      * Returns the attrsHandler.
181      * @return SootAttributesHandler
182      */

183     public SootAttributesHandler getAttrsHandler() {
184         return attrsHandler;
185     }
186
187     /**
188      * Sets the attrsHandler.
189      * @param attrsHandler The attrsHandler to set
190      */

191     public void setAttrsHandler(SootAttributesHandler attrsHandler) {
192         this.attrsHandler = attrsHandler;
193     }
194
195     /**
196      * Returns the editor.
197      * @return IEditorPart
198      */

199     public IEditorPart getEditor() {
200         return editor;
201     }
202
203     /**
204      * Returns the rec.
205      * @return IResource
206      */

207     public IResource getRec() {
208         return rec;
209     }
210
211     /**
212      * Sets the rec.
213      * @param rec The rec to set
214      */

215     public void setRec(IResource rec) {
216         this.rec = rec;
217     }
218
219     /**
220      * @return
221      */

222     public IDocument getDocument() {
223         return document;
224     }
225
226     /**
227      * @return
228      */

229     public ITextViewer getViewer() {
230         return viewer;
231     }
232
233     /**
234      * @param document
235      */

236     public void setDocument(IDocument document) {
237         this.document = document;
238     }
239
240     /**
241      * @param viewer
242      */

243     public void setViewer(ITextViewer viewer) {
244         this.viewer = viewer;
245     }
246
247     /**
248      * @return
249      */

250     public ArrayList JavaDoc getPackFileNames() {
251         return packFileNames;
252     }
253
254     /**
255      * @param list
256      */

257     public void setPackFileNames(ArrayList JavaDoc list) {
258         packFileNames = list;
259     }
260
261 }
262
Popular Tags