1 11 12 package org.eclipse.ui.views.markers.internal; 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.ide.IDEWorkbenchPlugin; 21 22 25 public class ImageFactory { 26 27 private static ImageRegistry imageRegistry = new ImageRegistry(); 28 private static Map map = new HashMap (); 29 30 31 39 public static Image getImage(String path) { 40 Image image = imageRegistry.get(path); 41 42 if (image == null) { 43 ImageDescriptor imageDescriptor = getImageDescriptor(path); 44 45 if (imageDescriptor != null) { 46 image = imageDescriptor.createImage(false); 47 48 if (image == null) 49 System.err.println(ImageFactory.class + ": error creating image for " + path); 51 imageRegistry.put(path, image); 52 } 53 } 54 55 return image; 56 } 57 58 67 public static ImageDescriptor getImageDescriptor(String path) { 68 ImageDescriptor imageDescriptor = (ImageDescriptor) map.get(path); 69 70 if (imageDescriptor == null) { 71 imageDescriptor =IDEWorkbenchPlugin.getIDEImageDescriptor(path); 72 map.put(path, imageDescriptor); 73 } 74 75 return imageDescriptor; 76 } 77 78 } 79 | Popular Tags |