KickJava   Java API By Example, From Geeks To Geeks.

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


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
21 package ca.mcgill.sable.soot.attributes;
22
23 import java.util.*;
24
25 import org.eclipse.jface.text.*;
26 import org.eclipse.swt.custom.StyleRange;
27 import org.eclipse.swt.graphics.Color;
28 import org.eclipse.swt.graphics.RGB;
29 import org.eclipse.swt.widgets.Display;
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 SootAttributesJimpleColorer extends AbstractAttributesColorer implements Runnable JavaDoc{
37
38
39     public void run(){
40         init();
41         computeColors();
42     }
43     
44     public void computeColors(){
45         if ((getHandler() == null) || (getHandler().getAttrList() == null)) return;
46         ArrayList sortedAttrs = sortAttrsByLength(getHandler().getAttrList());
47         Iterator it = getHandler().getAttrList().iterator();
48         
49         setStyleList(new ArrayList());
50
51         getDisplay().asyncExec( new Runnable JavaDoc() {
52             public void run(){
53                 setBgColor(getViewer().getTextWidget().getBackground());
54             };
55         });
56         
57         while (it.hasNext()) {
58             // sets colors for stmts
59
SootAttribute sa = (SootAttribute)it.next();
60              if ((sa.getJimpleStartLn() != 0) && (sa.getJimpleEndLn() != 0)) {
61                 if ((sa.getJimpleStartPos() != 0) && (sa.getJimpleEndPos() != 0)){
62                    if (sa.getColorList() != null){
63                         Iterator cit = sa.getColorList().iterator();
64                         while (cit.hasNext()){
65                             ColorAttribute ca = (ColorAttribute)cit.next();
66                             if (getHandler().isShowAllTypes()){
67                                 boolean fg = ca.fg() == 1 ? true: false;
68                                 setAttributeTextColor(sa.getJimpleStartLn(), sa.getJimpleEndLn(), sa.getJimpleStartPos()+1, sa.getJimpleEndPos()+1, ca.getRGBColor(), fg);//, tp);
69
}
70                             else {
71                                 if (getHandler().getTypesToShow().contains(ca.type())){
72                                     boolean fg = ca.fg() == 1 ? true: false;
73                                     setAttributeTextColor(sa.getJimpleStartLn(), sa.getJimpleEndLn(), sa.getJimpleStartPos()+1, sa.getJimpleEndPos()+1, ca.getRGBColor(), fg);//, tp);
74
}
75                             }
76                         }
77                     }
78                    
79                 }
80             }
81                     
82         }
83         
84         changeStyles();
85     }
86     protected void setLength(SootAttribute sa, int len){
87         sa.setJimpleLength(len);
88     }
89     
90
91 }
92
Popular Tags