1 11 package org.eclipse.jface.resource; 12 13 import org.eclipse.swt.graphics.Device; 14 import org.eclipse.swt.graphics.Image; 15 import org.eclipse.swt.graphics.ImageData; 16 17 20 class ImageDataImageDescriptor extends ImageDescriptor { 21 22 private ImageData data; 23 24 28 private Image originalImage = null; 29 30 35 ImageDataImageDescriptor(Image originalImage) { 36 this(originalImage.getImageData()); 37 this.originalImage = originalImage; 38 } 39 40 45 46 ImageDataImageDescriptor(ImageData data) { 47 this.data = data; 48 } 49 50 53 public Object createResource(Device device) throws DeviceResourceException { 54 55 if (originalImage != null) { 58 if (originalImage.getDevice() == device) { 60 return originalImage; 61 } 62 } 63 64 return super.createResource(device); 65 } 66 67 70 public void destroyResource(Object previouslyCreatedObject) { 71 if (previouslyCreatedObject == originalImage) { 72 return; 73 } 74 75 super.destroyResource(previouslyCreatedObject); 76 } 77 78 81 public ImageData getImageData() { 82 return data; 83 } 84 85 88 public int hashCode() { 89 return data.hashCode(); 90 } 91 92 95 public boolean equals(Object obj) { 96 if (!(obj instanceof ImageDataImageDescriptor)) { 97 return false; 98 } 99 100 ImageDataImageDescriptor imgWrap = (ImageDataImageDescriptor) obj; 101 102 if (originalImage != null) { 103 return imgWrap.originalImage == originalImage; 104 } 105 106 return (imgWrap.originalImage == null && data.equals(imgWrap.data)); 107 } 108 109 } 110 | Popular Tags |