2 * Copyright (c) 2002-2004 Adrian Dinu and others.
3 * All rights reserved. This program and the accompanying materials
4 * are made available under the terms of the Common Public License v1.0
5 * which accompanies this distribution, and is available at
6 * http://www.eclipse.org/legal/cpl-v10.html
9 * Adrian Dinu - initial implementation
10 * Alex Fitzpatrick - additional images
11 * Christopher Lenz - migration to use the plugin's image registry
13 * $Id: JSImages.java,v 1.1 2004-09-02 18:23:49 jsurfer Exp $
16 package net.sourceforge.phpeclipse.js.ui.editors;
20 import net.sourceforge.phpeclipse.js.ui.JSUIPlugin;
22 import org.eclipse.jface.resource.ImageDescriptor;
23 import org.eclipse.jface.resource.ImageRegistry;
24 import org.eclipse.swt.graphics.Image;
27 * Convenience class for storing references to image descriptors used by the JS
30 public class JSImages {
32 public static final String ICON_VAR =
33 "global_variable.gif"; //$NON-NLS-1$
34 public static final String ICON_FUNCTION =
35 "func.gif"; //$NON-NLS-1$
36 public static final String ICON_CLASS =
37 "class_obj.gif"; //$NON-NLS-1$
38 public static final String ICON_DYNAMIC_CLASS =
39 "dyn_class_obj.gif"; //$NON-NLS-1$
40 public static final String ICON_CLASS_METHOD =
41 "class_method.gif"; //$NON-NLS-1$
42 public static final String ICON_INSTANCE_METHOD =
43 "instance_method.gif"; //$NON-NLS-1$
44 public static final String ICON_CLASS_VAR =
45 "class_variable.gif"; //$NON-NLS-1$
46 public static final String ICON_INSTANCE_VAR =
47 "instance_variable.gif"; //$NON-NLS-1$
50 * Returns the image for the specified key, or <tt>null</tt> if no image for
53 * @param key the key under which the image was registered
54 * @return the image, or <tt>null</tt> if none
56 public static Image get(String key) {
57 return JSUIPlugin.getDefault().getImageRegistry().get(key);
61 * Returns the image descriptor for the specified key, or <tt>null</tt> if
62 * no image for that key is found.
64 * @param key the key under which the image was registered
65 * @return the image descriptor, or <tt>null</tt> if none
67 public static ImageDescriptor getDescriptor(String key) {
68 return JSUIPlugin.getDefault().getImageRegistry().getDescriptor(key);
72 * Initializes the given image registry with all images provided through
75 * @param reg the registry to initialize
77 public static void initializeRegistry(ImageRegistry reg) {
78 reg.put(ICON_VAR, createImageDescriptor(ICON_VAR));
79 reg.put(ICON_FUNCTION, createImageDescriptor(ICON_FUNCTION));
80 reg.put(ICON_CLASS, createImageDescriptor(ICON_CLASS));
81 reg.put(ICON_DYNAMIC_CLASS, createImageDescriptor(ICON_DYNAMIC_CLASS));
82 reg.put(ICON_CLASS_METHOD, createImageDescriptor(ICON_CLASS_METHOD));
83 reg.put(ICON_INSTANCE_METHOD,
84 createImageDescriptor(ICON_INSTANCE_METHOD));
85 reg.put(ICON_CLASS_VAR, createImageDescriptor(ICON_CLASS_VAR));
86 reg.put(ICON_INSTANCE_VAR, createImageDescriptor(ICON_INSTANCE_VAR));
90 * Utility method to create an <code>ImageDescriptor</code> from a path to a
93 * @param path the full path to the image file
94 * @return the image descriptor
96 private static ImageDescriptor createImageDescriptor(String path) {
98 URL url = JSUIPlugin.getDefault().getBundle()
99 .getEntry("/icons/" + path); //$NON-NLS-1$
100 return ImageDescriptor.createFromURL(url);
101 } catch (IllegalStateException e) {
102 return ImageDescriptor.getMissingImageDescriptor();