1 11 12 package org.eclipse.ui.internal.keys; 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.WorkbenchPlugin; 21 import org.eclipse.ui.internal.util.ImageSupport; 22 23 final class ImageFactory { 24 25 private static ImageRegistry imageRegistry = new ImageRegistry(); 26 private static Map map = new HashMap (); 27 28 static { 29 put("blank", "$nl$/icons/full/obj16/blank.gif"); put("change", "$nl$/icons/full/obj16/change_obj.gif"); 32 36 put("minus", "$nl$/icons/full/obj16/delete_obj.gif"); put("plus", "$nl$/icons/full/obj16/add_obj.gif"); } 39 40 static Image getImage(String key) { 41 Image image = imageRegistry.get(key); 42 43 if (image == null) { 44 ImageDescriptor imageDescriptor = getImageDescriptor(key); 45 46 if (imageDescriptor != null) { 47 image = imageDescriptor.createImage(false); 48 49 if (image == null) { 50 WorkbenchPlugin.log(ImageFactory.class +": error creating image for " + key); } 52 53 imageRegistry.put(key, image); 54 } 55 } 56 57 return image; 58 } 59 60 static ImageDescriptor getImageDescriptor(String key) { 61 ImageDescriptor imageDescriptor = (ImageDescriptor) map.get(key); 62 63 if (imageDescriptor == null) { 64 WorkbenchPlugin.log(ImageFactory.class +": no image descriptor for " + key); } 66 67 return imageDescriptor; 68 } 69 70 private static void put(String key, String value) { 71 map.put(key, ImageSupport.getImageDescriptor(value)); 72 } 73 } 74 | Popular Tags |