1 11 package org.eclipse.jface.resource; 12 13 import org.eclipse.swt.SWT; 14 import org.eclipse.swt.SWTException; 15 import org.eclipse.swt.graphics.Device; 16 import org.eclipse.swt.graphics.Image; 17 import org.eclipse.swt.graphics.ImageData; 18 import org.eclipse.swt.widgets.Display; 19 20 26 final class DerivedImageDescriptor extends ImageDescriptor { 27 28 private ImageDescriptor original; 29 private int flags; 30 31 39 public DerivedImageDescriptor(ImageDescriptor original, int swtFlags) { 40 this.original = original; 41 flags = swtFlags; 42 } 43 44 public Object createResource(Device device) throws DeviceResourceException { 45 try { 46 return internalCreateImage(device); 47 } catch (SWTException e) { 48 throw new DeviceResourceException(this, e); 49 } 50 } 51 52 public Image createImage(Device device) { 53 return internalCreateImage(device); 54 } 55 56 public int hashCode() { 57 return original.hashCode() + flags; 58 } 59 60 public boolean equals(Object arg0) { 61 if (arg0 instanceof DerivedImageDescriptor) { 62 DerivedImageDescriptor desc = (DerivedImageDescriptor)arg0; 63 64 return desc.original == original && flags == desc.flags; 65 } 66 67 return false; 68 } 69 70 79 private final Image internalCreateImage(Device device) { 80 Image originalImage = original.createImage(device); 81 Image result = new Image(device, originalImage, flags); 82 original.destroyResource(originalImage); 83 return result; 84 } 85 86 public ImageData getImageData() { 87 Image image = internalCreateImage(Display.getCurrent()); 88 ImageData result = image.getImageData(); 89 image.dispose(); 90 return result; 91 } 92 93 } 94 | Popular Tags |