KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > navigator > resources > plugin > NavigatorUIPluginImages


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.resources.plugin;
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.action.IAction;
20 import org.eclipse.jface.resource.ImageDescriptor;
21 import org.eclipse.jface.resource.ImageRegistry;
22 import org.eclipse.swt.graphics.Image;
23 import org.eclipse.ui.internal.navigator.NavigatorPlugin;
24
25 /**
26  * Handles all images and icons for the ui.
27  *
28  * <p>
29  * <strong>EXPERIMENTAL</strong>. This class or interface has been added as part of a work in
30  * progress. There is a guarantee neither that this API will work nor that it will remain the same.
31  * Please do not use this API without consulting with the Platform/UI team.
32  * </p>
33  *
34  * @since 3.2
35  */

36 public class NavigatorUIPluginImages {
37
38     private static URL JavaDoc fgIconLocation;
39
40     // Create image registry
41
private final static ImageRegistry NAVIGATORUIPLUGIN_REGISTRY = NavigatorPlugin.getDefault().getImageRegistry();
42
43     // Create the icon location
44
static {
45         String JavaDoc pathSuffix = "icons/full/"; //$NON-NLS-1$
46
fgIconLocation = FileLocator.find(NavigatorPlugin.getDefault().getBundle(), new Path(pathSuffix), Collections.EMPTY_MAP);
47     }
48
49     /**
50      * Gets the current image.
51      *
52      * @param key -
53      * Name of the icon.
54      * @return Image
55      */

56     public static Image get(String JavaDoc key) {
57         return NAVIGATORUIPLUGIN_REGISTRY.get(key);
58     }
59
60     /**
61      * Create and returns a image descriptor.
62      *
63      * @param String
64      * prefix - Icon dir structure.
65      * @param String
66      * name - The name of the icon.
67      * @return ImageDescriptor
68      */

69     private static ImageDescriptor create(String JavaDoc prefix, String JavaDoc name) {
70         return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
71     }
72
73     /**
74      * Creates the icon url
75      *
76      * @param String
77      * prefix - Icon dir structure.
78      * @param String
79      * name - The name of the icon.
80      * @return URL
81      */

82     private static URL JavaDoc makeIconFileURL(String JavaDoc prefix, String JavaDoc name) {
83         StringBuffer JavaDoc buffer = new StringBuffer JavaDoc(prefix);
84         buffer.append(name);
85         try {
86             return new URL JavaDoc(fgIconLocation, buffer.toString());
87         } catch (MalformedURLException JavaDoc ex) {
88
89             return null;
90         }
91     }
92
93     /**
94      * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
95      * are retrieved from the *lcl16 folders.
96      *
97      * @param action
98      * the action
99      * @param iconName
100      * the icon name
101      */

102     public static void setLocalImageDescriptors(IAction action, String JavaDoc iconName) {
103         setImageDescriptors(action, "lcl16/", iconName); //$NON-NLS-1$
104
}
105
106     /**
107      * Sets all available image descriptors for the given action.
108      *
109      * @param action -
110      * The action associated with the icon.
111      * @param type -
112      * The type of icon.
113      * @param relPath -
114      * The relative path of the icon.
115      */

116     public static void setImageDescriptors(IAction action, String JavaDoc type, String JavaDoc relPath) {
117         // /*relPath= relPath.substring(NAVIGATORUI_NAME_PREFIX_LENGTH);*/
118
// action.setDisabledImageDescriptor(create("d" + type, relPath));
119
// //$NON-NLS-1$
120
// action.setHoverImageDescriptor(create("c" + type, relPath));
121
// //$NON-NLS-1$
122
action.setImageDescriptor(create("e" + type, relPath)); //$NON-NLS-1$
123
}
124
125 }
126
Popular Tags