Modified: 1764120 - Variables View doesn't show global vars in class context
[phpeclipse.git] / net.sourceforge.phpeclipse.xdebug.ui / src / net / sourceforge / phpeclipse / xdebug / ui / XDebugUIPluginImages.java
1 /*******************************************************************************
2  * Copyright (c) 2000, 2004 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Common Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/cpl-v10.html
7  * 
8  * Contributors:
9  *     IBM Corporation - initial API and implementation
10  *******************************************************************************/
11 package net.sourceforge.phpeclipse.xdebug.ui;
12
13 import java.net.MalformedURLException;
14 import java.net.URL;
15
16 import org.eclipse.jface.resource.ImageDescriptor;
17 import org.eclipse.jface.resource.ImageRegistry;
18 import org.eclipse.swt.graphics.Image;
19
20 public class XDebugUIPluginImages {
21
22         /* Declare Common paths */
23         private static URL ICON_BASE_URL = null;
24
25         static {
26                 String pathSuffix = "icons/"; //$NON-NLS-1$
27                 ICON_BASE_URL = XDebugUIPlugin.getDefault().getBundle().getEntry(
28                                 pathSuffix);
29         }
30
31         // The plugin registry
32         private static ImageRegistry fgImageRegistry = null;
33
34         /*
35          * Set of predefined Image Descriptors.
36          */
37         private static final String T_OBJ = "obj16/"; //$NON-NLS-1$
38         // private static final String T_OVR= "ovr16/"; //$NON-NLS-1$
39
40         private static final String T_EVIEW = "eview16/"; //$NON-NLS-1$
41
42         private static final String T_LCL = "elcl16/";
43
44         public static final String IMG_EVIEW_ARGUMENTS_TAB = "IMG_EVIEW_ARGUMENTS_TAB";
45
46         public static final String IMG_EVIEW_ENVIROMENT_TAB = "IMG_EVIEW_ENVIROMENT_TAB";
47
48         public static final String IMG_PREV_EVENT = "IMG_PREV_EVENT";
49
50         public static final String DESC_NEXT_EVENT = "DESC_NEXT_EVENT";
51
52         public static final String IMG_ERROR_ST_OBJ = "IMG_ERROR_ST_OBJ";
53
54         public static final String IMG_WARNING_ST_OBJ = "IMG_WARNING_ST_OBJ";
55
56         public static final String IMG_INFO_ST_OBJ = "IMG_INFO_ST_OBJ";
57
58         public static final String IMG_ERROR_STACK_OBJ = "IMG_ERROR_STACK_OBJ";
59
60         public static final String IMG_PROPERTIES = "IMG_PROPERTIES";
61
62         // public static final String IMG_PROPERTIES_DISABLED =
63         // "IMG_PROPERTIES_DISABLED";
64         public static final String IMG_CLEAR = "IMG_CLEAR";
65
66         // public static final String IMG_CLEAR_DISABLED = "IMG_CLEAR_DISABLED";
67         public static final String IMG_READ_LOG = "IMG_READ_LOG";
68
69         // public static final String IMG_READ_LOG_DISABLED =
70         // "IMG_READ_LOG_DISABLED";
71         public static final String IMG_REMOVE_LOG = "IMG_REMOVE_LOG";
72
73         // public static final String IMG_REMOVE_LOG_DISABLED =
74         // "IMG_REMOVE_LOG_DISABLED";
75         public static final String IMG_FILTER = "IMG_FILTER";
76
77         // public static final String IMG_FILTER_DISABLED = "IMG_FILTER_DISABLED";
78         public static final String IMG_EXPORT = "IMG_EXPORT";
79
80         // public static final String IMG_EXPORT_DISABLED = "IMG_EXPORT_DISABLED";
81         public static final String IMG_IMPORT = "IMG_IMPORT";
82
83         // public static final String IMG_IMPORT_DISABLED = "IMG_IMPORT_DISABLED";
84         public static final String IMG_OPEN_LOG = "IMG_OPEN_LOG";
85
86         /**
87          * Returns the image managed under the given key in this registry.
88          * 
89          * @param key
90          *            the image's key
91          * @return the image managed under the given key
92          */
93         public static Image get(String key) {
94                 return getImageRegistry().get(key);
95         }
96
97         /**
98          * Returns the <code>ImageDescriptor</code> identified by the given key,
99          * or <code>null</code> if it does not exist.
100          */
101         public static ImageDescriptor getImageDescriptor(String key) {
102                 return getImageRegistry().getDescriptor(key);
103         }
104
105         /*
106          * Helper method to access the image registry from the XDebugUIPlugin class.
107          */
108         public static ImageRegistry getImageRegistry() {
109                 if (fgImageRegistry == null) {
110                         initializeImageRegistry();
111                 }
112                 return fgImageRegistry;
113         }
114
115         public static void initializeImageRegistry() {
116                 fgImageRegistry = new ImageRegistry(XDebugUIPlugin.getStandardDisplay());
117                 declareImages();
118         }
119
120         private static void declareImages() {
121                 declareRegistryImage(IMG_EVIEW_ARGUMENTS_TAB, T_EVIEW
122                                 + "arguments_tab.gif"); //$NON-NLS-1$
123                 declareRegistryImage(IMG_EVIEW_ENVIROMENT_TAB, T_EVIEW
124                                 + "environment_tab.gif"); //$NON-NLS-1$
125
126                 declareRegistryImage(IMG_ERROR_ST_OBJ, T_OBJ + "error_st_obj.gif");
127                 declareRegistryImage(IMG_WARNING_ST_OBJ, T_OBJ + "warning_st_obj.gif");
128                 declareRegistryImage(IMG_INFO_ST_OBJ, T_OBJ + "info_st_obj.gif");
129                 declareRegistryImage(IMG_ERROR_STACK_OBJ, T_OBJ + "error_stack.gif");
130
131                 declareRegistryImage(IMG_PROPERTIES, T_LCL + "properties.gif");
132                 // declareRegistryImage(IMG_PROPERTIES_DISABLED
133                 declareRegistryImage(IMG_CLEAR, T_LCL + "clear_log.gif");
134                 // declareRegistryImage(IMG_CLEAR_DISABLED
135                 declareRegistryImage(IMG_READ_LOG, T_LCL + "restore_log.gif");
136                 // declareRegistryImage(IMG_READ_LOG_DISABLED
137                 declareRegistryImage(IMG_REMOVE_LOG, T_LCL + "remove_log.gif");
138                 // declareRegistryImage(IMG_REMOVE_LOG_DISABLED
139                 declareRegistryImage(IMG_FILTER, T_LCL + "filter_log.gif");
140                 // declareRegistryImage(IMG_FILTER_DISABLED
141                 declareRegistryImage(IMG_EXPORT, T_LCL + "export_log.gif");
142                 // declareRegistryImage(IMG_EXPORT_DISABLED
143                 declareRegistryImage(IMG_IMPORT, T_LCL + "import_log.gif");
144                 // declareRegistryImage(IMG_IMPORT_DISABLED
145                 declareRegistryImage(IMG_OPEN_LOG, T_LCL + "open_log.gif");
146
147         }
148
149         /**
150          * Declare an Image in the registry table.
151          * 
152          * @param key
153          *            The key to use when registering the image
154          * @param path
155          *            The path where the image can be found. This path is relative
156          *            to where this plugin class is found (i.e. typically the
157          *            packages directory)
158          */
159         private final static void declareRegistryImage(String key, String path) {
160                 ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
161                 try {
162                         desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
163                 } catch (MalformedURLException me) {
164                         XDebugUIPlugin.log(me);
165                 }
166                 fgImageRegistry.put(key, desc);
167         }
168
169         private static URL makeIconFileURL(String iconPath)
170                         throws MalformedURLException {
171                 if (ICON_BASE_URL == null) {
172                         throw new MalformedURLException();
173                 }
174
175                 return new URL(ICON_BASE_URL, iconPath);
176         }
177
178 }