1 11 12 package org.eclipse.ui.internal.commands; 13 14 import java.util.HashMap ; 15 import java.util.Map ; 16 17 import org.eclipse.jface.resource.ImageDescriptor; 18 import org.eclipse.jface.resource.ImageRegistry; 19 import org.eclipse.swt.graphics.Image; 20 import org.eclipse.ui.internal.util.ImageSupport; 21 22 final class ImageFactory { 23 24 private static ImageRegistry imageRegistry = new ImageRegistry(); 25 private static Map map = new HashMap (); 26 27 static { 28 put("blank", "icons/full/obj16/blank.gif"); put("change", "icons/full/obj16/change_obj.gif"); put("minus", "icons/full/obj16/delete_obj.gif"); put("plus", "icons/full/obj16/add_obj.gif"); } 33 34 static Image getImage(String key) { 35 Image image = (Image) imageRegistry.get(key); 36 37 if (image == null) { 38 ImageDescriptor imageDescriptor = getImageDescriptor(key); 39 40 if (imageDescriptor != null) { 41 image = imageDescriptor.createImage(false); 42 43 if (image == null) 44 System.err.println(ImageFactory.class +": error creating image for " + key); 46 imageRegistry.put(key, image); 47 } 48 } 49 50 return image; 51 } 52 53 static ImageDescriptor getImageDescriptor(String key) { 54 ImageDescriptor imageDescriptor = (ImageDescriptor) map.get(key); 55 56 if (imageDescriptor == null) 57 System.err.println(ImageFactory.class +": no image descriptor for " + key); 59 return imageDescriptor; 60 } 61 62 private static void put(String key, String value) { 63 map.put(key, ImageSupport.getImageDescriptor(value)); 64 } 65 } 66 | Popular Tags |