KickJava   Java API By Example, From Geeks To Geeks.

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


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 import org.eclipse.jface.text.IDocument;
23 import org.eclipse.jface.text.ITextDoubleClickStrategy;
24 import org.eclipse.jface.text.ITextHover;
25 import org.eclipse.jface.text.TextAttribute;
26
27 import org.eclipse.jface.text.contentassist.*;
28 import org.eclipse.jface.text.presentation.IPresentationReconciler;
29 import org.eclipse.jface.text.presentation.PresentationReconciler;
30 import org.eclipse.jface.text.rules.DefaultDamagerRepairer;
31 import org.eclipse.jface.text.rules.Token;
32 import org.eclipse.jface.text.source.ISourceViewer;
33 import org.eclipse.jface.text.source.SourceViewerConfiguration;
34 import ca.mcgill.sable.soot.attributes.SootAttributesJimpleHover;
35
36
37
38 public class JimpleConfiguration extends SourceViewerConfiguration {
39     private JimpleDoubleClickStrategy doubleClickStrategy;
40     private JimpleScanner scanner;
41     private ColorManager colorManager;
42     private JimpleEditor editor;
43
44     public JimpleConfiguration(ColorManager colorManager, JimpleEditor editor) {
45         this.colorManager = colorManager;
46         setEditor(editor);
47     }
48     public String JavaDoc[] getConfiguredContentTypes(ISourceViewer sourceViewer) {
49         return new String JavaDoc[] {
50             IDocument.DEFAULT_CONTENT_TYPE};
51     }
52     public ITextDoubleClickStrategy getDoubleClickStrategy(
53         ISourceViewer sourceViewer,
54         String JavaDoc contentType) {
55         if (doubleClickStrategy == null)
56             doubleClickStrategy = new JimpleDoubleClickStrategy();
57         return doubleClickStrategy;
58     }
59
60     protected JimpleScanner getJimpleScanner() {
61         if (scanner == null) {
62             scanner = new JimpleScanner(colorManager);
63             scanner.setDefaultReturnToken(
64                 new Token(
65                     new TextAttribute(colorManager.getColor(IJimpleColorConstants.JIMPLE_DEFAULT))));
66         }
67         return scanner;
68     }
69
70     /**
71      * This is what causes Jimple keywords to be highlighted
72      */

73     public IPresentationReconciler getPresentationReconciler(ISourceViewer sourceViewer) {
74  
75         PresentationReconciler reconciler= new PresentationReconciler();
76   
77         DefaultDamagerRepairer dr= new DefaultDamagerRepairer(getJimpleScanner());
78         reconciler.setDamager(dr, IDocument.DEFAULT_CONTENT_TYPE);
79         reconciler.setRepairer(dr, IDocument.DEFAULT_CONTENT_TYPE);
80  
81         dr= new DefaultDamagerRepairer(getJimpleScanner());
82         reconciler.setDamager(dr, JimplePartitionScanner.JIMPLE_STRING);
83         reconciler.setRepairer(dr, JimplePartitionScanner.JIMPLE_STRING);
84         
85         return reconciler;
86
87     }
88     /**
89      * This allows text hover on Jimple Editor
90      */

91     public ITextHover getTextHover(ISourceViewer sourceViewer, String JavaDoc contentType) {
92         return new SootAttributesJimpleHover(getEditor());
93     }
94
95     public IContentAssistant getContentAssistant(ISourceViewer sourceViewer){
96         IContentAssistant ca = new ContentAssistant();
97         ca.install(sourceViewer);
98         return ca;
99     }
100     /**
101      * Returns the editor.
102      * @return JimpleEditor
103      */

104     public JimpleEditor getEditor() {
105         return editor;
106     }
107
108     /**
109      * Sets the editor.
110      * @param editor The editor to set
111      */

112     public void setEditor(JimpleEditor editor) {
113         this.editor = editor;
114     }
115
116 }
117
Popular Tags