1 11 package org.eclipse.jface.viewers; 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 29 public class DecorationOverlayIcon extends CompositeImageDescriptor { 30 31 private Image base; 33 34 private ImageDescriptor[] overlays; 36 37 private Point size; 39 40 52 public DecorationOverlayIcon(Image baseImage, 53 ImageDescriptor[] overlaysArray, Point sizeValue) { 54 this.base = baseImage; 55 this.overlays = overlaysArray; 56 this.size = sizeValue; 57 } 58 59 70 public DecorationOverlayIcon(Image baseImage, ImageDescriptor[] overlaysArray) { 71 this(baseImage, overlaysArray, new Point(baseImage.getBounds().width, baseImage.getBounds().height)); 72 } 73 74 84 public DecorationOverlayIcon(Image baseImage, ImageDescriptor overlayImage, int quadrant) { 85 this(baseImage, createArrayFrom(overlayImage, quadrant)); 86 } 87 88 94 private static ImageDescriptor[] createArrayFrom( 95 ImageDescriptor overlayImage, int quadrant) { 96 ImageDescriptor[] descs = new ImageDescriptor[] { null, null, null, null, null }; 97 descs[quadrant] = overlayImage; 98 return descs; 99 } 100 101 105 private void drawOverlays(ImageDescriptor[] overlaysArray) { 106 107 for (int i = 0; i < overlays.length; i++) { 108 ImageDescriptor overlay = overlaysArray[i]; 109 if (overlay == null) { 110 continue; 111 } 112 ImageData overlayData = overlay.getImageData(); 113 if (overlayData == null) { 115 overlayData = ImageDescriptor.getMissingImageDescriptor() 116 .getImageData(); 117 } 118 switch (i) { 119 case IDecoration.TOP_LEFT: 120 drawImage(overlayData, 0, 0); 121 break; 122 case IDecoration.TOP_RIGHT: 123 drawImage(overlayData, size.x - overlayData.width, 0); 124 break; 125 case IDecoration.BOTTOM_LEFT: 126 drawImage(overlayData, 0, size.y - overlayData.height); 127 break; 128 case IDecoration.BOTTOM_RIGHT: 129 drawImage(overlayData, size.x - overlayData.width, size.y 130 - overlayData.height); 131 break; 132 } 133 } 134 } 135 136 139 public boolean equals(Object o) { 140 if (!(o instanceof DecorationOverlayIcon)) { 141 return false; 142 } 143 DecorationOverlayIcon other = (DecorationOverlayIcon) o; 144 return base.equals(other.base) 145 && Arrays.equals(overlays, other.overlays); 146 } 147 148 151 public int hashCode() { 152 int code = base.hashCode(); 153 for (int i = 0; i < overlays.length; i++) { 154 if (overlays[i] != null) { 155 code ^= overlays[i].hashCode(); 156 } 157 } 158 return code; 159 } 160 161 164 protected void drawCompositeImage(int width, int height) { 165 if (overlays.length > IDecoration.UNDERLAY) { 166 ImageDescriptor underlay = overlays[IDecoration.UNDERLAY]; 167 if (underlay != null) { 168 drawImage(underlay.getImageData(), 0, 0); 169 } 170 } 171 drawImage(base.getImageData(), 0, 0); 172 drawOverlays(overlays); 173 } 174 175 178 protected Point getSize() { 179 return size; 180 } 181 182 185 protected int getTransparentPixel() { 186 return base.getImageData().transparentPixel; 187 } 188 189 } 190 | Popular Tags |