1 11 package org.eclipse.debug.internal.ui; 12 13 14 import java.util.HashMap ; 15 import java.util.Iterator ; 16 17 import org.eclipse.core.runtime.Assert; 18 import org.eclipse.jface.resource.ImageDescriptor; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.swt.widgets.Display; 21 22 25 public class ImageDescriptorRegistry { 26 27 private HashMap fRegistry= new HashMap (10); 28 private Display fDisplay; 29 30 34 public ImageDescriptorRegistry() { 35 this(DebugUIPlugin.getStandardDisplay()); 36 } 37 38 44 public ImageDescriptorRegistry(Display display) { 45 fDisplay= display; 46 Assert.isNotNull(fDisplay); 47 hookDisplay(); 48 } 49 50 57 public Image get(ImageDescriptor descriptor) { 58 if (descriptor == null) 59 descriptor= ImageDescriptor.getMissingImageDescriptor(); 60 61 Image result= (Image)fRegistry.get(descriptor); 62 if (result != null) 63 return result; 64 65 Assert.isTrue(fDisplay == DebugUIPlugin.getStandardDisplay(), DebugUIMessages.ImageDescriptorRegistry_0); 66 result= descriptor.createImage(); 67 if (result != null) 68 fRegistry.put(descriptor, result); 69 return result; 70 } 71 72 75 public void dispose() { 76 for (Iterator iter= fRegistry.values().iterator(); iter.hasNext(); ) { 77 Image image= (Image)iter.next(); 78 image.dispose(); 79 } 80 fRegistry.clear(); 81 } 82 83 private void hookDisplay() { 84 fDisplay.disposeExec(new Runnable () { 85 public void run() { 86 dispose(); 87 } 88 }); 89 } 90 } 91 92 | Popular Tags |