KickJava   Java API By Example, From Geeks To Geeks.

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


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 import java.util.*;
23
24 import org.eclipse.jface.text.*;
25 import org.eclipse.swt.custom.StyleRange;
26 import org.eclipse.swt.graphics.Color;
27 import org.eclipse.swt.graphics.RGB;
28 import org.eclipse.swt.widgets.Display;
29 import org.eclipse.swt.*;
30 import org.eclipse.ui.*;
31 import org.eclipse.ui.texteditor.AbstractTextEditor;
32
33 import ca.mcgill.sable.soot.SootPlugin;
34 import ca.mcgill.sable.soot.editors.*;
35
36 public class SootAttributesJavaColorer extends AbstractAttributesColorer implements Runnable JavaDoc{
37
38     public void run(){
39         init();
40         computeColors();
41     }
42     
43     public void computeColors(){//SootAttributesHandler handler, ITextViewer viewer, IEditorPart editorPart){
44

45         if ((getHandler() == null) || (getHandler().getAttrList() == null)) return;
46         ArrayList sortedAttrs = sortAttrsByLength(getHandler().getAttrList());
47         Iterator it = sortedAttrs.iterator();
48
49         setStyleList(new ArrayList());
50         
51         getDisplay().asyncExec( new Runnable JavaDoc() {
52             public void run() {
53                 if ((getViewer() != null) && (getViewer().getTextWidget() != null)){
54                     setBgColor(getViewer().getTextWidget().getBackground());
55                 }
56             };
57         });
58         
59         while (it.hasNext()) {
60             // sets colors for stmts
61
SootAttribute sa = (SootAttribute)it.next();
62             if ((sa.getJavaStartLn() != 0) && (sa.getJavaEndLn() != 0)){
63                 if (sa.getJavaStartPos() != 0 && sa.getJavaEndPos() != 0){
64                     if (sa.getColorList() != null){
65                         Iterator cit = sa.getColorList().iterator();
66                         while (cit.hasNext()){
67                             ColorAttribute ca = (ColorAttribute)cit.next();
68                             if (getHandler().isShowAllTypes()){
69                                 boolean fg = ca.fg() == 1 ? true: false;
70                                 setAttributeTextColor(sa.getJavaStartLn(), sa.getJavaEndLn(), sa.getJavaStartPos()+1, sa.getJavaEndPos()+1, ca.getRGBColor(), fg);//, tp);
71
}
72                             else {
73                                 if (getHandler().getTypesToShow().contains(ca.type())){
74                                     boolean fg = ca.fg() == 1 ? true: false;
75                                     setAttributeTextColor(sa.getJavaStartLn(), sa.getJavaEndLn(), sa.getJavaStartPos()+1, sa.getJavaEndPos()+1, ca.getRGBColor(), fg);//, tp);
76
}
77                             }
78                         }
79                     }
80                     
81                 }
82             }
83     
84         }
85         changeStyles();
86     }
87     
88     
89     protected void setLength(SootAttribute sa, int len){
90         sa.setJavaLength(len);
91     }
92     
93 }
94
Popular Tags