001: /* Soot - a J*va Optimization Framework
002: * Copyright (C) 2003 Jennifer Lhotak
003: *
004: * This library is free software; you can redistribute it and/or
005: * modify it under the terms of the GNU Lesser General Public
006: * License as published by the Free Software Foundation; either
007: * version 2.1 of the License, or (at your option) any later version.
008: *
009: * This library is distributed in the hope that it will be useful,
010: * but WITHOUT ANY WARRANTY; without even the implied warranty of
011: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
012: * Lesser General Public License for more details.
013: *
014: * You should have received a copy of the GNU Lesser General Public
015: * License along with this library; if not, write to the
016: * Free Software Foundation, Inc., 59 Temple Place - Suite 330,
017: * Boston, MA 02111-1307, USA.
018: */
019:
020: package ca.mcgill.sable.soot.attributes;
021:
022: import java.util.*;
023:
024: import org.eclipse.jface.text.*;
025: import org.eclipse.swt.custom.StyleRange;
026: import org.eclipse.swt.graphics.Color;
027: import org.eclipse.swt.graphics.RGB;
028: import org.eclipse.swt.widgets.Display;
029: import org.eclipse.swt.*;
030: import org.eclipse.ui.*;
031: import org.eclipse.ui.texteditor.AbstractTextEditor;
032:
033: import ca.mcgill.sable.soot.SootPlugin;
034: import ca.mcgill.sable.soot.editors.*;
035:
036: public class SootAttributesJavaColorer extends
037: AbstractAttributesColorer implements Runnable {
038:
039: public void run() {
040: init();
041: computeColors();
042: }
043:
044: public void computeColors() {//SootAttributesHandler handler, ITextViewer viewer, IEditorPart editorPart){
045:
046: if ((getHandler() == null)
047: || (getHandler().getAttrList() == null))
048: return;
049: ArrayList sortedAttrs = sortAttrsByLength(getHandler()
050: .getAttrList());
051: Iterator it = sortedAttrs.iterator();
052:
053: setStyleList(new ArrayList());
054:
055: getDisplay().asyncExec(new Runnable() {
056: public void run() {
057: if ((getViewer() != null)
058: && (getViewer().getTextWidget() != null)) {
059: setBgColor(getViewer().getTextWidget()
060: .getBackground());
061: }
062: };
063: });
064:
065: while (it.hasNext()) {
066: // sets colors for stmts
067: SootAttribute sa = (SootAttribute) it.next();
068: if ((sa.getJavaStartLn() != 0) && (sa.getJavaEndLn() != 0)) {
069: if (sa.getJavaStartPos() != 0
070: && sa.getJavaEndPos() != 0) {
071: if (sa.getColorList() != null) {
072: Iterator cit = sa.getColorList().iterator();
073: while (cit.hasNext()) {
074: ColorAttribute ca = (ColorAttribute) cit
075: .next();
076: if (getHandler().isShowAllTypes()) {
077: boolean fg = ca.fg() == 1 ? true
078: : false;
079: setAttributeTextColor(sa
080: .getJavaStartLn(), sa
081: .getJavaEndLn(), sa
082: .getJavaStartPos() + 1, sa
083: .getJavaEndPos() + 1, ca
084: .getRGBColor(), fg);//, tp);
085: } else {
086: if (getHandler().getTypesToShow()
087: .contains(ca.type())) {
088: boolean fg = ca.fg() == 1 ? true
089: : false;
090: setAttributeTextColor(sa
091: .getJavaStartLn(), sa
092: .getJavaEndLn(), sa
093: .getJavaStartPos() + 1, sa
094: .getJavaEndPos() + 1, ca
095: .getRGBColor(), fg);//, tp);
096: }
097: }
098: }
099: }
100:
101: }
102: }
103:
104: }
105: changeStyles();
106: }
107:
108: protected void setLength(SootAttribute sa, int len) {
109: sa.setJavaLength(len);
110: }
111:
112: }
|