KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > keys > ImageFactory


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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.internal.keys;
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.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 JavaDoc map = new HashMap JavaDoc();
27
28     static {
29         put("blank", "$nl$/icons/full/obj16/blank.gif"); //$NON-NLS-1$//$NON-NLS-2$
30
put("change", "$nl$/icons/full/obj16/change_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
31

32         /*
33          * TODO Remove these images from the registry if they are no longer
34          * needed.
35          */

36         put("minus", "$nl$/icons/full/obj16/delete_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
37
put("plus", "$nl$/icons/full/obj16/add_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
38
}
39
40     static Image getImage(String JavaDoc 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); //$NON-NLS-1$
51
}
52
53                 imageRegistry.put(key, image);
54             }
55         }
56
57         return image;
58     }
59
60     static ImageDescriptor getImageDescriptor(String JavaDoc key) {
61         ImageDescriptor imageDescriptor = (ImageDescriptor) map.get(key);
62
63         if (imageDescriptor == null) {
64             WorkbenchPlugin.log(ImageFactory.class +": no image descriptor for " + key); //$NON-NLS-1$
65
}
66
67         return imageDescriptor;
68     }
69
70     private static void put(String JavaDoc key, String JavaDoc value) {
71         map.put(key, ImageSupport.getImageDescriptor(value));
72     }
73 }
74
Popular Tags