1 package net.sourceforge.phpdt.debug.ui;
3 import java.net.MalformedURLException;
6 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
8 import org.eclipse.jface.action.IAction;
9 import org.eclipse.jface.resource.ImageDescriptor;
10 import org.eclipse.jface.resource.ImageRegistry;
11 import org.eclipse.swt.graphics.Image;
13 public class PHPDebugUiImages {
15 protected static final String NAME_PREFIX = "net.sourceforge.phpdt.debug.ui.";
16 protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
17 protected static URL iconBaseURL;
21 iconBaseURL= PHPDebugUiPlugin.getDefault().getBundle().getEntry("/icons/"); //$NON-NLS-1$
25 String pathSuffix = "icons/";
27 iconBaseURL = new URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
28 } catch (MalformedURLException e) {
29 PHPDebugUiPlugin.log(e);
33 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
35 protected static final String CTOOL_PREFIX = "ctool16";
36 protected static final String EVIEW_PREFIX = "eview16";
38 public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX + "arguments_tab.gif";
40 public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB);
43 * Returns the image managed under the given key in this registry.
45 * @param key the image's key
46 * @return the image managed under the given key
48 public static Image get(String key) {
49 return IMAGE_REGISTRY.get(key);
53 * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
54 * are retrieved from the *tool16 folders.
56 public static void setToolImageDescriptors(IAction action, String iconName) {
57 setImageDescriptors(action, "tool16", iconName);
61 * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
62 * are retrieved from the *lcl16 folders.
64 public static void setLocalImageDescriptors(IAction action, String iconName) {
65 setImageDescriptors(action, "lcl16", iconName);
68 public static ImageRegistry getImageRegistry() {
69 return IMAGE_REGISTRY;
72 //---- Helper methods to access icons on the file system --------------------------------------
74 protected static void setImageDescriptors(IAction action, String type, String relPath) {
77 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath));
79 action.setDisabledImageDescriptor(id);
80 } catch (MalformedURLException e) {}
83 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath));
85 action.setHoverImageDescriptor(id);
86 } catch (MalformedURLException e) {}
88 action.setImageDescriptor(create("e" + type, relPath));
91 protected static ImageDescriptor createManaged(String prefix, String name) {
93 ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
94 IMAGE_REGISTRY.put(name, result);
96 } catch (MalformedURLException e) {
97 return ImageDescriptor.getMissingImageDescriptor();
101 protected static ImageDescriptor create(String prefix, String name) {
103 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
104 } catch (MalformedURLException e) {
105 return ImageDescriptor.getMissingImageDescriptor();
109 protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
110 if (iconBaseURL == null)
111 throw new MalformedURLException();
113 StringBuffer buffer = new StringBuffer(prefix);
116 return new URL(iconBaseURL, buffer.toString());