1 11 package org.eclipse.compare.internal.patch; 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.jface.viewers.IDecoration; 18 import org.eclipse.swt.graphics.*; 19 20 24 class DecoratorOverlayIcon extends CompositeImageDescriptor { 25 private Image base; 27 28 private ImageDescriptor[] overlays; 30 31 private Point size; 33 34 35 42 public DecoratorOverlayIcon(Image baseImage, 43 ImageDescriptor[] overlaysArray, Point sizeValue) { 44 this.base = baseImage; 45 this.overlays = overlaysArray; 46 this.size = sizeValue; 47 } 48 49 52 protected void drawOverlays(ImageDescriptor[] overlaysArray) { 53 54 for (int i = 0; i < overlays.length; i++) { 55 ImageDescriptor overlay = overlaysArray[i]; 56 if (overlay == null) { 57 continue; 58 } 59 ImageData overlayData = overlay.getImageData(); 60 if (overlayData == null) { 62 overlayData = ImageDescriptor.getMissingImageDescriptor() 63 .getImageData(); 64 } 65 switch (i) { 66 case IDecoration.TOP_LEFT: 67 drawImage(overlayData, 0, 0); 68 break; 69 case IDecoration.TOP_RIGHT: 70 drawImage(overlayData, size.x - overlayData.width, 0); 71 break; 72 case IDecoration.BOTTOM_LEFT: 73 drawImage(overlayData, 0, size.y - overlayData.height); 74 break; 75 case IDecoration.BOTTOM_RIGHT: 76 drawImage(overlayData, size.x - overlayData.width, size.y 77 - overlayData.height); 78 break; 79 } 80 } 81 } 82 83 public boolean equals(Object o) { 84 if (!(o instanceof DecoratorOverlayIcon)) { 85 return false; 86 } 87 DecoratorOverlayIcon other = (DecoratorOverlayIcon) o; 88 return base.equals(other.base) 89 && Arrays.equals(overlays, other.overlays); 90 } 91 92 public int hashCode() { 93 int code = base.hashCode(); 94 for (int i = 0; i < overlays.length; i++) { 95 if (overlays[i] != null) { 96 code ^= overlays[i].hashCode(); 97 } 98 } 99 return code; 100 } 101 102 protected void drawCompositeImage(int width, int height) { 103 ImageDescriptor underlay = overlays[IDecoration.UNDERLAY]; 104 if (underlay != null) { 105 drawImage(underlay.getImageData(), 0, 0); 106 } 107 drawImage(base.getImageData(), 0, 0); 108 drawOverlays(overlays); 109 } 110 111 protected Point getSize() { 112 return size; 113 } 114 115 118 protected int getTransparentPixel() { 119 return base.getImageData().transparentPixel; 120 } 121 122 } 123 | Popular Tags |