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.ui.*;
030: import org.eclipse.ui.texteditor.AbstractTextEditor;
031:
032: import ca.mcgill.sable.soot.SootPlugin;
033: import ca.mcgill.sable.soot.editors.*;
034:
035: public class SootAttributesJimpleColorer extends
036: AbstractAttributesColorer implements Runnable {
037:
038: public void run() {
039: init();
040: computeColors();
041: }
042:
043: public void computeColors() {
044: if ((getHandler() == null)
045: || (getHandler().getAttrList() == null))
046: return;
047: ArrayList sortedAttrs = sortAttrsByLength(getHandler()
048: .getAttrList());
049: Iterator it = getHandler().getAttrList().iterator();
050:
051: setStyleList(new ArrayList());
052:
053: getDisplay().asyncExec(new Runnable() {
054: public void run() {
055: setBgColor(getViewer().getTextWidget().getBackground());
056: };
057: });
058:
059: while (it.hasNext()) {
060: // sets colors for stmts
061: SootAttribute sa = (SootAttribute) it.next();
062: if ((sa.getJimpleStartLn() != 0)
063: && (sa.getJimpleEndLn() != 0)) {
064: if ((sa.getJimpleStartPos() != 0)
065: && (sa.getJimpleEndPos() != 0)) {
066: if (sa.getColorList() != null) {
067: Iterator cit = sa.getColorList().iterator();
068: while (cit.hasNext()) {
069: ColorAttribute ca = (ColorAttribute) cit
070: .next();
071: if (getHandler().isShowAllTypes()) {
072: boolean fg = ca.fg() == 1 ? true
073: : false;
074: setAttributeTextColor(sa
075: .getJimpleStartLn(), sa
076: .getJimpleEndLn(), sa
077: .getJimpleStartPos() + 1, sa
078: .getJimpleEndPos() + 1, ca
079: .getRGBColor(), fg);//, tp);
080: } else {
081: if (getHandler().getTypesToShow()
082: .contains(ca.type())) {
083: boolean fg = ca.fg() == 1 ? true
084: : false;
085: setAttributeTextColor(sa
086: .getJimpleStartLn(), sa
087: .getJimpleEndLn(), sa
088: .getJimpleStartPos() + 1,
089: sa.getJimpleEndPos() + 1,
090: ca.getRGBColor(), fg);//, tp);
091: }
092: }
093: }
094: }
095:
096: }
097: }
098:
099: }
100:
101: changeStyles();
102: }
103:
104: protected void setLength(SootAttribute sa, int len) {
105: sa.setJimpleLength(len);
106: }
107:
108: }
|