inital plugin from webtools project
[phpeclipse.git] / net.sourceforge.phpeclipse / src / net / sourceforge / phpdt / externaltools / internal / model / ExternalToolsImages.java
1 package net.sourceforge.phpdt.externaltools.internal.model;
2
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
8  
9 Contributors:
10 **********************************************************************/
11
12 import java.net.MalformedURLException;
13 import java.net.URL;
14 import java.util.HashMap;
15
16 import net.sourceforge.phpdt.externaltools.internal.ui.IExternalToolsUIConstants;
17 import net.sourceforge.phpdt.externaltools.model.IExternalToolConstants;
18 import net.sourceforge.phpeclipse.PHPeclipsePlugin;
19
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.externaltools.internal.model.ExternalToolsPlugin;
24
25 /**
26  * The images provided by the external tools plugin.
27  */
28 public class ExternalToolsImages {
29
30         /** 
31          * The image registry containing <code>Image</code>s.
32          */
33         private static ImageRegistry imageRegistry;
34         
35         /**
36          * A table of all the <code>ImageDescriptor</code>s.
37          */
38         private static HashMap imageDescriptors;
39
40         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$
42         
43         /* Declare Common paths */
44         private static URL ICON_BASE_URL= null;
45
46 //      static {
47 //              String pathSuffix = "icons/externaltools/full/"; //$NON-NLS-1$
48 //                      
49 //              try {
50 //                      ICON_BASE_URL= new URL(PHPeclipsePlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
51 //              } catch (MalformedURLException e) {
52 //                      // do nothing
53 //              }
54 //      }
55         static {
56                 String pathSuffix = "icons/full/"; //$NON-NLS-1$        
57                 ICON_BASE_URL= ExternalToolsPlugin.getDefault().getBundle().getEntry(pathSuffix);
58         }
59
60         // Use IPath and toOSString to build the names to ensure they have the slashes correct
61         private final static String CTOOL= "ctool16/"; //basic colors - size 16x16 //$NON-NLS-1$
62         private final static String LOCALTOOL= "clcl16/"; //basic colors - size 16x16 //$NON-NLS-1$
63         private final static String DLCL= "dlcl16/"; //disabled - size 16x16 //$NON-NLS-1$
64         private final static String ELCL= "elcl16/"; //enabled - size 16x16 //$NON-NLS-1$
65         private final static String OBJECT= "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
66         private final static String WIZBAN= "wizban/"; //basic colors - size 16x16 //$NON-NLS-1$
67         private final static String OVR= "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$
68         private final static String VIEW= "cview16/"; // views //$NON-NLS-1$
69         
70         /**
71          * Declare all images
72          */
73         private static void declareImages() {
74                 // Ant View Actions
75                 declareRegistryImage(IExternalToolsUIConstants.IMG_REMOVE, LOCALTOOL + "remove_co.gif"); //$NON-NLS-1$
76                 declareRegistryImage(IExternalToolsUIConstants.IMG_REMOVE_ALL, LOCALTOOL + "removeAll_co.gif"); //$NON-NLS-1$
77                 declareRegistryImage(IExternalToolsUIConstants.IMG_ADD, LOCALTOOL + "add_co.gif"); //$NON-NLS-1$
78                 declareRegistryImage(IExternalToolsUIConstants.IMG_RUN, LOCALTOOL + "run_tool.gif"); //$NON-NLS-1$
79                 declareRegistryImage(IExternalToolsUIConstants.IMG_SEARCH, LOCALTOOL + "search.gif"); //$NON-NLS-1$
80                 declareRegistryImage(IExternalToolsUIConstants.IMG_MOVE_UP, LOCALTOOL + "moveUp.gif"); //$NON-NLS-1$
81                 declareRegistryImage(IExternalToolsUIConstants.IMG_MOVE_DOWN, LOCALTOOL + "moveDown.gif"); //$NON-NLS-1$
82                 declareRegistryImage(IExternalToolsUIConstants.IMG_ACTIVATE, LOCALTOOL + "activate.gif"); //$NON-NLS-1$
83                 declareRegistryImage(IExternalToolsUIConstants.IMG_DEACTIVATE, LOCALTOOL + "deactivate.gif"); //$NON-NLS-1$
84                 declareRegistryImage(IExternalToolsUIConstants.IMG_GO_TO_FILE, LOCALTOOL + "gotoobj_tsk.gif"); //$NON-NLS-1$
85                 // Ant View Labels
86 //              declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_PROJECT, OBJECT + "file_obj.gif"); //$NON-NLS-1$
87 //              declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_PROJECT_ERROR, LOCALTOOL + "ant_project_err.gif"); //$NON-NLS-1$
88 //              declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET, LOCALTOOL + "ant_target.gif"); //$NON-NLS-1$
89 //              declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ERROR, LOCALTOOL + "error.gif"); //$NON-NLS-1$
90 //              declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ELEMENTS, LOCALTOOL + "elements.gif"); //$NON-NLS-1$
91 //              declareRegistryImage(IExternalToolsUIConstants.IMG_ANT_TARGET_ELEMENT, LOCALTOOL + "element.gif"); //$NON-NLS-1$
92                 // Wizards
93                 declareRegistryImage(IExternalToolConstants.IMG_WIZBAN_EXTERNAL_TOOLS, WIZBAN + "ext_tools_wiz.gif"); //$NON-NLS-1$
94                 
95                 // Actions
96                 declareRegistryImage(IExternalToolConstants.IMG_ACTION_REFRESH, LOCALTOOL + "refresh.gif"); //$NON-NLS-1$
97                 
98                 // Objects
99                 declareRegistryImage(IExternalToolConstants.IMG_TAB_MAIN, OBJECT + "main_tab.gif"); //$NON-NLS-1$
100                 declareRegistryImage(IExternalToolConstants.IMG_TAB_OPTIONS, OBJECT + "options_tab.gif"); //$NON-NLS-1$
101                 
102                 //ANT object
103                 declareRegistryImage(IExternalToolConstants.IMG_TAB_ANT_TARGETS, LOCALTOOL + "ant_tsk_check.gif"); //$NON-NLS-1$
104         }
105
106         /**
107          * Declare an Image in the registry table.
108          * @param key   The key to use when registering the image
109          * @param path  The path where the image can be found. This path is relative to where
110          *                              this plugin class is found (i.e. typically the packages directory)
111          */
112         private final static void declareRegistryImage(String key, String path) {
113                 ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor();
114                 try {
115                         desc= ImageDescriptor.createFromURL(makeIconFileURL(path));
116                 } catch (MalformedURLException me) {
117                         //ExternalToolsPlugin.log(me);
118                 }
119                 imageRegistry.put(key, desc);
120                 imageDescriptors.put(key, desc);
121         }
122         
123         /**
124          * Returns the ImageRegistry.
125          */
126         public static ImageRegistry getImageRegistry() {
127                 if (imageRegistry == null) {
128                         initializeImageRegistry();
129                 }
130                 return imageRegistry;
131         }
132
133         /**
134          *      Initialize the image registry by declaring all of the required
135          *      graphics. This involves creating JFace image descriptors describing
136          *      how to create/find the image should it be needed.
137          *      The image is not actually allocated until requested.
138          *
139          *      Prefix conventions
140          *              Wizard Banners                  WIZBAN_
141          *              Preference Banners              PREF_BAN_
142          *              Property Page Banners   PROPBAN_
143          *              Color toolbar                   CTOOL_
144          *              Enable toolbar                  ETOOL_
145          *              Disable toolbar                 DTOOL_
146          *              Local enabled toolbar   ELCL_
147          *              Local Disable toolbar   DLCL_
148          *              Object large                    OBJL_
149          *              Object small                    OBJS_
150          *              View                                    VIEW_
151          *              Product images                  PROD_
152          *              Misc images                             MISC_
153          *
154          *      Where are the images?
155          *              The images (typically gifs) are found in the same location as this plugin class.
156          *              This may mean the same package directory as the package holding this class.
157          *              The images are declared using this.getClass() to ensure they are looked up via
158          *              this plugin class.
159          *      @see JFace's ImageRegistry
160          */
161         public static ImageRegistry initializeImageRegistry() {
162                 imageRegistry= new ImageRegistry(PHPeclipsePlugin.getStandardDisplay());
163                 imageDescriptors = new HashMap(30);
164                 declareImages();
165                 return imageRegistry;
166         }
167
168         /**
169          * Returns the <code>Image<code> identified by the given key,
170          * or <code>null</code> if it does not exist.
171          */
172         public static Image getImage(String key) {
173                 return getImageRegistry().get(key);
174         }
175         
176         /**
177          * Returns the <code>ImageDescriptor<code> identified by the given key,
178          * or <code>null</code> if it does not exist.
179          */
180         public static ImageDescriptor getImageDescriptor(String key) {
181                 if (imageDescriptors == null) {
182                         initializeImageRegistry();
183                 }
184                 return (ImageDescriptor)imageDescriptors.get(key);
185         }
186         
187         private static URL makeIconFileURL(String iconPath) throws MalformedURLException {
188                 if (ICON_BASE_URL == null) {
189                         throw new MalformedURLException();
190                 }
191                         
192                 return new URL(ICON_BASE_URL, iconPath);
193         }
194 }
195
196