KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > NavigatorImages


1 /*******************************************************************************
2  * Copyright (c) 2003, 2006 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 package org.eclipse.ui.internal.navigator;
12
13 import java.net.MalformedURLException JavaDoc;
14 import java.net.URL JavaDoc;
15 import java.util.Collections JavaDoc;
16
17 import org.eclipse.core.runtime.FileLocator;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
22
23 /**
24  *
25  *
26  * @since 3.2
27  */

28 public class NavigatorImages {
29
30     // Create image registry
31
private final static ImageRegistry NAVIGATOR_PLUGIN_REGISTRY = NavigatorPlugin
32             .getDefault().getImageRegistry();
33
34     private static URL JavaDoc ICONS_LOCATION;
35     static {
36         ICONS_LOCATION = FileLocator.find(NavigatorPlugin.getDefault()
37                 .getBundle(), 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 JavaDoc 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 JavaDoc prefix, String JavaDoc name) {
62         ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(
63                 prefix, name));
64         NAVIGATOR_PLUGIN_REGISTRY.put(name, result);
65         return result;
66     }
67
68     /**
69      * Creates the icon url
70      *
71      * @param prefix
72      * Icon dir structure.
73      * @param name
74      * The name of the icon.
75      * @return URL
76      */

77     private static URL JavaDoc makeIconFileURL(String JavaDoc prefix, String JavaDoc name) {
78         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(prefix);
79         buffer.append(name);
80         try {
81             return new URL JavaDoc(ICONS_LOCATION, buffer.toString());
82         } catch (MalformedURLException JavaDoc ex) {
83             return null;
84         }
85     }
86 }
87
Popular Tags