KickJava   Java API By Example, From Geeks To Geeks.

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


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

11
12 package org.eclipse.ui.internal.commands;
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.util.ImageSupport;
21
22 final class ImageFactory {
23
24     private static ImageRegistry imageRegistry = new ImageRegistry();
25     private static Map JavaDoc map = new HashMap JavaDoc();
26
27     static {
28         put("blank", "icons/full/obj16/blank.gif"); //$NON-NLS-1$//$NON-NLS-2$
29
put("change", "icons/full/obj16/change_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
30
put("minus", "icons/full/obj16/delete_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
31
put("plus", "icons/full/obj16/add_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
32
}
33
34     static Image getImage(String JavaDoc 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); //$NON-NLS-1$
45

46                 imageRegistry.put(key, image);
47             }
48         }
49
50         return image;
51     }
52
53     static ImageDescriptor getImageDescriptor(String JavaDoc key) {
54         ImageDescriptor imageDescriptor = (ImageDescriptor) map.get(key);
55
56         if (imageDescriptor == null)
57             System.err.println(ImageFactory.class +": no image descriptor for " + key); //$NON-NLS-1$
58

59         return imageDescriptor;
60     }
61
62     private static void put(String JavaDoc key, String JavaDoc value) {
63         map.put(key, ImageSupport.getImageDescriptor(value));
64     }
65 }
66
Popular Tags