1 19 20 package ca.mcgill.sable.soot.ui; 21 22 import java.util.*; 23 24 import org.eclipse.jface.resource.ImageDescriptor; 25 import org.eclipse.jface.viewers.ILabelProviderListener; 26 import org.eclipse.jface.viewers.ITableLabelProvider; 27 import org.eclipse.swt.graphics.Color; 28 import org.eclipse.swt.graphics.GC; 29 import org.eclipse.swt.graphics.Image; 30 import org.eclipse.swt.graphics.RGB; 31 32 import ca.mcgill.sable.soot.SootPlugin; 33 import ca.mcgill.sable.soot.attributes.AnalysisKey; 34 import ca.mcgill.sable.soot.editors.ColorManager; 35 36 public class KeysLabelProvider implements ITableLabelProvider { 37 38 private HashMap images; 39 private ArrayList imageList; 40 43 public Image getColumnImage(Object element, int columnIndex) { 44 AnalysisKey key = (AnalysisKey)element; 45 ColorManager colorManager = SootPlugin.getDefault().getColorManager(); 46 RGB rgb = new RGB(key.getRed(), key.getGreen(), key.getBlue()); 47 Color c = colorManager.getColor(rgb); 48 if (imageList == null){ 49 imageList = new ArrayList(); 50 } 51 if (images == null){ 52 images = new HashMap(); 53 } 54 Image image = null; 55 ImageDescriptor id = SootPlugin.getImageDescriptor("key.png"); 56 if (!images.isEmpty()){ 57 Iterator it = images.keySet().iterator(); 58 while (it.hasNext()){ 59 RGB next = (RGB)it.next(); 60 if (next.red == key.getRed() && next.green == key.getGreen() && next.blue == key.getBlue()){ 61 image = (Image)images.get(next); 62 } 63 } 64 } 65 if (image == null) { 66 image = id.createImage(); 67 images.put(rgb, image); 68 } 69 GC gc = new GC(image); 70 gc.setBackground(c); 71 gc.fillRectangle(3,3,9,9); 72 gc.dispose(); 73 74 75 return image; 76 } 77 78 public void dispose(){ 79 if (images == null) return; 80 Iterator it2 = images.keySet().iterator(); 81 while (it2.hasNext()){ 82 ((Image)images.get(it2.next())).dispose(); 83 } 84 images = null; 85 } 86 87 90 public String getColumnText(Object element, int columnIndex) { 91 return ((AnalysisKey)element).getKey(); 92 } 93 94 97 public void addListener(ILabelProviderListener listener) { 98 99 } 100 101 102 105 public boolean isLabelProperty(Object element, String property) { 106 return false; 107 } 108 109 112 public void removeListener(ILabelProviderListener listener) { 113 114 } 115 116 } 117 | Popular Tags |