1 package net.sourceforge.phpdt.debug.ui;
3 import java.net.MalformedURLException;
6 import org.eclipse.jface.action.IAction;
7 import org.eclipse.jface.resource.ImageDescriptor;
8 import org.eclipse.jface.resource.ImageRegistry;
9 import org.eclipse.swt.graphics.Image;
10 import net.sourceforge.phpdt.internal.debug.ui.PHPDebugUiPlugin;
12 public class PHPDebugUiImages {
14 protected static final String NAME_PREFIX = "net.sourceforge.phpdt.debug.ui.";
15 protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
16 protected static URL iconBaseURL;
19 String pathSuffix = "icons/";
21 iconBaseURL = new URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
22 } catch (MalformedURLException e) {
23 PHPDebugUiPlugin.log(e);
27 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
29 protected static final String CTOOL_PREFIX = "ctool16";
30 protected static final String EVIEW_PREFIX = "eview16";
32 public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX + "arguments_tab.gif";
34 public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB);
37 * Returns the image managed under the given key in this registry.
39 * @param key the image's key
40 * @return the image managed under the given key
42 public static Image get(String key) {
43 return IMAGE_REGISTRY.get(key);
47 * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
48 * are retrieved from the *tool16 folders.
50 public static void setToolImageDescriptors(IAction action, String iconName) {
51 setImageDescriptors(action, "tool16", iconName);
55 * Sets the three image descriptors for enabled, disabled, and hovered to an action. The actions
56 * are retrieved from the *lcl16 folders.
58 public static void setLocalImageDescriptors(IAction action, String iconName) {
59 setImageDescriptors(action, "lcl16", iconName);
62 public static ImageRegistry getImageRegistry() {
63 return IMAGE_REGISTRY;
66 //---- Helper methods to access icons on the file system --------------------------------------
68 protected static void setImageDescriptors(IAction action, String type, String relPath) {
71 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath));
73 action.setDisabledImageDescriptor(id);
74 } catch (MalformedURLException e) {}
77 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath));
79 action.setHoverImageDescriptor(id);
80 } catch (MalformedURLException e) {}
82 action.setImageDescriptor(create("e" + type, relPath));
85 protected static ImageDescriptor createManaged(String prefix, String name) {
87 ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
88 IMAGE_REGISTRY.put(name, result);
90 } catch (MalformedURLException e) {
91 return ImageDescriptor.getMissingImageDescriptor();
95 protected static ImageDescriptor create(String prefix, String name) {
97 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
98 } catch (MalformedURLException e) {
99 return ImageDescriptor.getMissingImageDescriptor();
103 protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
104 if (iconBaseURL == null)
105 throw new MalformedURLException();
107 StringBuffer buffer = new StringBuffer(prefix);
110 return new URL(iconBaseURL, buffer.toString());