KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > views > markers > internal > ImageFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11
12 package org.eclipse.ui.views.markers.internal;
13
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
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 /**
23  * Manages images and image descriptors.
24  */

25 public class ImageFactory {
26
27     private static ImageRegistry imageRegistry = new ImageRegistry();
28     private static Map JavaDoc map = new HashMap JavaDoc();
29
30     
31     /**
32      * Returns an image for the given path in the ide plug-in
33      * or <code>null</code> if an image could not be created.
34      *
35      * @param path the path of the image relative to "org.eclipse.ui/icons/full"
36      * @return the image located at the specified path or <code>null</code> if
37      * no image could be created.
38      */

39     public static Image getImage(String JavaDoc 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); //$NON-NLS-1$
50

51                 imageRegistry.put(path, image);
52             }
53         }
54
55         return image;
56     }
57     
58     /**
59      * Returns an image descriptor for the given path in the ide
60      * plug-in or <code>null</code> if no
61      * image could be found.
62      *
63      * @param path the path of the image relative to "org.eclipse.ui/icons/full"
64      * @return an image descriptor or <code>null</code> if no image was found at the
65      * specified path.
66      */

67     public static ImageDescriptor getImageDescriptor(String JavaDoc 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