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.";
17 protected static final int NAME_PREFIX_LENGTH = NAME_PREFIX.length();
19 protected static URL iconBaseURL;
22 iconBaseURL = PHPDebugUiPlugin.getDefault().getBundle().getEntry(
23 "/icons/"); //$NON-NLS-1$
27 * static { String pathSuffix = "icons/"; try { iconBaseURL = new
28 * URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(),
29 * pathSuffix); } catch (MalformedURLException e) { PHPDebugUiPlugin.log(e); } }
31 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
33 protected static final String CTOOL_PREFIX = "ctool16";
35 protected static final String EVIEW_PREFIX = "eview16";
37 public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX
38 + "arguments_tab.gif";
40 public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(
41 EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB);
44 * Returns the image managed under the given key in this registry.
48 * @return the image managed under the given key
50 public static Image get(String key) {
51 return IMAGE_REGISTRY.get(key);
55 * Sets the three image descriptors for enabled, disabled, and hovered to an
56 * action. The actions are retrieved from the *tool16 folders.
58 public static void setToolImageDescriptors(IAction action, String iconName) {
59 setImageDescriptors(action, "tool16", iconName);
63 * Sets the three image descriptors for enabled, disabled, and hovered to an
64 * action. The actions are retrieved from the *lcl16 folders.
66 public static void setLocalImageDescriptors(IAction action, String iconName) {
67 setImageDescriptors(action, "lcl16", iconName);
70 public static ImageRegistry getImageRegistry() {
71 return IMAGE_REGISTRY;
74 // ---- Helper methods to access icons on the file system
75 // --------------------------------------
77 protected static void setImageDescriptors(IAction action, String type,
81 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL(
82 "d" + type, relPath));
84 action.setDisabledImageDescriptor(id);
85 } catch (MalformedURLException e) {
89 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL(
90 "c" + type, relPath));
92 action.setHoverImageDescriptor(id);
93 } catch (MalformedURLException e) {
96 action.setImageDescriptor(create("e" + type, relPath));
99 protected static ImageDescriptor createManaged(String prefix, String name) {
101 ImageDescriptor result = ImageDescriptor
102 .createFromURL(makeIconFileURL(prefix, name
103 .substring(NAME_PREFIX_LENGTH)));
104 IMAGE_REGISTRY.put(name, result);
106 } catch (MalformedURLException e) {
107 return ImageDescriptor.getMissingImageDescriptor();
111 protected static ImageDescriptor create(String prefix, String name) {
113 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
114 } catch (MalformedURLException e) {
115 return ImageDescriptor.getMissingImageDescriptor();
119 protected static URL makeIconFileURL(String prefix, String name)
120 throws MalformedURLException {
121 if (iconBaseURL == null)
122 throw new MalformedURLException();
124 StringBuffer buffer = new StringBuffer(prefix);
127 return new URL(iconBaseURL, buffer.toString());