1 19 20 package ca.mcgill.sable.soot.cfg.figures; 21 22 import org.eclipse.draw2d.*; 23 import java.util.*; 24 import org.eclipse.swt.*; 25 import org.eclipse.swt.graphics.*; 26 import ca.mcgill.sable.soot.*; 27 import org.eclipse.draw2d.text.*; 28 import ca.mcgill.sable.soot.editors.*; 29 import org.eclipse.draw2d.geometry.*; 30 import org.eclipse.jface.resource.*; 31 32 public class CFGNodeDataFigure extends Figure { 33 34 private Panel nodeFigure; private RectangleFigure rect; 36 37 private ArrayList data; 38 39 40 Font f = new Font(null, "Arial", 8, SWT.NORMAL); 41 42 43 public CFGNodeDataFigure() { 44 super(); 45 setRect(new RectangleFigure()); 46 47 this.add(getRect()); 48 49 getRect().setBackgroundColor(SootPlugin.getDefault().getColorManager().getColor(new RGB(255, 255 ,255))); 50 ToolbarLayout layout = new ToolbarLayout(); 51 layout.setMinorAlignment(ToolbarLayout.ALIGN_CENTER); 52 layout.setVertical(false); 53 54 this.setLayoutManager(layout); 55 56 getRect().setLayoutManager(layout); 57 } 58 59 60 private soot.Unit unit; 61 62 public void updateFigure(){ 63 if (getData() == null) return; 64 65 int height = 0; 66 int width = 0; 67 Iterator it = getData().iterator(); 68 while (it.hasNext()){ 69 unit = (soot.Unit)it.next(); 70 String next = unit.toString(); 71 72 Label l = new Label(next); 73 l.setFont(f); 74 l.getInsets().top = 1; 75 l.getInsets().bottom = 1; 76 l.getInsets().right = 1; 77 l.getInsets().left = 1; 78 height = height + l.getSize().height/2; 79 int length = next.length()*7; 80 width = length > width ? length : width; 81 getRect().add(l); 82 83 } 84 85 getRect().setSize(width+10, height+10); 86 this.setSize(width+10, height+10); 87 88 } 89 90 91 94 public RectangleFigure getRect() { 95 return rect; 96 } 97 98 Image stopImage = null; 99 Image highlightImage = null; 100 101 public void addStopIcon(){ 102 if (stopImage == null){ 103 ImageDescriptor desc = SootPlugin.getImageDescriptor("stop_icon.gif"); 104 stopImage = desc.createImage(); 105 } 106 ((Label)getRect().getChildren().get(0)).setIcon(stopImage); 107 } 108 109 Label indicatorLabel; 110 111 public void addIndicator(){ 112 if (highlightImage == null){ 113 ImageDescriptor desc = SootPlugin.getImageDescriptor("indicator.gif"); 114 highlightImage = desc.createImage(); 115 } 116 117 indicatorLabel = new Label(highlightImage); 118 this.add(indicatorLabel, 0); 119 } 120 121 public void removeIndicator(){ 122 if (this.getChildren().get(0).equals(indicatorLabel)){ 123 this.remove(indicatorLabel); 124 } 125 } 126 127 public void removeStopIcon(){ 128 ((Label)getRect().getChildren().get(0)).setIcon(null); 129 } 130 131 132 133 136 public ArrayList getData() { 137 return data; 138 } 139 140 143 public void setData(ArrayList list) { 144 data = list; 145 } 146 147 148 151 public void setRect(RectangleFigure figure) { 152 rect = figure; 153 } 154 155 156 159 public soot.Unit getUnit() { 160 return unit; 161 } 162 163 166 public void setUnit(soot.Unit unit) { 167 this.unit = unit; 168 } 169 170 } 171 | Popular Tags |