01: /*******************************************************************************
02: * Copyright (c) 2000, 2007 IBM Corporation and others.
03: * All rights reserved. This program and the accompanying materials
04: * are made available under the terms of the Eclipse Public License v1.0
05: * which accompanies this distribution, and is available at
06: * http://www.eclipse.org/legal/epl-v10.html
07: *
08: * Contributors:
09: * IBM Corporation - initial API and implementation
10: *******************************************************************************/package org.eclipse.ui.internal.keys;
11:
12: import java.util.HashMap;
13: import java.util.Map;
14:
15: import org.eclipse.jface.resource.ImageDescriptor;
16: import org.eclipse.jface.resource.ImageRegistry;
17: import org.eclipse.swt.graphics.Image;
18: import org.eclipse.ui.internal.WorkbenchPlugin;
19: import org.eclipse.ui.internal.util.ImageSupport;
20:
21: final class ImageFactory {
22:
23: private static ImageRegistry imageRegistry = new ImageRegistry();
24: private static Map map = new HashMap();
25:
26: static {
27: put("blank", "$nl$/icons/full/obj16/blank.gif"); //$NON-NLS-1$//$NON-NLS-2$
28: put("change", "$nl$/icons/full/obj16/change_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
29:
30: /*
31: * TODO Remove these images from the registry if they are no longer
32: * needed.
33: */
34: put("minus", "$nl$/icons/full/obj16/delete_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
35: put("plus", "$nl$/icons/full/obj16/add_obj.gif"); //$NON-NLS-1$//$NON-NLS-2$
36: }
37:
38: static Image getImage(String key) {
39: Image image = imageRegistry.get(key);
40:
41: if (image == null) {
42: ImageDescriptor imageDescriptor = getImageDescriptor(key);
43:
44: if (imageDescriptor != null) {
45: image = imageDescriptor.createImage(false);
46:
47: if (image == null) {
48: WorkbenchPlugin.log(ImageFactory.class
49: + ": error creating image for " + key); //$NON-NLS-1$
50: }
51:
52: imageRegistry.put(key, image);
53: }
54: }
55:
56: return image;
57: }
58:
59: static ImageDescriptor getImageDescriptor(String key) {
60: ImageDescriptor imageDescriptor = (ImageDescriptor) map
61: .get(key);
62:
63: if (imageDescriptor == null) {
64: WorkbenchPlugin.log(ImageFactory.class
65: + ": no image descriptor for " + key); //$NON-NLS-1$
66: }
67:
68: return imageDescriptor;
69: }
70:
71: private static void put(String key, String value) {
72: map.put(key, ImageSupport.getImageDescriptor(value));
73: }
74: }
|