01: /*******************************************************************************
02: * Copyright (c) 2003, 2006 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.navigator;
11:
12: import java.net.MalformedURLException;
13: import java.net.URL;
14: import java.util.Collections;
15:
16: import org.eclipse.core.runtime.FileLocator;
17: import org.eclipse.core.runtime.Path;
18: import org.eclipse.jface.resource.ImageDescriptor;
19: import org.eclipse.jface.resource.ImageRegistry;
20: import org.eclipse.swt.graphics.Image;
21:
22: /**
23: *
24: *
25: * @since 3.2
26: */
27: public class NavigatorImages {
28:
29: // Create image registry
30: private final static ImageRegistry NAVIGATOR_PLUGIN_REGISTRY = NavigatorPlugin
31: .getDefault().getImageRegistry();
32:
33: private static URL ICONS_LOCATION;
34: static {
35: ICONS_LOCATION = FileLocator.find(NavigatorPlugin.getDefault()
36: .getBundle(),
37: new Path("icons/full/"), Collections.EMPTY_MAP); //$NON-NLS-1$
38: }
39:
40: /**
41: * Gets the current image.
42: *
43: * @param key
44: * Name of the icon.
45: * @return Image
46: */
47: public static Image get(String key) {
48: return NAVIGATOR_PLUGIN_REGISTRY.get(key);
49: }
50:
51: /**
52: * Create and returns a image descriptor and adds the image to the
53: * registery.
54: *
55: * @param prefix
56: * Icon dir structure.
57: * @param name
58: * The name of the icon.
59: * @return ImageDescriptor
60: */
61: public static ImageDescriptor createManaged(String prefix,
62: String name) {
63: ImageDescriptor result = ImageDescriptor
64: .createFromURL(makeIconFileURL(prefix, name));
65: NAVIGATOR_PLUGIN_REGISTRY.put(name, result);
66: return result;
67: }
68:
69: /**
70: * Creates the icon url
71: *
72: * @param prefix
73: * Icon dir structure.
74: * @param name
75: * The name of the icon.
76: * @return URL
77: */
78: private static URL makeIconFileURL(String prefix, String name) {
79: StringBuffer buffer = new StringBuffer(prefix);
80: buffer.append(name);
81: try {
82: return new URL(ICONS_LOCATION, buffer.toString());
83: } catch (MalformedURLException ex) {
84: return null;
85: }
86: }
87: }
|