001: /*******************************************************************************
002: * Copyright (c) 2000, 2005 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.ui.internal.console;
011:
012: import java.net.MalformedURLException;
013: import java.net.URL;
014:
015: import org.eclipse.jface.resource.ImageDescriptor;
016: import org.eclipse.jface.resource.ImageRegistry;
017: import org.eclipse.swt.graphics.Image;
018: import org.eclipse.ui.console.ConsolePlugin;
019: import org.eclipse.ui.console.IConsoleConstants;
020:
021: /**
022: * The images provided by the debug plugin.
023: */
024: public class ConsolePluginImages {
025:
026: /**
027: * The image registry containing <code>Image</code>s and the <code>ImageDescriptor</code>s.
028: */
029: private static ImageRegistry imageRegistry;
030:
031: /* Declare Common paths */
032: private static URL ICON_BASE_URL = null;
033:
034: static {
035: String pathSuffix = "icons/full/"; //$NON-NLS-1$
036: ICON_BASE_URL = ConsolePlugin.getDefault().getBundle()
037: .getEntry(pathSuffix);
038: }
039:
040: // Use IPath and toOSString to build the names to ensure they have the slashes correct
041: private final static String LOCALTOOL = "clcl16/"; //basic colors - size 16x16 //$NON-NLS-1$
042: private final static String DLCL = "dlcl16/"; //disabled - size 16x16 //$NON-NLS-1$
043: private final static String ELCL = "elcl16/"; //enabled - size 16x16 //$NON-NLS-1$
044: private final static String VIEW = "cview16/"; // views //$NON-NLS-1$
045:
046: /**
047: * Declare all images
048: */
049: private static void declareImages() {
050: // Actions
051:
052: //local toolbars
053: declareRegistryImage(IConsoleConstants.IMG_LCL_CLEAR, LOCALTOOL
054: + "clear_co.gif"); //$NON-NLS-1$
055: declareRegistryImage(IInternalConsoleConstants.IMG_LCL_PIN,
056: LOCALTOOL + "pin.gif"); //$NON-NLS-1$
057: declareRegistryImage(IInternalConsoleConstants.IMG_LCL_LOCK,
058: LOCALTOOL + "lock_co.gif"); //$NON-NLS-1$
059:
060: // disabled local toolbars
061: declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_CLEAR,
062: DLCL + "clear_co.gif"); //$NON-NLS-1$
063: declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_PIN,
064: DLCL + "pin.gif"); //$NON-NLS-1$
065: declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_LOCK,
066: DLCL + "lock_co.gif"); //$NON-NLS-1$
067: declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_CLOSE,
068: DLCL + "rem_co.gif"); //$NON-NLS-1$
069:
070: // enabled local toolbars
071: declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_CLEAR,
072: ELCL + "clear_co.gif"); //$NON-NLS-1$
073: declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_PIN,
074: ELCL + "pin.gif"); //$NON-NLS-1$
075: declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_LOCK,
076: ELCL + "lock_co.gif"); //$NON-NLS-1$
077: declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_CLOSE,
078: ELCL + "rem_co.gif"); //$NON-NLS-1$
079: declareRegistryImage(
080: IInternalConsoleConstants.IMG_ELCL_NEW_CON, ELCL
081: + "new_con.gif"); //$NON-NLS-1$
082:
083: // Views
084: declareRegistryImage(IConsoleConstants.IMG_VIEW_CONSOLE, VIEW
085: + "console_view.gif"); //$NON-NLS-1$
086: }
087:
088: /**
089: * Declare an Image in the registry table.
090: * @param key The key to use when registering the image
091: * @param path The path where the image can be found. This path is relative to where
092: * this plugin class is found (i.e. typically the packages directory)
093: */
094: private final static void declareRegistryImage(String key,
095: String path) {
096: ImageDescriptor desc = ImageDescriptor
097: .getMissingImageDescriptor();
098: try {
099: desc = ImageDescriptor.createFromURL(makeIconFileURL(path));
100: } catch (MalformedURLException me) {
101: ConsolePlugin.log(me);
102: }
103: imageRegistry.put(key, desc);
104: }
105:
106: /**
107: * Returns the ImageRegistry.
108: */
109: public static ImageRegistry getImageRegistry() {
110: if (imageRegistry == null) {
111: initializeImageRegistry();
112: }
113: return imageRegistry;
114: }
115:
116: /**
117: * Initialize the image registry by declaring all of the required
118: * graphics. This involves creating JFace image descriptors describing
119: * how to create/find the image should it be needed.
120: * The image is not actually allocated until requested.
121: *
122: * Prefix conventions
123: * Wizard Banners WIZBAN_
124: * Preference Banners PREF_BAN_
125: * Property Page Banners PROPBAN_
126: * Color toolbar CTOOL_
127: * Enable toolbar ETOOL_
128: * Disable toolbar DTOOL_
129: * Local enabled toolbar ELCL_
130: * Local Disable toolbar DLCL_
131: * Object large OBJL_
132: * Object small OBJS_
133: * View VIEW_
134: * Product images PROD_
135: * Misc images MISC_
136: *
137: * Where are the images?
138: * The images (typically gifs) are found in the same location as this plugin class.
139: * This may mean the same package directory as the package holding this class.
140: * The images are declared using this.getClass() to ensure they are looked up via
141: * this plugin class.
142: * @see org.eclipse.jface.resource.ImageRegistry
143: */
144: public static ImageRegistry initializeImageRegistry() {
145: imageRegistry = new ImageRegistry(ConsolePlugin
146: .getStandardDisplay());
147: declareImages();
148: return imageRegistry;
149: }
150:
151: /**
152: * Returns the <code>Image<code> identified by the given key,
153: * or <code>null</code> if it does not exist.
154: */
155: public static Image getImage(String key) {
156: return getImageRegistry().get(key);
157: }
158:
159: /**
160: * Returns the <code>ImageDescriptor<code> identified by the given key,
161: * or <code>null</code> if it does not exist.
162: */
163: public static ImageDescriptor getImageDescriptor(String key) {
164: return getImageRegistry().getDescriptor(key);
165: }
166:
167: private static URL makeIconFileURL(String iconPath)
168: throws MalformedURLException {
169: if (ICON_BASE_URL == null) {
170: throw new MalformedURLException();
171: }
172:
173: return new URL(ICON_BASE_URL, iconPath);
174: }
175: }
|