1 11 package org.eclipse.ui.internal; 12 13 import org.eclipse.jface.resource.CompositeImageDescriptor; 14 import org.eclipse.jface.resource.ImageDescriptor; 15 import org.eclipse.swt.graphics.ImageData; 16 import org.eclipse.swt.graphics.Point; 17 import org.eclipse.ui.internal.util.Util; 18 19 22 public class OverlayIcon extends CompositeImageDescriptor { 23 24 private Point fSize = null; 26 27 private ImageDescriptor fBase = null; 29 30 private ImageDescriptor fOverlay = null; 32 33 38 public OverlayIcon(ImageDescriptor base, ImageDescriptor overlay, Point size) { 39 fBase = base; 40 fOverlay = overlay; 41 fSize = size; 42 } 43 44 47 protected void drawCompositeImage(int width, int height) { 48 ImageData bg; 49 if (fBase == null || (bg = fBase.getImageData()) == null) { 50 bg = DEFAULT_IMAGE_DATA; 51 } 52 drawImage(bg, 0, 0); 53 54 if (fOverlay != null) { 55 drawTopRight(fOverlay); 56 } 57 } 58 59 63 protected void drawTopRight(ImageDescriptor overlay) { 64 if (overlay == null) { 65 return; 66 } 67 int x = getSize().x; 68 ImageData id = overlay.getImageData(); 69 x -= id.width; 70 drawImage(id, x, 0); 71 } 72 73 76 protected Point getSize() { 77 return fSize; 78 } 79 80 84 public int hashCode() { 85 return Util.hashCode(fBase) * 17 + Util.hashCode(fOverlay); 86 } 87 88 91 public boolean equals(Object obj) { 92 if (!(obj instanceof OverlayIcon)) { 93 return false; 94 } 95 OverlayIcon overlayIcon = (OverlayIcon) obj; 96 return Util.equals(this.fBase, overlayIcon.fBase) 97 && Util.equals(this.fOverlay, overlayIcon.fOverlay) 98 && Util.equals(this.fSize, overlayIcon.fSize); 99 } 100 } 101 | Popular Tags |