1 11 package org.eclipse.team.internal.ui; 12 13 import java.util.Arrays ; 14 15 import org.eclipse.jface.resource.CompositeImageDescriptor; 16 import org.eclipse.jface.resource.ImageDescriptor; 17 import org.eclipse.swt.graphics.*; 18 19 22 public class OverlayIcon extends CompositeImageDescriptor { 23 private Image base; 25 private ImageDescriptor descriptorBase; 27 private ImageDescriptor[] overlays; 29 private Point size; 31 private int[] locations; 33 34 public static final int TOP_LEFT = 0; 35 public static final int TOP_RIGHT = 1; 36 public static final int BOTTOM_LEFT = 2; 37 public static final int BOTTOM_RIGHT = 3; 38 39 public static final int DEFAULT_WIDTH= 22; 40 public static final int DEFAULT_HEIGHT= 16; 41 42 50 public OverlayIcon(Image base, ImageDescriptor[] overlays, int[] locations, Point size) { 51 this.base = base; 52 this.descriptorBase = null; 53 this.overlays = overlays; 54 this.locations = locations; 55 this.size = size; 56 } 57 58 protected void drawOverlays(ImageDescriptor[] overlays, int[] locations) { 59 Point size = getSize(); 60 for (int i = 0; i < overlays.length; i++) { 61 ImageDescriptor overlay = overlays[i]; 62 ImageData overlayData = overlay.getImageData(); 63 switch (locations[i]) { 64 case TOP_LEFT: 65 drawImage(overlayData, 0, 0); 66 break; 67 case TOP_RIGHT: 68 drawImage(overlayData, size.x - overlayData.width, 0); 69 break; 70 case BOTTOM_LEFT: 71 drawImage(overlayData, 0, size.y - overlayData.height); 72 break; 73 case BOTTOM_RIGHT: 74 drawImage(overlayData, size.x - overlayData.width, size.y - overlayData.height); 75 break; 76 } 77 } 78 } 79 80 public boolean equals(Object o) { 81 if (! (o instanceof OverlayIcon)) return false; 82 OverlayIcon other = (OverlayIcon) o; 83 return base.equals(other.base) && Arrays.equals(overlays, other.overlays); 84 } 85 86 public int hashCode() { 87 int code = base.hashCode(); 88 for (int i = 0; i < overlays.length; i++) { 89 code ^= overlays[i].hashCode(); 90 } 91 return code; 92 } 93 94 95 protected void drawCompositeImage(int width, int height) { 96 if(descriptorBase != null) { 97 ImageData bg; 98 if (descriptorBase == null || (bg= descriptorBase.getImageData()) == null) 99 bg= DEFAULT_IMAGE_DATA; 100 drawImage(bg, 0, 0); 101 } else { 102 drawImage(base.getImageData(), 0, 0); 103 } 104 drawOverlays(overlays, locations); 105 } 106 107 protected Point getSize() { 108 return size; 109 } 110 } 111 | Popular Tags |