1 12 package org.eclipse.ant.internal.ui; 13 14 import org.eclipse.jface.resource.CompositeImageDescriptor; 15 import org.eclipse.jface.resource.ImageDescriptor; 16 import org.eclipse.swt.graphics.ImageData; 17 import org.eclipse.swt.graphics.Point; 18 19 23 public class AntImageDescriptor extends CompositeImageDescriptor { 24 25 26 public final static int HAS_ERRORS= 0x0001; 27 28 29 public final static int IMPORTED= 0x0002; 30 31 32 public final static int HAS_WARNINGS= 0x0004; 33 34 private ImageDescriptor fBaseImage; 35 private int fFlags; 36 private Point fSize; 37 38 45 public AntImageDescriptor(ImageDescriptor baseImage, int flags) { 46 setBaseImage(baseImage); 47 setFlags(flags); 48 } 49 50 53 protected Point getSize() { 54 if (fSize == null) { 55 ImageData data= getBaseImage().getImageData(); 56 setSize(new Point(data.width, data.height)); 57 } 58 return fSize; 59 } 60 61 64 public boolean equals(Object object) { 65 if (!(object instanceof AntImageDescriptor)){ 66 return false; 67 } 68 69 AntImageDescriptor other= (AntImageDescriptor)object; 70 return (getBaseImage().equals(other.getBaseImage()) && getFlags() == other.getFlags()); 71 } 72 73 76 public int hashCode() { 77 return getBaseImage().hashCode() | getFlags(); 78 } 79 80 83 protected void drawCompositeImage(int width, int height) { 84 ImageData bg= getBaseImage().getImageData(); 85 if (bg == null) { 86 bg= DEFAULT_IMAGE_DATA; 87 } 88 drawImage(bg, 0, 0); 89 drawOverlays(); 90 } 91 92 95 protected void drawOverlays() { 96 int flags= getFlags(); 97 int y= 0; 98 ImageData data= null; 99 if ((flags & IMPORTED) != 0) { 100 data= AntUIImages.getImageDescriptor(IAntUIConstants.IMG_OVR_IMPORT).getImageData(); 101 drawImage(data, 0, 0); 102 } 103 if ((flags & HAS_ERRORS) != 0) { 104 y= getSize().y; 105 data= AntUIImages.getImageDescriptor(IAntUIConstants.IMG_OVR_ERROR).getImageData(); 106 y -= data.height; 107 drawImage(data, 0, y); 108 } else if ((flags & HAS_WARNINGS) != 0) { 109 y= getSize().y; 110 data= AntUIImages.getImageDescriptor(IAntUIConstants.IMG_OVR_WARNING).getImageData(); 111 y -= data.height; 112 drawImage(data, 0, y); 113 } 114 } 115 116 protected ImageDescriptor getBaseImage() { 117 return fBaseImage; 118 } 119 120 protected void setBaseImage(ImageDescriptor baseImage) { 121 fBaseImage = baseImage; 122 } 123 124 protected int getFlags() { 125 return fFlags; 126 } 127 128 protected void setFlags(int flags) { 129 fFlags = flags; 130 } 131 132 protected void setSize(Point size) { 133 fSize = size; 134 } 135 } 136 | Popular Tags |