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.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;
15 public class PHPDebugUiImages {
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;
23 iconBaseURL= PHPDebugUiPlugin.getDefault().getBundle().getEntry("/icons/"); //$NON-NLS-1$
27 String pathSuffix = "icons/";
29 iconBaseURL = new URL(PHPDebugUiPlugin.getDefault().getDescriptor().getInstallURL(), pathSuffix);
30 } catch (MalformedURLException e) {
31 PHPDebugUiPlugin.log(e);
35 protected static final ImageRegistry IMAGE_REGISTRY = new ImageRegistry();
37 protected static final String CTOOL_PREFIX = "ctool16";
38 protected static final String EVIEW_PREFIX = "eview16";
40 public static final String IMG_EVIEW_ARGUMENTS_TAB = NAME_PREFIX + "arguments_tab.gif";
42 public static final ImageDescriptor DESC_EVIEW_ARGUMENTS_TAB = createManaged(EVIEW_PREFIX, IMG_EVIEW_ARGUMENTS_TAB);
45 * Returns the image managed under the given key in this registry.
47 * @param key the image's key
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 action. The actions
56 * 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 action. The actions
64 * 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 --------------------------------------
76 protected static void setImageDescriptors(IAction action, String type, String relPath) {
79 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("d" + type, relPath));
81 action.setDisabledImageDescriptor(id);
82 } catch (MalformedURLException e) {}
85 ImageDescriptor id = ImageDescriptor.createFromURL(makeIconFileURL("c" + type, relPath));
87 action.setHoverImageDescriptor(id);
88 } catch (MalformedURLException e) {}
90 action.setImageDescriptor(create("e" + type, relPath));
93 protected static ImageDescriptor createManaged(String prefix, String name) {
95 ImageDescriptor result = ImageDescriptor.createFromURL(makeIconFileURL(prefix, name.substring(NAME_PREFIX_LENGTH)));
96 IMAGE_REGISTRY.put(name, result);
98 } catch (MalformedURLException e) {
99 return ImageDescriptor.getMissingImageDescriptor();
103 protected static ImageDescriptor create(String prefix, String name) {
105 return ImageDescriptor.createFromURL(makeIconFileURL(prefix, name));
106 } catch (MalformedURLException e) {
107 return ImageDescriptor.getMissingImageDescriptor();
111 protected static URL makeIconFileURL(String prefix, String name) throws MalformedURLException {
112 if (iconBaseURL == null)
113 throw new MalformedURLException();
115 StringBuffer buffer = new StringBuffer(prefix);
118 return new URL(iconBaseURL, buffer.toString());