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;
20 String pathSuffix = "icons/";
22 iconBaseURL = new URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
23 } catch (MalformedURLException e) {
24 PHPDebugUiPlugin.log(e);
28 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
30 protected static final String CTOOL_PREFIX = "ctool16";
31 protected static final String EVIEW_PREFIX = "eview16";
33 public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX + "arguments_tab.gif";
35 public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB);
38 * Returns the image managed under the given key in this registry.
40 * @param key the image's key
41 * @return the image managed under the given key
43 public static Image get(String key) {
44 return IMAGE_REGISTRY.get(key);
48 * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
49 * are retrieved from the *tool16 folders.
51 public static void setToolImageDescriptors(IAction action, String iconName) {
52 setImageDescriptors(action, "tool16", iconName);
56 * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
57 * are retrieved from the *lcl16 folders.
59 public static void setLocalImageDescriptors(IAction action, String iconName) {
60 setImageDescriptors(action, "lcl16", iconName);
63 public static ImageRegistry getImageRegistry() {
64 return IMAGE_REGISTRY;
67 //---- Helper methods to access icons on the file system --------------------------------------
69 protected static void setImageDescriptors(IAction action, String type, String relPath) {
72 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath));
74 action.setDisabledImageDescriptor(id);
75 } catch (MalformedURLException e) {}
78 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath));
80 action.setHoverImageDescriptor(id);
81 } catch (MalformedURLException e) {}
83 action.setImageDescriptor(create("e" + type, relPath));
86 protected static ImageDescriptor createManaged(String prefix, String name) {
88 ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
89 IMAGE_REGISTRY.put(name, result);
91 } catch (MalformedURLException e) {
92 return ImageDescriptor.getMissingImageDescriptor();
96 protected static ImageDescriptor create(String prefix, String name) {
98 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
99 } catch (MalformedURLException e) {
100 return ImageDescriptor.getMissingImageDescriptor();
104 protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
105 if (iconBaseURL == null)
106 throw new MalformedURLException();
108 StringBuffer buffer = new StringBuffer(prefix);
111 return new URL(iconBaseURL, buffer.toString());