KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > console > ConsolePluginImages


1 /*******************************************************************************
2  * Copyright (c) 2000, 2005 IBM Corporation and others.
3  * All rights reserved. This program and the accompanying materials
4  * are made available under the terms of the Eclipse Public License v1.0
5  * which accompanies this distribution, and is available at
6  * http://www.eclipse.org/legal/epl-v10.html
7  *
8  * Contributors:
9  * IBM Corporation - initial API and implementation
10  *******************************************************************************/

11 package org.eclipse.ui.internal.console;
12
13
14 import java.net.MalformedURLException JavaDoc;
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.jface.resource.ImageDescriptor;
18 import org.eclipse.jface.resource.ImageRegistry;
19 import org.eclipse.swt.graphics.Image;
20 import org.eclipse.ui.console.ConsolePlugin;
21 import org.eclipse.ui.console.IConsoleConstants;
22
23 /**
24  * The images provided by the debug plugin.
25  */

26 public class ConsolePluginImages {
27
28     /**
29      * The image registry containing <code>Image</code>s and the <code>ImageDescriptor</code>s.
30      */

31     private static ImageRegistry imageRegistry;
32         
33     /* Declare Common paths */
34     private static URL JavaDoc ICON_BASE_URL= null;
35
36     static {
37         String JavaDoc pathSuffix = "icons/full/"; //$NON-NLS-1$
38
ICON_BASE_URL= ConsolePlugin.getDefault().getBundle().getEntry(pathSuffix);
39     }
40
41     // Use IPath and toOSString to build the names to ensure they have the slashes correct
42
private final static String JavaDoc LOCALTOOL= "clcl16/"; //basic colors - size 16x16 //$NON-NLS-1$
43
private final static String JavaDoc DLCL= "dlcl16/"; //disabled - size 16x16 //$NON-NLS-1$
44
private final static String JavaDoc ELCL= "elcl16/"; //enabled - size 16x16 //$NON-NLS-1$
45
private final static String JavaDoc VIEW= "cview16/"; // views //$NON-NLS-1$
46

47     /**
48      * Declare all images
49      */

50     private static void declareImages() {
51         // Actions
52

53         //local toolbars
54
declareRegistryImage(IConsoleConstants.IMG_LCL_CLEAR, LOCALTOOL + "clear_co.gif"); //$NON-NLS-1$
55
declareRegistryImage(IInternalConsoleConstants.IMG_LCL_PIN, LOCALTOOL + "pin.gif"); //$NON-NLS-1$
56
declareRegistryImage(IInternalConsoleConstants.IMG_LCL_LOCK, LOCALTOOL + "lock_co.gif"); //$NON-NLS-1$
57

58         // disabled local toolbars
59
declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_CLEAR, DLCL + "clear_co.gif"); //$NON-NLS-1$
60
declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_PIN, DLCL + "pin.gif"); //$NON-NLS-1$
61
declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_LOCK, DLCL + "lock_co.gif"); //$NON-NLS-1$
62
declareRegistryImage(IInternalConsoleConstants.IMG_DLCL_CLOSE, DLCL + "rem_co.gif"); //$NON-NLS-1$
63

64         // enabled local toolbars
65
declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_CLEAR, ELCL + "clear_co.gif"); //$NON-NLS-1$
66
declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_PIN, ELCL + "pin.gif"); //$NON-NLS-1$
67
declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_LOCK, ELCL + "lock_co.gif"); //$NON-NLS-1$
68
declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_CLOSE, ELCL + "rem_co.gif"); //$NON-NLS-1$
69
declareRegistryImage(IInternalConsoleConstants.IMG_ELCL_NEW_CON, ELCL + "new_con.gif"); //$NON-NLS-1$
70

71         // Views
72
declareRegistryImage(IConsoleConstants.IMG_VIEW_CONSOLE, VIEW + "console_view.gif"); //$NON-NLS-1$
73
}
74
75     /**
76      * Declare an Image in the registry table.
77      * @param key The key to use when registering the image
78      * @param path The path where the image can be found. This path is relative to where
79      * this plugin class is found (i.e. typically the packages directory)
80      */

81     private final static void declareRegistryImage(String JavaDoc key, String JavaDoc path) {
82         ImageDescriptor desc= ImageDescriptor.getMissingImageDescriptor();
83         try {
84             desc= ImageDescriptor.createFromURL(makeIconFileURL(path));
85         } catch (MalformedURLException JavaDoc me) {
86             ConsolePlugin.log(me);
87         }
88         imageRegistry.put(key, desc);
89     }
90     
91     /**
92      * Returns the ImageRegistry.
93      */

94     public static ImageRegistry getImageRegistry() {
95         if (imageRegistry == null) {
96             initializeImageRegistry();
97         }
98         return imageRegistry;
99     }
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 org.eclipse.jface.resource.ImageRegistry
128      */

129     public static ImageRegistry initializeImageRegistry() {
130         imageRegistry= new ImageRegistry(ConsolePlugin.getStandardDisplay());
131         declareImages();
132         return imageRegistry;
133     }
134
135     /**
136      * Returns the <code>Image<code> identified by the given key,
137      * or <code>null</code> if it does not exist.
138      */

139     public static Image getImage(String JavaDoc key) {
140         return getImageRegistry().get(key);
141     }
142     
143     /**
144      * Returns the <code>ImageDescriptor<code> identified by the given key,
145      * or <code>null</code> if it does not exist.
146      */

147     public static ImageDescriptor getImageDescriptor(String JavaDoc key) {
148         return getImageRegistry().getDescriptor(key);
149     }
150     
151     private static URL JavaDoc makeIconFileURL(String JavaDoc iconPath) throws MalformedURLException JavaDoc {
152         if (ICON_BASE_URL == null) {
153             throw new MalformedURLException JavaDoc();
154         }
155             
156         return new URL JavaDoc(ICON_BASE_URL, iconPath);
157     }
158 }
159
Popular Tags