KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ant > internal > ui > AntUIImages


1 /*******************************************************************************
2  * Copyright (c) 2000, 2006 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  * John-Mason P. Shackelford (john-mason.shackelford@pearson.com) - bug 49380, 49445, 53547
11  *******************************************************************************/

12 package org.eclipse.ant.internal.ui;
13
14
15 import java.net.URL JavaDoc;
16
17 import org.eclipse.core.runtime.FileLocator;
18 import org.eclipse.core.runtime.Path;
19 import org.eclipse.core.runtime.Platform;
20 import org.eclipse.jface.resource.CompositeImageDescriptor;
21 import org.eclipse.jface.resource.ImageDescriptor;
22 import org.eclipse.jface.resource.ImageRegistry;
23 import org.eclipse.swt.graphics.Image;
24 import org.osgi.framework.Bundle;
25
26 /**
27  * The images provided by the external tools plugin.
28  */

29 public class AntUIImages {
30
31     /**
32      * The image registry containing <code>Image</code>s.
33      */

34     private static ImageRegistry imageRegistry;
35     
36     /**
37      * The registry for composite images
38      */

39     private static ImageDescriptorRegistry imageDescriptorRegistry;
40
41     private static String JavaDoc ICONS_PATH = "$nl$/icons/full/"; //$NON-NLS-1$
42

43     // Use IPath and toOSString to build the names to ensure they have the slashes correct
44
private final static String JavaDoc LOCALTOOL= ICONS_PATH + "elcl16/"; //basic colors - size 16x16 //$NON-NLS-1$
45
private final static String JavaDoc OBJECT= ICONS_PATH + "obj16/"; //basic colors - size 16x16 //$NON-NLS-1$
46
private final static String JavaDoc OVR= ICONS_PATH + "ovr16/"; //basic colors - size 7x8 //$NON-NLS-1$
47
private final static String JavaDoc WIZ= ICONS_PATH + "wizban/"; //$NON-NLS-1$
48
private static final String JavaDoc T_ETOOL= ICONS_PATH + "etool16"; //$NON-NLS-1$
49

50     /**
51      * Declare all images
52      */

53     private static void declareImages() {
54         // Ant Editor images
55
declareRegistryImage(IAntUIConstants.IMG_PROPERTY, OBJECT + "property_obj.gif"); //$NON-NLS-1$
56
declareRegistryImage(IAntUIConstants.IMG_TASK_PROPOSAL, OBJECT + "task_obj.gif"); //$NON-NLS-1$
57
declareRegistryImage(IAntUIConstants.IMG_TEMPLATE_PROPOSAL, OBJECT + "template_obj.gif"); //$NON-NLS-1$
58

59         declareRegistryImage(IAntUIConstants.IMG_SEGMENT_EDIT, T_ETOOL + "segment_edit.gif"); //$NON-NLS-1$
60
declareRegistryImage(IAntUIConstants.IMG_MARK_OCCURRENCES, T_ETOOL + "mark_occurrences.gif"); //$NON-NLS-1$
61

62         // Ant View Actions
63
declareRegistryImage(IAntUIConstants.IMG_ANT, OBJECT + "ant.gif"); //$NON-NLS-1$
64
declareRegistryImage(IAntUIConstants.IMG_REMOVE, LOCALTOOL + "remove_co.gif"); //$NON-NLS-1$
65
declareRegistryImage(IAntUIConstants.IMG_REMOVE_ALL, LOCALTOOL + "removeall_co.gif"); //$NON-NLS-1$
66
declareRegistryImage(IAntUIConstants.IMG_ADD, LOCALTOOL + "add_co.gif"); //$NON-NLS-1$
67
declareRegistryImage(IAntUIConstants.IMG_RUN, LOCALTOOL + "run_tool.gif"); //$NON-NLS-1$
68
declareRegistryImage(IAntUIConstants.IMG_SEARCH, LOCALTOOL + "search.gif"); //$NON-NLS-1$
69

70         declareRegistryImage(IAntUIConstants.IMG_FILTER_INTERNAL_TARGETS, LOCALTOOL + "filter_internal_targets.gif"); //$NON-NLS-1$
71
declareRegistryImage(IAntUIConstants.IMG_FILTER_IMPORTED_ELEMENTS, LOCALTOOL + "filter_imported_elements.gif"); //$NON-NLS-1$
72
declareRegistryImage(IAntUIConstants.IMG_FILTER_PROPERTIES, LOCALTOOL + "filter_properties.gif"); //$NON-NLS-1$
73
declareRegistryImage(IAntUIConstants.IMG_FILTER_TOP_LEVEL, LOCALTOOL + "filter_top_level.gif"); //$NON-NLS-1$
74
declareRegistryImage(IAntUIConstants.IMG_LINK_WITH_EDITOR, LOCALTOOL + "synced.gif"); //$NON-NLS-1$
75
declareRegistryImage(IAntUIConstants.IMG_SORT_OUTLINE, LOCALTOOL + "alpha_mode.gif"); //$NON-NLS-1$
76
declareRegistryImage(IAntUIConstants.IMG_REFRESH, LOCALTOOL + "refresh.gif"); //$NON-NLS-1$
77

78         // Ant View Labels
79
declareRegistryImage(IAntUIConstants.IMG_ANT_PROJECT, OBJECT + "ant_buildfile.gif"); //$NON-NLS-1$
80
declareRegistryImage(IAntUIConstants.IMG_ANT_TARGET, OBJECT + "targetpublic_obj.gif"); //$NON-NLS-1$
81
declareRegistryImage(IAntUIConstants.IMG_ANT_TARGET_INTERNAL, OBJECT + "targetinternal_obj.gif"); //$NON-NLS-1$
82
declareRegistryImage(IAntUIConstants.IMG_ANT_DEFAULT_TARGET, OBJECT + "defaulttarget_obj.gif"); //$NON-NLS-1$
83
declareRegistryImage(IAntUIConstants.IMG_ANT_TARGET_ERROR, OBJECT + "ant_target_err.gif"); //$NON-NLS-1$
84

85         //ANT objects
86
declareRegistryImage(IAntUIConstants.IMG_TAB_CLASSPATH, OBJECT + "classpath.gif"); //$NON-NLS-1$
87
declareRegistryImage(IAntUIConstants.IMG_ANT_TYPE, OBJECT + "type.gif"); //$NON-NLS-1$
88
declareRegistryImage(IAntUIConstants.IMG_ANT_TASKDEF, OBJECT + "taskdef_obj.gif"); //$NON-NLS-1$
89
declareRegistryImage(IAntUIConstants.IMG_ANT_MACRODEF, OBJECT + "macrodef_obj.gif"); //$NON-NLS-1$
90
declareRegistryImage(IAntUIConstants.IMG_ANT_IMPORT, OBJECT + "import_obj.gif"); //$NON-NLS-1$
91
declareRegistryImage(IAntUIConstants.IMG_ANT_ECLIPSE_RUNTIME_OBJECT, OBJECT + "eclipse_obj.gif"); //$NON-NLS-1$
92

93         declareRegistryImage(IAntUIConstants.IMG_WIZARD_BANNER, WIZ + "ant_wiz.png"); //$NON-NLS-1$
94
declareRegistryImage(IAntUIConstants.IMG_EXPORT_WIZARD_BANNER, WIZ + "export_ant_wiz.png"); //$NON-NLS-1$
95
declareRegistryImage(IAntUIConstants.IMG_TAB_ANT_TARGETS, LOCALTOOL + "ant_targets.gif"); //$NON-NLS-1$
96
declareRegistryImage(IAntUIConstants.IMG_ANT_BUILD_TAB, OBJECT + "build_tab.gif"); //$NON-NLS-1$
97

98         // Overlays
99
declareRegistryImage(IAntUIConstants.IMG_OVR_ERROR, OVR + "error_co.gif"); //$NON-NLS-1$
100
declareRegistryImage(IAntUIConstants.IMG_OVR_WARNING, OVR + "warning_co.gif"); //$NON-NLS-1$
101
declareRegistryImage(IAntUIConstants.IMG_OVR_IMPORT, OVR + "import_co.gif"); //$NON-NLS-1$
102
}
103
104     /**
105      * Declare an Image in the registry table.
106      * @param key The key to use when registering the image
107      * @param path The path where the image can be found. This path is relative to where
108      * this plugin class is found (i.e. typically the packages directory)
109      */

110     private final static void declareRegistryImage(String JavaDoc key, String JavaDoc path) {
111         ImageDescriptor desc = ImageDescriptor.getMissingImageDescriptor();
112         Bundle bundle = Platform.getBundle(AntUIPlugin.getUniqueIdentifier());
113         URL JavaDoc url = null;
114         if (bundle != null) {
115             url = FileLocator.find(bundle, new Path(path), null);
116             desc = ImageDescriptor.createFromURL(url);
117         }
118         imageRegistry.put(key, desc);
119     }
120     
121     /**
122      * Returns the ImageRegistry.
123      */

124     public static ImageRegistry getImageRegistry() {
125         if (imageRegistry == null) {
126             initializeImageRegistry();
127         }
128         return imageRegistry;
129     }
130
131     /**
132      * Initialize the image registry by declaring all of the required
133      * graphics. This involves creating JFace image descriptors describing
134      * how to create/find the image should it be needed.
135      * The image is not actually allocated until requested.
136      *
137      * Prefix conventions
138      * Wizard Banners WIZBAN_
139      * Preference Banners PREF_BAN_
140      * Property Page Banners PROPBAN_
141      * Color toolbar CTOOL_
142      * Enable toolbar ETOOL_
143      * Disable toolbar DTOOL_
144      * Local enabled toolbar ELCL_
145      * Local Disable toolbar DLCL_
146      * Object large OBJL_
147      * Object small OBJS_
148      * View VIEW_
149      * Product images PROD_
150      * Misc images MISC_
151      *
152      * Where are the images?
153      * The images (typically gifs) are found in the same location as this plugin class.
154      * This may mean the same package directory as the package holding this class.
155      * The images are declared using this.getClass() to ensure they are looked up via
156      * this plugin class.
157      * @see org.eclipse.jface.resource.ImageRegistry
158      */

159     public static ImageRegistry initializeImageRegistry() {
160         imageRegistry= new ImageRegistry(AntUIPlugin.getStandardDisplay());
161         declareImages();
162         return imageRegistry;
163     }
164
165     /**
166      * Returns the <code>Image<code> identified by the given key,
167      * or <code>null</code> if it does not exist.
168      */

169     public static Image getImage(String JavaDoc key) {
170         return getImageRegistry().get(key);
171     }
172     
173     /**
174      * Returns the <code>ImageDescriptor<code> identified by the given key,
175      * or <code>null</code> if it does not exist.
176      */

177     public static ImageDescriptor getImageDescriptor(String JavaDoc key) {
178         return getImageRegistry().getDescriptor(key);
179     }
180     
181     /**
182      * Returns the image for the given composite descriptor.
183      */

184     public static Image getImage(CompositeImageDescriptor imageDescriptor) {
185         if (imageDescriptorRegistry == null) {
186             imageDescriptorRegistry = new ImageDescriptorRegistry();
187         }
188         return imageDescriptorRegistry.get(imageDescriptor);
189     }
190     
191     public static void disposeImageDescriptorRegistry() {
192         if (imageDescriptorRegistry != null) {
193             imageDescriptorRegistry.dispose();
194         }
195     }
196 }
197
Popular Tags