Delete association of htmledit.gif for the PHPUnitEditor
[phpeclipse.git] / net.sourceforge.phpeclipse.debug.ui / src / net / sourceforge / phpdt / debug / ui / PHPDebugUiImages.java
1 package net.sourceforge.phpdt.debug.ui;
2
3 import java.net.MalformedURLException;
4 import java.net.URL;
5
6 // import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
7
8 //import org.eclipse.jdt.internal.ui.JavaPlugin;
9 import org.eclipse.jface.action.IAction;
10 import org.eclipse.jface.resource.ImageDescriptor;
11 import org.eclipse.jface.resource.ImageRegistry;
12 import org.eclipse.swt.graphics.Image;
13 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
14
15 public class PHPDebugUiImages {
16
17         protected static final String NAME_PREFIX = "net.sourceforge.phpdt.debug.ui.";
18         protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
19         protected static URL iconBaseURL;
20
21         
22         static {
23                 iconBaseURL= PHPDebugUiPlugin.getDefault().getBundle().getEntry("/icons/"); //$NON-NLS-1$
24         }
25 /*      
26         static {
27                 String pathSuffix = "icons/";
28                 try {
29                         iconBaseURL = new URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
30                 } catch (MalformedURLException e) {
31                         PHPDebugUiPlugin.log(e);
32                 }
33         }
34 */
35         protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
36
37         protected static final String CTOOL_PREFIX = "ctool16";
38         protected static final String EVIEW_PREFIX = "eview16";
39
40         public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX + "arguments_tab.gif";
41
42         public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB);
43
44         /**
45          * Returns the image managed under the given key in this registry.
46          * 
47          * @param key the image's key
48          * @return the image managed under the given key
49          */
50         public static Image get(String key) {
51                 return IMAGE_REGISTRY.get(key);
52         }
53
54         /**
55          * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
56          * are retrieved from the *tool16 folders.
57          */
58         public static void setToolImageDescriptors(IAction action, String iconName) {
59                 setImageDescriptors(action, "tool16", iconName);
60         }
61
62         /**
63          * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
64          * are retrieved from the *lcl16 folders.
65          */
66         public static void setLocalImageDescriptors(IAction action, String iconName) {
67                 setImageDescriptors(action, "lcl16", iconName);
68         }
69
70         public static ImageRegistry getImageRegistry() {
71                 return IMAGE_REGISTRY;
72         }
73
74         //---- Helper methods to access icons on the file system --------------------------------------
75
76         protected static void setImageDescriptors(IAction action, String type, String relPath) {
77
78                 try {
79                         ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath));
80                         if (id != null)
81                                 action.setDisabledImageDescriptor(id);
82                 } catch (MalformedURLException e) {}
83
84                 try {
85                         ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath));
86                         if (id != null)
87                                 action.setHoverImageDescriptor(id);
88                 } catch (MalformedURLException e) {}
89
90                 action.setImageDescriptor(create("e" + type, relPath));
91         }
92
93         protected static ImageDescriptor createManaged(String prefix, String name) {
94                 try {
95                         ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
96                         IMAGE_REGISTRY.put(name, result);
97                         return result;
98                 } catch (MalformedURLException e) {
99                         return ImageDescriptor.getMissingImageDescriptor();
100                 }
101         }
102
103         protected static ImageDescriptor create(String prefix, String name) {
104                 try {
105                         return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
106                 } catch (MalformedURLException e) {
107                         return ImageDescriptor.getMissingImageDescriptor();
108                 }
109         }
110
111         protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
112                 if (iconBaseURL == null)
113                         throw new MalformedURLException();
114
115                 StringBuffer buffer = new StringBuffer(prefix);
116                 buffer.append('/');
117                 buffer.append(name);
118                 return new URL(iconBaseURL, buffer.toString());
119         }
120 }