KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > eclipse > ui > internal > WorkbenchImages


1 /*******************************************************************************
2  * Copyright (c) 2000, 2007 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;
12
13 import java.net.URL JavaDoc;
14 import java.util.HashMap JavaDoc;
15 import java.util.Map JavaDoc;
16
17 import org.eclipse.core.runtime.Assert;
18 import org.eclipse.jface.resource.ImageDescriptor;
19 import org.eclipse.jface.resource.ImageRegistry;
20 import org.eclipse.swt.SWT;
21 import org.eclipse.swt.graphics.Color;
22 import org.eclipse.swt.graphics.GC;
23 import org.eclipse.swt.graphics.Image;
24 import org.eclipse.swt.graphics.ImageData;
25 import org.eclipse.swt.widgets.Display;
26 import org.eclipse.ui.ISharedImages;
27 import org.eclipse.ui.PlatformUI;
28 import org.eclipse.ui.internal.misc.Policy;
29 import org.eclipse.ui.internal.misc.ProgramImageDescriptor;
30 import org.eclipse.ui.internal.util.BundleUtility;
31
32 /**
33  * This class provides convenience access to many of the resources required
34  * by the workbench. The class stores some images as descriptors, and
35  * some are stored as real Images in the registry. This is a pure
36  * speed-space tradeoff. The trick for users of this class is that
37  * images obtained from the registry (using getImage()), don't require
38  * disposal since they are shared, while images obtained using
39  * getImageDescriptor() will require disposal. Consult the declareImages
40  * method to see if a given image is declared as a registry image or
41  * just as a descriptor. If you change an image from being stored
42  * as a descriptor to a registry image, or vice-versa, make sure to
43  * check all users of the image to ensure they are calling
44  * the correct getImage... method and handling disposal correctly.
45  *
46  * Images:
47  * - use getImage(key) to access cached images from the registry.
48  * - Less common images are found by calling getImageDescriptor(key)
49  * where key can be found in IWorkbenchGraphicConstants
50  *
51  * This class initializes the image registry by declaring all of the required
52  * graphics. This involves creating image descriptors describing
53  * how to create/find the image should it be needed.
54  * The image is not actually allocated until requested.
55  *
56  * Some Images are also made available to other plugins by being
57  * placed in the descriptor table of the SharedImages class.
58  *
59  * Where are the images?
60  * The images (typically gifs) are found the plugins install directory
61  *
62  * How to add a new image
63  * Place the gif file into the appropriate directories.
64  * Add a constant to IWorkbenchGraphicConstants following the conventions
65  * Add the declaration to this file
66  */

67 public/*final*/class WorkbenchImages {
68
69     private static Map JavaDoc descriptors;
70
71     private static ImageRegistry imageRegistry;
72
73     /* Declare Common paths */
74
75     public final static String JavaDoc ICONS_PATH = "$nl$/icons/full/";//$NON-NLS-1$
76

77     private final static String JavaDoc PATH_ETOOL = ICONS_PATH + "etool16/"; //Enabled toolbar icons.//$NON-NLS-1$
78

79     private final static String JavaDoc PATH_DTOOL = ICONS_PATH + "dtool16/"; //Disabled toolbar icons.//$NON-NLS-1$
80

81     private final static String JavaDoc PATH_ELOCALTOOL = ICONS_PATH + "elcl16/"; //Enabled local toolbar icons.//$NON-NLS-1$
82

83     private final static String JavaDoc PATH_DLOCALTOOL = ICONS_PATH + "dlcl16/"; //Disabled local toolbar icons.//$NON-NLS-1$
84

85     private final static String JavaDoc PATH_EVIEW = ICONS_PATH + "eview16/"; //View icons//$NON-NLS-1$
86

87     //private final static String PATH_PROD = ICONS_PATH+"prod/"; //Product images
88
private final static String JavaDoc PATH_OBJECT = ICONS_PATH + "obj16/"; //Model object icons//$NON-NLS-1$
89

90     private final static String JavaDoc PATH_POINTER = ICONS_PATH + "pointer/"; //Pointer icons//$NON-NLS-1$
91

92     private final static String JavaDoc PATH_WIZBAN = ICONS_PATH + "wizban/"; //Wizard icons//$NON-NLS-1$
93

94
95     //private final static String PATH_STAT = ICONS_PATH+"stat/";
96
//private final static String PATH_MISC = ICONS_PATH+"misc/";
97
//private final static String PATH_OVERLAY = ICONS_PATH+"ovr16/";
98

99     /**
100      * Declares a workbench image given the path of the image file (relative to
101      * the workbench plug-in). This is a helper method that creates the image
102      * descriptor and passes it to the main <code>declareImage</code> method.
103      *
104      * @param key the symbolic name of the image
105      * @param path the path of the image file relative to the base of the workbench
106      * plug-ins install directory
107      * @param shared <code>true</code> if this is a shared image, and
108      * <code>false</code> if this is not a shared image
109      */

110     private final static void declareImage(String JavaDoc key, String JavaDoc path,
111             boolean shared) {
112         URL JavaDoc url = BundleUtility.find(PlatformUI.PLUGIN_ID, path);
113         ImageDescriptor desc = ImageDescriptor.createFromURL(url);
114         declareImage(key, desc, shared);
115     }
116
117     private static void drawViewMenu(GC gc, GC maskgc) {
118         Display display = Display.getCurrent();
119         
120         gc.setForeground(display.getSystemColor(SWT.COLOR_WIDGET_DARK_SHADOW));
121         gc.setBackground(display.getSystemColor(SWT.COLOR_LIST_BACKGROUND));
122         
123         int[] shapeArray = new int[] {1, 1, 10, 1, 6, 5, 5, 5};
124         gc.fillPolygon(shapeArray);
125         gc.drawPolygon(shapeArray);
126         
127         Color black = display.getSystemColor(SWT.COLOR_BLACK);
128         Color white = display.getSystemColor(SWT.COLOR_WHITE);
129         
130         maskgc.setBackground(black);
131         maskgc.fillRectangle(0,0,12,16);
132         
133         maskgc.setBackground(white);
134         maskgc.setForeground(white);
135         maskgc.fillPolygon(shapeArray);
136         maskgc.drawPolygon(shapeArray);
137     }
138     
139     /**
140      * Declares all the workbench's images, including both "shared" ones and
141      * internal ones.
142      */

143     private final static void declareImages() {
144         
145         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR,
146                 PATH_ETOOL + "pin_editor.gif", false); //$NON-NLS-1$
147
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR_DISABLED,
148                 PATH_DTOOL + "pin_editor.gif", false); //$NON-NLS-1$
149

150         // other toolbar buttons
151

152         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVE_EDIT, PATH_ETOOL
153                 + "save_edit.gif", false); //$NON-NLS-1$
154
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVE_EDIT_DISABLED,
155                 PATH_DTOOL + "save_edit.gif", false); //$NON-NLS-1$
156

157         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT,
158                 PATH_ETOOL + "saveas_edit.gif", false); //$NON-NLS-1$
159
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT_DISABLED,
160                 PATH_DTOOL + "saveas_edit.gif", false); //$NON-NLS-1$
161

162         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEALL_EDIT,
163                 PATH_ETOOL + "saveall_edit.gif", false); //$NON-NLS-1$
164
declareImage(
165                 IWorkbenchGraphicConstants.IMG_ETOOL_SAVEALL_EDIT_DISABLED,
166                 PATH_DTOOL + "saveall_edit.gif", false); //$NON-NLS-1$
167

168         declareImage(ISharedImages.IMG_TOOL_UNDO,
169                 PATH_ETOOL + "undo_edit.gif", true); //$NON-NLS-1$
170
declareImage(ISharedImages.IMG_TOOL_UNDO_HOVER, PATH_ETOOL
171                 + "undo_edit.gif", true); //$NON-NLS-1$
172
declareImage(ISharedImages.IMG_TOOL_UNDO_DISABLED, PATH_DTOOL
173                 + "undo_edit.gif", true); //$NON-NLS-1$
174

175         declareImage(ISharedImages.IMG_TOOL_REDO,
176                 PATH_ETOOL + "redo_edit.gif", true); //$NON-NLS-1$
177
declareImage(ISharedImages.IMG_TOOL_REDO_HOVER, PATH_ETOOL
178                 + "redo_edit.gif", true); //$NON-NLS-1$
179
declareImage(ISharedImages.IMG_TOOL_REDO_DISABLED, PATH_DTOOL
180                 + "redo_edit.gif", true); //$NON-NLS-1$
181

182         declareImage(ISharedImages.IMG_TOOL_CUT,
183                 PATH_ETOOL + "cut_edit.gif", true); //$NON-NLS-1$
184
declareImage(ISharedImages.IMG_TOOL_CUT_HOVER, PATH_ETOOL
185                 + "cut_edit.gif", true); //$NON-NLS-1$
186
declareImage(ISharedImages.IMG_TOOL_CUT_DISABLED, PATH_DTOOL
187                 + "cut_edit.gif", true); //$NON-NLS-1$
188

189         declareImage(ISharedImages.IMG_TOOL_COPY,
190                 PATH_ETOOL + "copy_edit.gif", true); //$NON-NLS-1$
191
declareImage(ISharedImages.IMG_TOOL_COPY_HOVER, PATH_ETOOL
192                 + "copy_edit.gif", true); //$NON-NLS-1$
193
declareImage(ISharedImages.IMG_TOOL_COPY_DISABLED, PATH_DTOOL
194                 + "copy_edit.gif", true); //$NON-NLS-1$
195

196         declareImage(ISharedImages.IMG_TOOL_PASTE, PATH_ETOOL
197                 + "paste_edit.gif", true); //$NON-NLS-1$
198
declareImage(ISharedImages.IMG_TOOL_PASTE_HOVER, PATH_ETOOL
199                 + "paste_edit.gif", true); //$NON-NLS-1$
200
declareImage(ISharedImages.IMG_TOOL_PASTE_DISABLED, PATH_DTOOL
201                 + "paste_edit.gif", true); //$NON-NLS-1$
202

203         declareImage(ISharedImages.IMG_TOOL_DELETE, PATH_ETOOL
204                 + "delete_edit.gif", true); //$NON-NLS-1$
205
declareImage(ISharedImages.IMG_TOOL_DELETE_HOVER, PATH_ETOOL
206                 + "delete_edit.gif", true); //$NON-NLS-1$
207
declareImage(ISharedImages.IMG_TOOL_DELETE_DISABLED, PATH_DTOOL
208                 + "delete_edit.gif", true); //$NON-NLS-1$
209
declareImage(ISharedImages.IMG_TOOL_NEW_WIZARD,
210                 PATH_ETOOL + "new_wiz.gif", true); //$NON-NLS-1$
211
declareImage(ISharedImages.IMG_TOOL_NEW_WIZARD_HOVER, PATH_ETOOL
212                         + "new_wiz.gif", true); //$NON-NLS-1$
213
declareImage(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED, PATH_DTOOL
214                         + "new_wiz.gif", true); //$NON-NLS-1$
215

216         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PRINT_EDIT,
217                 PATH_ETOOL + "print_edit.gif", false); //$NON-NLS-1$
218
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PRINT_EDIT_DISABLED,
219                 PATH_DTOOL + "print_edit.gif", false); //$NON-NLS-1$
220

221         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_HELP_CONTENTS,
222                 PATH_ETOOL + "help_contents.gif", true); //$NON-NLS-1$
223
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_HELP_SEARCH,
224                 PATH_ETOOL + "help_search.gif", true); //$NON-NLS-1$
225

226         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_NEW_FASTVIEW,
227                 PATH_ETOOL + "new_fastview.gif", true); //$NON-NLS-1$
228
declareImage(IWorkbenchGraphicConstants.IMG_DTOOL_NEW_FASTVIEW,
229                 PATH_DTOOL + "new_fastview.gif", true); //$NON-NLS-1$
230

231         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_RESTORE_TRIMPART,
232                 PATH_ETOOL + "fastview_restore.gif", true); //$NON-NLS-1$
233
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_EDITOR_TRIMPART,
234                 PATH_ETOOL + "editor_area.gif", true); //$NON-NLS-1$
235

236         declareImage(ISharedImages.IMG_TOOL_FORWARD, PATH_ELOCALTOOL
237                 + "forward_nav.gif", true); //$NON-NLS-1$
238
declareImage(ISharedImages.IMG_TOOL_FORWARD_HOVER, PATH_ELOCALTOOL
239                 + "forward_nav.gif", true); //$NON-NLS-1$
240
declareImage(ISharedImages.IMG_TOOL_FORWARD_DISABLED, PATH_DLOCALTOOL
241                 + "forward_nav.gif", true); //$NON-NLS-1$
242

243         declareImage(ISharedImages.IMG_TOOL_BACK, PATH_ELOCALTOOL
244                 + "backward_nav.gif", true); //$NON-NLS-1$
245
declareImage(ISharedImages.IMG_TOOL_BACK_HOVER, PATH_ELOCALTOOL
246                 + "backward_nav.gif", true); //$NON-NLS-1$
247
declareImage(ISharedImages.IMG_TOOL_BACK_DISABLED, PATH_DLOCALTOOL
248                 + "backward_nav.gif", true); //$NON-NLS-1$
249

250         declareImage(ISharedImages.IMG_TOOL_UP,
251                 PATH_ELOCALTOOL + "up_nav.gif", true); //$NON-NLS-1$
252
declareImage(ISharedImages.IMG_TOOL_UP_HOVER, PATH_ELOCALTOOL
253                 + "up_nav.gif", true); //$NON-NLS-1$
254
declareImage(ISharedImages.IMG_TOOL_UP_DISABLED, PATH_DLOCALTOOL
255                 + "up_nav.gif", true); //$NON-NLS-1$
256

257         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_NEW_PAGE, PATH_EVIEW
258                 + "new_persp.gif", false); //$NON-NLS-1$
259

260         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_HOME_NAV,
261                 PATH_ELOCALTOOL + "home_nav.gif", false); //$NON-NLS-1$
262

263         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_DEF_PERSPECTIVE,
264                 PATH_EVIEW + "default_persp.gif", false); //$NON-NLS-1$
265

266         declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_NEW_WIZ, PATH_WIZBAN
267                         + "new_wiz.png", false); //$NON-NLS-1$
268

269     // testing PNG images cross platform, allows designers to pickup nightly builds
270
// declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_NEW_WIZ, PATH_WIZBAN
271
// + "new_wiz.png", false); //$NON-NLS-1$
272

273         declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_IMPORT_WIZ, PATH_ETOOL
274                         + "import_wiz.gif", false); //$NON-NLS-1$
275
declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_EXPORT_WIZ, PATH_ETOOL
276                         + "export_wiz.gif", false); //$NON-NLS-1$
277
declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_WIZ, PATH_WIZBAN
278                         + "import_wiz.png", false); //$NON-NLS-1$
279
declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_EXPORT_WIZ, PATH_WIZBAN
280                         + "export_wiz.png", false); //$NON-NLS-1$
281
declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_PREF_WIZ, PATH_WIZBAN
282                 + "importpref_wiz.png", false); //$NON-NLS-1$
283
declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_EXPORT_PREF_WIZ, PATH_WIZBAN
284                 + "exportpref_wiz.png", false); //$NON-NLS-1$
285

286         declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_WORKINGSET_WIZ,
287                 PATH_WIZBAN + "workset_wiz.png", false); //$NON-NLS-1$
288

289         declareImage(IWorkbenchGraphicConstants.IMG_VIEW_DEFAULTVIEW_MISC,
290                 PATH_EVIEW + "defaultview_misc.gif", false); //$NON-NLS-1$
291

292         declareImage(IWorkbenchGraphicConstants.IMG_OBJ_FONT, PATH_OBJECT
293                 + "font.gif", true); //$NON-NLS-1$
294
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_THEME_CATEGORY,
295                 PATH_OBJECT + "theme_category.gif", true); //$NON-NLS-1$
296
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_ACTIVITY, PATH_OBJECT
297                 + "activity.gif", true); //$NON-NLS-1$
298
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_ACTIVITY_CATEGORY,
299                 PATH_OBJECT + "activity_category.gif", true); //$NON-NLS-1$
300
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_WORKING_SETS,
301                PATH_OBJECT + "workingsets.gif", true); //$NON-NLS-1$
302

303         declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SEPARATOR,
304                PATH_OBJECT + "separator.gif", true); //$NON-NLS-1$
305

306         declareImage(IWorkbenchGraphicConstants.IMG_OBJ_NODE,
307                 PATH_OBJECT + "generic_elements.gif", true); //$NON-NLS-1$
308
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_ELEMENT,
309                 PATH_OBJECT + "generic_element.gif", true); //$NON-NLS-1$
310

311         declareImage(ISharedImages.IMG_OBJ_FILE,
312                 PATH_OBJECT + "file_obj.gif", true); //$NON-NLS-1$
313
declareImage(ISharedImages.IMG_OBJ_FOLDER,
314                 PATH_OBJECT + "fldr_obj.gif", true); //$NON-NLS-1$
315
declareImage(ISharedImages.IMG_OBJ_ELEMENT, PATH_OBJECT
316                 + "elements_obj.gif", true); //$NON-NLS-1$
317
declareImage(ISharedImages.IMG_DEF_VIEW, PATH_EVIEW
318                 + "defaultview_misc.gif", true); //$NON-NLS-1$
319

320         declareImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW,
321                 PATH_ELOCALTOOL + "close_view.gif", true); //$NON-NLS-1$
322
declareImage(IWorkbenchGraphicConstants.IMG_LCL_PIN_VIEW,
323                 PATH_ELOCALTOOL + "pin_view.gif", true); //$NON-NLS-1$
324
declareImage(IWorkbenchGraphicConstants.IMG_LCL_MIN_VIEW,
325                 PATH_ELOCALTOOL + "min_view.gif", true); //$NON-NLS-1$
326
declareImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU,
327                 PATH_ELOCALTOOL + "view_menu.gif", true); //$NON-NLS-1$
328
declareImage(IWorkbenchGraphicConstants.IMG_LCL_LINKTO_HELP,
329                 PATH_ELOCALTOOL + "linkto_help.gif", true); //$NON-NLS-1$
330

331         declareImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW_THIN,
332                 PATH_ELOCALTOOL + "thin_close_view.gif", true); //$NON-NLS-1$
333
declareImage(IWorkbenchGraphicConstants.IMG_LCL_HIDE_TOOLBAR_THIN,
334                 PATH_ELOCALTOOL + "thin_hide_toolbar.gif", true); //$NON-NLS-1$
335
declareImage(IWorkbenchGraphicConstants.IMG_LCL_MAX_VIEW_THIN,
336                 PATH_ELOCALTOOL + "thin_max_view.gif", true); //$NON-NLS-1$
337
declareImage(IWorkbenchGraphicConstants.IMG_LCL_MIN_VIEW_THIN,
338                 PATH_ELOCALTOOL + "thin_min_view.gif", true); //$NON-NLS-1$
339
declareImage(IWorkbenchGraphicConstants.IMG_LCL_RESTORE_VIEW_THIN,
340                 PATH_ELOCALTOOL + "thin_restore_view.gif", true); //$NON-NLS-1$
341
declareImage(IWorkbenchGraphicConstants.IMG_LCL_SHOW_TOOLBAR_THIN,
342                 PATH_ELOCALTOOL + "thin_show_toolbar.gif", true); //$NON-NLS-1$
343
declareImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU_THIN,
344                 PATH_ELOCALTOOL + "thin_view_menu.gif", true); //$NON-NLS-1$
345

346         
347         declareImage(ISharedImages.IMG_OBJS_ERROR_TSK, PATH_OBJECT
348                 + "error_tsk.gif", true); //$NON-NLS-1$
349
declareImage(ISharedImages.IMG_OBJS_WARN_TSK, PATH_OBJECT
350                 + "warn_tsk.gif", true); //$NON-NLS-1$
351
declareImage(ISharedImages.IMG_OBJS_INFO_TSK, PATH_OBJECT
352                 + "info_tsk.gif", true); //$NON-NLS-1$
353

354         declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_LEFT_SOURCE,
355                 PATH_POINTER + "left_source.bmp", true); //$NON-NLS-1$
356
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_LEFT_MASK,
357                 PATH_POINTER + "left_mask.bmp", true); //$NON-NLS-1$
358
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_RIGHT_SOURCE,
359                 PATH_POINTER + "right_source.bmp", true); //$NON-NLS-1$
360
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_RIGHT_MASK,
361                 PATH_POINTER + "right_mask.bmp", true); //$NON-NLS-1$
362
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOP_SOURCE,
363                 PATH_POINTER + "top_source.bmp", true); //$NON-NLS-1$
364
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOP_MASK,
365                 PATH_POINTER + "top_mask.bmp", true); //$NON-NLS-1$
366
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_BOTTOM_SOURCE,
367                 PATH_POINTER + "bottom_source.bmp", true); //$NON-NLS-1$
368
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_BOTTOM_MASK,
369                 PATH_POINTER + "bottom_mask.bmp", true); //$NON-NLS-1$
370
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_INVALID_SOURCE,
371                 PATH_POINTER + "invalid_source.bmp", true); //$NON-NLS-1$
372
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_INVALID_MASK,
373                 PATH_POINTER + "invalid_mask.bmp", true); //$NON-NLS-1$
374
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_STACK_SOURCE,
375                 PATH_POINTER + "stack_source.bmp", true); //$NON-NLS-1$
376
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_STACK_MASK,
377                 PATH_POINTER + "stack_mask.bmp", true); //$NON-NLS-1$
378
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_OFFSCREEN_SOURCE,
379                 PATH_POINTER + "offscreen_source.bmp", true); //$NON-NLS-1$
380
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_OFFSCREEN_MASK,
381                 PATH_POINTER + "offscreen_mask.bmp", true); //$NON-NLS-1$
382
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOFASTVIEW_SOURCE,
383                 PATH_POINTER + "tofastview_source.bmp", true); //$NON-NLS-1$
384
declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOFASTVIEW_MASK,
385                 PATH_POINTER + "tofastview_mask.bmp", true); //$NON-NLS-1$
386

387         // signed jar images
388
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_YES, PATH_OBJECT
389                 + "signed_yes_tbl.gif", true); //$NON-NLS-1$
390
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_NO, PATH_OBJECT
391                 + "signed_no_tbl.gif", true); //$NON-NLS-1$
392
declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_UNKNOWN,
393                 PATH_OBJECT + "signed_unkn_tbl.gif", true); //$NON-NLS-1$
394

395         // Manually create the view menu
396

397         Display d = Display.getCurrent();
398         
399         Image viewMenu = new Image(d, 11, 16);
400         Image viewMenuMask = new Image(d, 11, 16);
401         
402         GC gc = new GC(viewMenu);
403         GC maskgc = new GC(viewMenuMask);
404         drawViewMenu(gc, maskgc);
405         gc.dispose();
406         maskgc.dispose();
407         
408         ImageData data = viewMenu.getImageData();
409         data.transparentPixel = data.getPixel(0,0);
410         
411         Image vm2 = new Image(d, viewMenu.getImageData(), viewMenuMask.getImageData());
412         viewMenu.dispose();
413         viewMenuMask.dispose();
414                 
415         getImageRegistry().put(IWorkbenchGraphicConstants.IMG_LCL_RENDERED_VIEW_MENU, vm2);
416         
417     }
418
419     /**
420      * Declares a workbench image.
421      * <p>
422      * The workbench remembers the given image descriptor under the given name,
423      * and makes the image available to plug-ins via
424      * {@link org.eclipse.ui.ISharedImages IWorkbench.getSharedImages()}.
425      * For "shared" images, the workbench remembers the image descriptor and
426      * will manages the image object create from it; clients retrieve "shared"
427      * images via
428      * {@link org.eclipse.ui.ISharedImages#getImage ISharedImages.getImage()}.
429      * For the other, "non-shared" images, the workbench remembers only the
430      * image descriptor; clients retrieve the image descriptor via
431      * {@link org.eclipse.ui.ISharedImages#getImageDescriptor
432      * ISharedImages.getImageDescriptor()} and are entirely
433      * responsible for managing the image objects they create from it.
434      * (This is made confusing by the historical fact that the API interface
435      * is called "ISharedImages".)
436      * </p>
437      *
438      * @param symbolicName the symbolic name of the image
439      * @param descriptor the image descriptor
440      * @param shared <code>true</code> if this is a shared image, and
441      * <code>false</code> if this is not a shared image
442      * @see org.eclipse.ui.ISharedImages#getImage
443      * @see org.eclipse.ui.ISharedImages#getImageDescriptor
444      */

445     public static void declareImage(String JavaDoc symbolicName,
446             ImageDescriptor descriptor, boolean shared) {
447         if (Policy.DEBUG_DECLARED_IMAGES) {
448             Image image = descriptor.createImage(false);
449             if (image == null) {
450                 WorkbenchPlugin.log("Image not found in WorkbenchImages.declaredImage(). symbolicName=" + symbolicName + " descriptor=" + descriptor, new Exception JavaDoc("stack dump")); //$NON-NLS-1$//$NON-NLS-2$//$NON-NLS-3$
451
}
452             else {
453                 image.dispose();
454             }
455         }
456         getDescriptors().put(symbolicName, descriptor);
457         if (shared) {
458             getImageRegistry().put(symbolicName, descriptor);
459         }
460     }
461
462     /**
463      * Returns the map from symbolic name to ImageDescriptor.
464      *
465      * @return the map from symbolic name to ImageDescriptor.
466      */

467     private static Map JavaDoc getDescriptors() {
468         if (descriptors == null) {
469             initializeImageRegistry();
470         }
471         return descriptors;
472     }
473     
474     /**
475      * Returns the image stored in the workbench plugin's image registry
476      * under the given symbolic name. If there isn't any value associated
477      * with the name then <code>null</code> is returned.
478      *
479      * The returned Image is managed by the workbench plugin's image registry.
480      * Callers of this method must not dispose the returned image.
481      *
482      * This method is essentially a convenient short form of
483      * WorkbenchImages.getImageRegistry.get(symbolicName).
484      */

485     public static Image getImage(String JavaDoc symbolicName) {
486         return getImageRegistry().get(symbolicName);
487     }
488
489     /**
490      * Returns the image descriptor stored under the given symbolic name.
491      * If there isn't any value associated with the name then <code>null
492      * </code> is returned.
493      *
494      * The class also "caches" commonly used images in the image registry.
495      * If you are looking for one of these common images it is recommended you use
496      * the getImage() method instead.
497      */

498     public static ImageDescriptor getImageDescriptor(String JavaDoc symbolicName) {
499         return (ImageDescriptor) getDescriptors().get(symbolicName);
500     }
501
502     /**
503      * Convenience Method.
504      * Returns an ImageDescriptor obtained from an external program.
505      * If there isn't any image then <code>null</code> is returned.
506      *
507      * This method is convenience and only intended for use by the workbench because it
508      * explicitly uses the workbench's registry for caching/retrieving images from other
509      * extensions -- other plugins must user their own registry.
510      * This convenience method is subject to removal.
511      *
512      * Note:
513      * This consults the plugin for extension and obtains its installation location.
514      * all requested images are assumed to be in a directory below and relative to that
515      * plugins installation directory.
516      */

517
518     public static ImageDescriptor getImageDescriptorFromProgram(
519             String JavaDoc filename, int offset) {
520         Assert.isNotNull(filename);
521         String JavaDoc key = filename + "*" + offset; //use * as it is not a valid filename character//$NON-NLS-1$
522
ImageDescriptor desc = getImageDescriptor(key);
523         if (desc == null) {
524             desc = new ProgramImageDescriptor(filename, offset);
525             getDescriptors().put(key, desc);
526         }
527         return desc;
528     }
529
530     /**
531      * Returns the ImageRegistry.
532      */

533     public static ImageRegistry getImageRegistry() {
534         if (imageRegistry == null) {
535             initializeImageRegistry();
536         }
537         return imageRegistry;
538     }
539
540     /**
541      * Initialize the image registry by declaring all of the required
542      * graphics. This involves creating JFace image descriptors describing
543      * how to create/find the image should it be needed.
544      * The image is not actually allocated until requested.
545      *
546      * Prefix conventions
547      * Wizard Banners WIZBAN_
548      * Preference Banners PREF_BAN_
549      * Property Page Banners PROPBAN_
550      * Enable toolbar ETOOL_
551      * Disable toolbar DTOOL_
552      * Local enabled toolbar ELCL_
553      * Local Disable toolbar DLCL_
554      * Object large OBJL_
555      * Object small OBJS_
556      * View VIEW_
557      * Product images PROD_
558      * Misc images MISC_
559      *
560      * Where are the images?
561      * The images (typically gifs) are found in the same location as this plugin class.
562      * This may mean the same package directory as the package holding this class.
563      * The images are declared using this.getClass() to ensure they are looked up via
564      * this plugin class.
565      * @see ImageRegistry
566      */

567     private static void initializeImageRegistry() {
568         imageRegistry = new ImageRegistry();
569         descriptors = new HashMap JavaDoc();
570         declareImages();
571     }
572     
573     /**
574      * Disposes and clears the workbench images.
575      * Called when the workbench is shutting down.
576      *
577      * @since 3.1
578      */

579     public static void dispose() {
580         if (imageRegistry != null) {
581             imageRegistry.dispose();
582             imageRegistry = null;
583             descriptors = null;
584         }
585     }
586     
587     /**
588      * Get the workbench image with the given path relative to
589      * ICON_PATH.
590      * @param relativePath
591      * @return ImageDescriptor
592      */

593     public static ImageDescriptor getWorkbenchImageDescriptor(String JavaDoc relativePath){
594         return ImageDescriptor.createFromURL(BundleUtility.find(PlatformUI.PLUGIN_ID, ICONS_PATH + relativePath));
595     }
596 }
597
Popular Tags