1 11 package org.eclipse.jdt.ui; 12 13 14 import org.eclipse.core.runtime.Assert; 15 16 import org.eclipse.swt.graphics.ImageData; 17 import org.eclipse.swt.graphics.Point; 18 19 import org.eclipse.jface.resource.CompositeImageDescriptor; 20 import org.eclipse.jface.resource.ImageDescriptor; 21 22 import org.eclipse.jdt.internal.ui.JavaPlugin; 23 import org.eclipse.jdt.internal.ui.JavaPluginImages; 24 25 36 public class JavaElementImageDescriptor extends CompositeImageDescriptor { 37 38 39 public final static int ABSTRACT= 0x001; 40 41 42 public final static int FINAL= 0x002; 43 44 45 public final static int SYNCHRONIZED= 0x004; 46 47 48 public final static int STATIC= 0x008; 49 50 51 public final static int RUNNABLE= 0x010; 52 53 54 public final static int WARNING= 0x020; 55 56 57 public final static int ERROR= 0x040; 58 59 60 public final static int OVERRIDES= 0x080; 61 62 63 public final static int IMPLEMENTS= 0x100; 64 65 66 public final static int CONSTRUCTOR= 0x200; 67 68 72 public final static int DEPRECATED= 0x400; 73 74 78 public final static int VOLATILE= 0x800; 79 80 84 public final static int TRANSIENT= 0x1000; 85 86 87 private ImageDescriptor fBaseImage; 88 private int fFlags; 89 private Point fSize; 90 91 99 public JavaElementImageDescriptor(ImageDescriptor baseImage, int flags, Point size) { 100 fBaseImage= baseImage; 101 Assert.isNotNull(fBaseImage); 102 fFlags= flags; 103 Assert.isTrue(fFlags >= 0); 104 fSize= size; 105 Assert.isNotNull(fSize); 106 } 107 108 116 public void setAdornments(int adornments) { 117 Assert.isTrue(adornments >= 0); 118 fFlags= adornments; 119 } 120 121 126 public int getAdronments() { 127 return fFlags; 128 } 129 130 135 public void setImageSize(Point size) { 136 Assert.isNotNull(size); 137 Assert.isTrue(size.x >= 0 && size.y >= 0); 138 fSize= size; 139 } 140 141 146 public Point getImageSize() { 147 return new Point(fSize.x, fSize.y); 148 } 149 150 153 protected Point getSize() { 154 return fSize; 155 } 156 157 160 public boolean equals(Object object) { 161 if (object == null || !JavaElementImageDescriptor.class.equals(object.getClass())) 162 return false; 163 164 JavaElementImageDescriptor other= (JavaElementImageDescriptor)object; 165 return (fBaseImage.equals(other.fBaseImage) && fFlags == other.fFlags && fSize.equals(other.fSize)); 166 } 167 168 171 public int hashCode() { 172 return fBaseImage.hashCode() | fFlags | fSize.hashCode(); 173 } 174 175 178 protected void drawCompositeImage(int width, int height) { 179 ImageData bg= getImageData(fBaseImage); 180 181 if ((fFlags & DEPRECATED) != 0) { Point size= getSize(); 183 ImageData data= getImageData(JavaPluginImages.DESC_OVR_DEPRECATED); 184 drawImage(data, 0, size.y - data.height); 185 } 186 drawImage(bg, 0, 0); 187 188 drawTopRight(); 189 drawBottomRight(); 190 drawBottomLeft(); 191 192 193 } 194 195 private ImageData getImageData(ImageDescriptor descriptor) { 196 ImageData data= descriptor.getImageData(); if (data == null) { 198 data= DEFAULT_IMAGE_DATA; 199 JavaPlugin.logErrorMessage("Image data not available: " + descriptor.toString()); } 201 return data; 202 } 203 204 private void addTopRightImage(ImageDescriptor desc, Point pos) { 205 ImageData data= getImageData(desc); 206 int x= pos.x - data.width; 207 if (x >= 0) { 208 drawImage(data, x, pos.y); 209 pos.x= x; 210 } 211 } 212 213 private void addBottomRightImage(ImageDescriptor desc, Point pos) { 214 ImageData data= getImageData(desc); 215 int x= pos.x - data.width; 216 int y= pos.y - data.height; 217 if (x >= 0 && y >= 0) { 218 drawImage(data, x, y); 219 pos.x= x; 220 } 221 } 222 223 private void addBottomLeftImage(ImageDescriptor desc, Point pos) { 224 ImageData data= getImageData(desc); 225 int x= pos.x; 226 int y= pos.y - data.height; 227 if (x + data.width < getSize().x && y >= 0) { 228 drawImage(data, x, y); 229 pos.x= x + data.width; 230 } 231 } 232 233 234 private void drawTopRight() { 235 Point pos= new Point(getSize().x, 0); 236 if ((fFlags & ABSTRACT) != 0) { 237 addTopRightImage(JavaPluginImages.DESC_OVR_ABSTRACT, pos); 238 } 239 if ((fFlags & CONSTRUCTOR) != 0) { 240 addTopRightImage(JavaPluginImages.DESC_OVR_CONSTRUCTOR, pos); 241 } 242 if ((fFlags & FINAL) != 0) { 243 addTopRightImage(JavaPluginImages.DESC_OVR_FINAL, pos); 244 } 245 if ((fFlags & VOLATILE) != 0) { 246 addTopRightImage(JavaPluginImages.DESC_OVR_VOLATILE, pos); 247 } 248 if ((fFlags & STATIC) != 0) { 249 addTopRightImage(JavaPluginImages.DESC_OVR_STATIC, pos); 250 } 251 252 } 253 254 private void drawBottomRight() { 255 Point size= getSize(); 256 Point pos= new Point(size.x, size.y); 257 258 int flags= fFlags; 259 260 int syncAndOver= SYNCHRONIZED | OVERRIDES; 261 int syncAndImpl= SYNCHRONIZED | IMPLEMENTS; 262 263 if ((flags & syncAndOver) == syncAndOver) { addBottomRightImage(JavaPluginImages.DESC_OVR_SYNCH_AND_OVERRIDES, pos); 265 flags &= ~syncAndOver; } else if ((flags & syncAndImpl) == syncAndImpl) { addBottomRightImage(JavaPluginImages.DESC_OVR_SYNCH_AND_IMPLEMENTS, pos); 268 flags &= ~syncAndImpl; } 270 if ((flags & OVERRIDES) != 0) { 271 addBottomRightImage(JavaPluginImages.DESC_OVR_OVERRIDES, pos); 272 } 273 if ((flags & IMPLEMENTS) != 0) { 274 addBottomRightImage(JavaPluginImages.DESC_OVR_IMPLEMENTS, pos); 275 } 276 if ((flags & SYNCHRONIZED) != 0) { 277 addBottomRightImage(JavaPluginImages.DESC_OVR_SYNCH, pos); 278 } 279 if ((flags & RUNNABLE) != 0) { 280 addBottomRightImage(JavaPluginImages.DESC_OVR_RUN, pos); 281 } 282 if ((flags & TRANSIENT) != 0) { 283 addBottomRightImage(JavaPluginImages.DESC_OVR_TRANSIENT, pos); 284 } 285 } 286 287 private void drawBottomLeft() { 288 Point pos= new Point(0, getSize().y); 289 if ((fFlags & ERROR) != 0) { 290 addBottomLeftImage(JavaPluginImages.DESC_OVR_ERROR, pos); 291 } 292 if ((fFlags & WARNING) != 0) { 293 addBottomLeftImage(JavaPluginImages.DESC_OVR_WARNING, pos); 294 } 295 296 } 297 } 298 | Popular Tags |