001: /*******************************************************************************
002: * Copyright (c) 2000, 2003 IBM Corporation and others.
003: * All rights reserved. This program and the accompanying materials
004: * are made available under the terms of the Eclipse Public License v1.0
005: * which accompanies this distribution, and is available at
006: * http://www.eclipse.org/legal/epl-v10.html
007: *
008: * Contributors:
009: * IBM Corporation - initial API and implementation
010: *******************************************************************************/package org.eclipse.jsp;
011:
012: import java.net.MalformedURLException;
013: import java.net.URL;
014: import java.util.HashMap;
015:
016: import org.eclipse.debug.core.DebugPlugin;
017: import org.eclipse.jface.resource.ImageDescriptor;
018: import org.eclipse.jface.resource.ImageRegistry;
019: import org.eclipse.swt.graphics.Image;
020:
021: /**
022: * The images provided by the debug plugin.
023: */
024: public class JspPluginImages {
025:
026: /**
027: * The image registry containing <code>Image</code>s.
028: */
029: private static ImageRegistry imageRegistry;
030:
031: /**
032: * A table of all the <code>ImageDescriptor</code>s.
033: */
034: private static HashMap imageDescriptors;
035:
036: /* Declare Common paths */
037: private static URL ICON_BASE_URL = null;
038:
039: static {
040: String pathSuffix = "icons/full/"; //$NON-NLS-1$
041:
042: try {
043: ICON_BASE_URL = new URL(JspUIPlugin.getDefault()
044: .getDescriptor().getInstallURL(), pathSuffix);
045: } catch (MalformedURLException e) {
046: // do nothing
047: }
048: }
049:
050: // Use IPath and toOSString to build the names to ensure they have the slashes correct
051: //private final static String CTOOL= "ctool16/"; //basic colors - size 16x16 //$NON-NLS-1$
052: //private final static String LOCALTOOL= "clcl16/"; //basic colors - size 16x16 //$NON-NLS-1$
053: //private final static String DLCL= "dlcl16/"; //disabled - size 16x16 //$NON-NLS-1$
054: //private final static String ELCL= "elcl16/"; //enabled - size 16x16 //$NON-NLS-1$
055: private final static String OBJECT = "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
056: //private final static String WIZBAN= "wizban/"; //basic colors - size 16x16 //$NON-NLS-1$
057: //private final static String OVR= "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$
058: //private final static String VIEW= "cview16/"; // views //$NON-NLS-1$
059:
060: public final static String IMG_OBJ_TOMCAT = "IMG_TOMCAT"; //$NON-NLS-1$
061: public final static String IMG_OBJ_JSP = "IMG_OBJ_JSP"; //$NON-NLS-1$
062:
063: /**
064: * Declare all images
065: */
066: private static void declareImages() {
067:
068: declareRegistryImage(IMG_OBJ_TOMCAT, OBJECT + "tomcat_obj.gif"); //$NON-NLS-1$
069: declareRegistryImage(IMG_OBJ_JSP, OBJECT + "jsp_obj.gif"); //$NON-NLS-1$
070: }
071:
072: /**
073: * Declare an Image in the registry table.
074: * @param key The key to use when registering the image
075: * @param path The path where the image can be found. This path is relative to where
076: * this plugin class is found (i.e. typically the packages directory)
077: */
078: private final static void declareRegistryImage(String key,
079: String path) {
080: ImageDescriptor desc = ImageDescriptor
081: .getMissingImageDescriptor();
082: try {
083: desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
084: } catch (MalformedURLException me) {
085: DebugPlugin.log(me);
086: }
087: imageRegistry.put(key, desc);
088: imageDescriptors.put(key, desc);
089: }
090:
091: /**
092: * Returns the ImageRegistry.
093: */
094: public static ImageRegistry getImageRegistry() {
095: if (imageRegistry == null) {
096: initializeImageRegistry();
097: }
098: return imageRegistry;
099: }
100:
101: /**
102: * Initialize the image registry by declaring all of the required
103: * graphics. This involves creating JFace image descriptors describing
104: * how to create/find the image should it be needed.
105: * The image is not actually allocated until requested.
106: *
107: * Prefix conventions
108: * Wizard Banners WIZBAN_
109: * Preference Banners PREF_BAN_
110: * Property Page Banners PROPBAN_
111: * Color toolbar CTOOL_
112: * Enable toolbar ETOOL_
113: * Disable toolbar DTOOL_
114: * Local enabled toolbar ELCL_
115: * Local Disable toolbar DLCL_
116: * Object large OBJL_
117: * Object small OBJS_
118: * View VIEW_
119: * Product images PROD_
120: * Misc images MISC_
121: *
122: * Where are the images?
123: * The images (typically gifs) are found in the same location as this plugin class.
124: * This may mean the same package directory as the package holding this class.
125: * The images are declared using this.getClass() to ensure they are looked up via
126: * this plugin class.
127: * @see JFace's ImageRegistry
128: */
129: public static ImageRegistry initializeImageRegistry() {
130: imageRegistry = new ImageRegistry(JspUIPlugin
131: .getStandardDisplay());
132: imageDescriptors = new HashMap(30);
133: declareImages();
134: return imageRegistry;
135: }
136:
137: /**
138: * Returns the <code>Image<code> identified by the given key,
139: * or <code>null</code> if it does not exist.
140: */
141: public static Image getImage(String key) {
142: return getImageRegistry().get(key);
143: }
144:
145: /**
146: * Returns the <code>ImageDescriptor<code> identified by the given key,
147: * or <code>null</code> if it does not exist.
148: */
149: public static ImageDescriptor getImageDescriptor(String key) {
150: if (imageDescriptors == null) {
151: initializeImageRegistry();
152: }
153: return (ImageDescriptor) imageDescriptors.get(key);
154: }
155:
156: private static URL makeIconFileURL(String iconPath)
157: throws MalformedURLException {
158: if (ICON_BASE_URL == null) {
159: throw new MalformedURLException();
160: }
161:
162: return new URL(ICON_BASE_URL, iconPath);
163: }
164: }
|