1 package net.sourceforge.phpdt.externaltools.internal.model;
3 /**********************************************************************
4 Copyright (c) 2002 IBM Corp. and others. All rights reserved.
5 This file is made available under the terms of the Common Public License v1.0
6 which accompanies this distribution, and is available at
7 http://www.eclipse.org/legal/cpl-v10.html
10 **********************************************************************/
12 import java.net.MalformedURLException;
14 import java.util.HashMap;
16 import net.sourceforge.phpdt.externaltools.internal.ui.IExternalToolsUIConstants;
17 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
19 import org.eclipse.jface.resource.ImageDescriptor;
20 import org.eclipse.jface.resource.ImageRegistry;
21 import org.eclipse.swt.graphics.Image;
22 import org.eclipse.ui.externaltools.internal.model.ExternalToolsPlugin;
25 * The images provided by the external tools plugin.
27 public class ExternalToolsImages {
30 * The image registry containing <code>Image</code>s.
32 private static ImageRegistry imageRegistry;
35 * A table of all the <code>ImageDescriptor</code>s.
37 private static HashMap imageDescriptors;
39 //private static final String ATTR_LAUNCH_CONFIG_TYPE_ICON = "icon"; //$NON-NLS-1$
41 //private static final String ATTR_LAUNCH_CONFIG_TYPE_ID = "configTypeID"; //$NON-NLS-1$
43 /* Declare Common paths */
44 private static URL ICON_BASE_URL = null;
47 // String pathSuffix = "icons/externaltools/full/"; //$NON-NLS-1$
51 // URL(PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL(),
53 // } catch (MalformedURLException e) {
58 String pathSuffix = "icons/full/"; //$NON-NLS-1$
59 ICON_BASE_URL = ExternalToolsPlugin.getDefault().getBundle().getEntry(
63 // Use IPath and toOSString to build the names to ensure they have the
65 //private final static String CTOOL = "ctool16/"; // basic colors - size 16x16
68 private final static String LOCALTOOL = "clcl16/"; // basic colors - size
69 // 16x16 //$NON-NLS-1$
71 //private final static String DLCL = "dlcl16/"; // disabled - size 16x16
74 //private final static String ELCL = "elcl16/"; // enabled - size 16x16
77 private final static String OBJECT = "obj16/"; // basic colors - size 16x16
80 private final static String WIZBAN = "wizban/"; // basic colors - size 16x16
83 //private final static String OVR = "ovr16/"; // basic colors - size 7x8
86 //private final static String VIEW = "cview16/"; // views //$NON-NLS-1$
91 private static void declareImages() {
93 declareRegistryImage(IExternalToolsUIConstants.IMG_REMOVE, LOCALTOOL
94 + "remove_co.gif"); //$NON-NLS-1$
95 declareRegistryImage(IExternalToolsUIConstants.IMG_REMOVE_ALL,
96 LOCALTOOL + "removeAll_co.gif"); //$NON-NLS-1$
97 declareRegistryImage(IExternalToolsUIConstants.IMG_ADD, LOCALTOOL
98 + "add_co.gif"); //$NON-NLS-1$
99 declareRegistryImage(IExternalToolsUIConstants.IMG_RUN, LOCALTOOL
100 + "run_tool.gif"); //$NON-NLS-1$
101 declareRegistryImage(IExternalToolsUIConstants.IMG_SEARCH, LOCALTOOL
102 + "search.gif"); //$NON-NLS-1$
103 declareRegistryImage(IExternalToolsUIConstants.IMG_MOVE_UP, LOCALTOOL
104 + "moveUp.gif"); //$NON-NLS-1$
105 declareRegistryImage(IExternalToolsUIConstants.IMG_MOVE_DOWN, LOCALTOOL
106 + "moveDown.gif"); //$NON-NLS-1$
107 declareRegistryImage(IExternalToolsUIConstants.IMG_ACTIVATE, LOCALTOOL
108 + "activate.gif"); //$NON-NLS-1$
109 declareRegistryImage(IExternalToolsUIConstants.IMG_DEACTIVATE,
110 LOCALTOOL + "deactivate.gif"); //$NON-NLS-1$
111 declareRegistryImage(IExternalToolsUIConstants.IMG_GO_TO_FILE,
112 LOCALTOOL + "gotoobj_tsk.gif"); //$NON-NLS-1$
114 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_PROJECT,
115 // OBJECT + "file_obj.gif"); //$NON-NLS-1$
116 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_PROJECT_ERROR,
117 // LOCALTOOL + "ant_project_err.gif"); //$NON-NLS-1$
118 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET,
119 // LOCALTOOL + "ant_target.gif"); //$NON-NLS-1$
120 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ERROR,
121 // LOCALTOOL + "error.gif"); //$NON-NLS-1$
122 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ELEMENTS,
123 // LOCALTOOL + "elements.gif"); //$NON-NLS-1$
124 // declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ELEMENT,
125 // LOCALTOOL + "element.gif"); //$NON-NLS-1$
127 declareRegistryImage(IExternalToolConstants.IMG_WIZBAN_EXTERNAL_TOOLS,
128 WIZBAN + "ext_tools_wiz.gif"); //$NON-NLS-1$
131 declareRegistryImage(IExternalToolConstants.IMG_ACTION_REFRESH,
132 LOCALTOOL + "refresh.gif"); //$NON-NLS-1$
135 declareRegistryImage(IExternalToolConstants.IMG_TAB_MAIN, OBJECT
136 + "main_tab.gif"); //$NON-NLS-1$
137 declareRegistryImage(IExternalToolConstants.IMG_TAB_OPTIONS, OBJECT
138 + "options_tab.gif"); //$NON-NLS-1$
141 declareRegistryImage(IExternalToolConstants.IMG_TAB_ANT_TARGETS,
142 LOCALTOOL + "ant_tsk_check.gif"); //$NON-NLS-1$
146 * Declare an Image in the registry table.
149 * The key to use when registering the image
151 * The path where the image can be found. This path is relative
152 * to where this plugin class is found (i.e. typically the
153 * packages directory)
155 private final static void declareRegistryImage(String key, String path) {
156 ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
158 desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
159 } catch (MalformedURLException me) {
160 // ExternalToolsPlugin.log(me);
162 imageRegistry.put(key, desc);
163 imageDescriptors.put(key, desc);
167 * Returns the ImageRegistry.
169 public static ImageRegistry getImageRegistry() {
170 if (imageRegistry == null) {
171 initializeImageRegistry();
173 return imageRegistry;
177 * Initialize the image registry by declaring all of the required graphics.
178 * This involves creating JFace image descriptors describing how to
179 * create/find the image should it be needed. The image is not actually
180 * allocated until requested.
182 * Prefix conventions Wizard Banners WIZBAN_ Preference Banners PREF_BAN_
183 * Property Page Banners PROPBAN_ Color toolbar CTOOL_ Enable toolbar ETOOL_
184 * Disable toolbar DTOOL_ Local enabled toolbar ELCL_ Local Disable toolbar
185 * DLCL_ Object large OBJL_ Object small OBJS_ View VIEW_ Product images
186 * PROD_ Misc images MISC_
188 * Where are the images? The images (typically gifs) are found in the same
189 * location as this plugin class. This may mean the same package directory
190 * as the package holding this class. The images are declared using
191 * this.getClass() to ensure they are looked up via this plugin class.
193 * @see JFace's ImageRegistry
195 public static ImageRegistry initializeImageRegistry() {
196 imageRegistry = new ImageRegistry(ExternalToolsPlugin
197 .getStandardDisplay());
198 imageDescriptors = new HashMap(30);
200 return imageRegistry;
204 * Returns the <code>Image<code> identified by the given key,
205 * or <code>null</code> if it does not exist.
207 public static Image getImage(String key) {
208 return getImageRegistry().get(key);
212 * Returns the <code>ImageDescriptor<code> identified by the given key,
213 * or <code>null</code> if it does not exist.
215 public static ImageDescriptor getImageDescriptor(String key) {
216 if (imageDescriptors == null) {
217 initializeImageRegistry();
219 return (ImageDescriptor) imageDescriptors.get(key);
222 private static URL makeIconFileURL(String iconPath)
223 throws MalformedURLException {
224 if (ICON_BASE_URL == null) {
225 throw new MalformedURLException();
228 return new URL(ICON_BASE_URL, iconPath);