1 11 package org.eclipse.ui.internal; 12 13 import java.net.URL ; 14 import java.util.HashMap ; 15 import java.util.Map ; 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 67 publicclass WorkbenchImages { 68 69 private static Map descriptors; 70 71 private static ImageRegistry imageRegistry; 72 73 74 75 public final static String ICONS_PATH = "$nl$/icons/full/"; 77 private final static String PATH_ETOOL = ICONS_PATH + "etool16/"; 79 private final static String PATH_DTOOL = ICONS_PATH + "dtool16/"; 81 private final static String PATH_ELOCALTOOL = ICONS_PATH + "elcl16/"; 83 private final static String PATH_DLOCALTOOL = ICONS_PATH + "dlcl16/"; 85 private final static String PATH_EVIEW = ICONS_PATH + "eview16/"; 87 private final static String PATH_OBJECT = ICONS_PATH + "obj16/"; 90 private final static String PATH_POINTER = ICONS_PATH + "pointer/"; 92 private final static String PATH_WIZBAN = ICONS_PATH + "wizban/"; 94 95 99 110 private final static void declareImage(String key, String path, 111 boolean shared) { 112 URL 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 143 private final static void declareImages() { 144 145 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR, 146 PATH_ETOOL + "pin_editor.gif", false); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PIN_EDITOR_DISABLED, 148 PATH_DTOOL + "pin_editor.gif", false); 150 152 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVE_EDIT, PATH_ETOOL 153 + "save_edit.gif", false); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVE_EDIT_DISABLED, 155 PATH_DTOOL + "save_edit.gif", false); 157 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT, 158 PATH_ETOOL + "saveas_edit.gif", false); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEAS_EDIT_DISABLED, 160 PATH_DTOOL + "saveas_edit.gif", false); 162 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_SAVEALL_EDIT, 163 PATH_ETOOL + "saveall_edit.gif", false); declareImage( 165 IWorkbenchGraphicConstants.IMG_ETOOL_SAVEALL_EDIT_DISABLED, 166 PATH_DTOOL + "saveall_edit.gif", false); 168 declareImage(ISharedImages.IMG_TOOL_UNDO, 169 PATH_ETOOL + "undo_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_UNDO_HOVER, PATH_ETOOL 171 + "undo_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_UNDO_DISABLED, PATH_DTOOL 173 + "undo_edit.gif", true); 175 declareImage(ISharedImages.IMG_TOOL_REDO, 176 PATH_ETOOL + "redo_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_REDO_HOVER, PATH_ETOOL 178 + "redo_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_REDO_DISABLED, PATH_DTOOL 180 + "redo_edit.gif", true); 182 declareImage(ISharedImages.IMG_TOOL_CUT, 183 PATH_ETOOL + "cut_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_CUT_HOVER, PATH_ETOOL 185 + "cut_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_CUT_DISABLED, PATH_DTOOL 187 + "cut_edit.gif", true); 189 declareImage(ISharedImages.IMG_TOOL_COPY, 190 PATH_ETOOL + "copy_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_COPY_HOVER, PATH_ETOOL 192 + "copy_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_COPY_DISABLED, PATH_DTOOL 194 + "copy_edit.gif", true); 196 declareImage(ISharedImages.IMG_TOOL_PASTE, PATH_ETOOL 197 + "paste_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_PASTE_HOVER, PATH_ETOOL 199 + "paste_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_PASTE_DISABLED, PATH_DTOOL 201 + "paste_edit.gif", true); 203 declareImage(ISharedImages.IMG_TOOL_DELETE, PATH_ETOOL 204 + "delete_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_DELETE_HOVER, PATH_ETOOL 206 + "delete_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_DELETE_DISABLED, PATH_DTOOL 208 + "delete_edit.gif", true); declareImage(ISharedImages.IMG_TOOL_NEW_WIZARD, 210 PATH_ETOOL + "new_wiz.gif", true); declareImage(ISharedImages.IMG_TOOL_NEW_WIZARD_HOVER, PATH_ETOOL 212 + "new_wiz.gif", true); declareImage(ISharedImages.IMG_TOOL_NEW_WIZARD_DISABLED, PATH_DTOOL 214 + "new_wiz.gif", true); 216 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PRINT_EDIT, 217 PATH_ETOOL + "print_edit.gif", false); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_PRINT_EDIT_DISABLED, 219 PATH_DTOOL + "print_edit.gif", false); 221 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_HELP_CONTENTS, 222 PATH_ETOOL + "help_contents.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_HELP_SEARCH, 224 PATH_ETOOL + "help_search.gif", true); 226 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_NEW_FASTVIEW, 227 PATH_ETOOL + "new_fastview.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_DTOOL_NEW_FASTVIEW, 229 PATH_DTOOL + "new_fastview.gif", true); 231 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_RESTORE_TRIMPART, 232 PATH_ETOOL + "fastview_restore.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_EDITOR_TRIMPART, 234 PATH_ETOOL + "editor_area.gif", true); 236 declareImage(ISharedImages.IMG_TOOL_FORWARD, PATH_ELOCALTOOL 237 + "forward_nav.gif", true); declareImage(ISharedImages.IMG_TOOL_FORWARD_HOVER, PATH_ELOCALTOOL 239 + "forward_nav.gif", true); declareImage(ISharedImages.IMG_TOOL_FORWARD_DISABLED, PATH_DLOCALTOOL 241 + "forward_nav.gif", true); 243 declareImage(ISharedImages.IMG_TOOL_BACK, PATH_ELOCALTOOL 244 + "backward_nav.gif", true); declareImage(ISharedImages.IMG_TOOL_BACK_HOVER, PATH_ELOCALTOOL 246 + "backward_nav.gif", true); declareImage(ISharedImages.IMG_TOOL_BACK_DISABLED, PATH_DLOCALTOOL 248 + "backward_nav.gif", true); 250 declareImage(ISharedImages.IMG_TOOL_UP, 251 PATH_ELOCALTOOL + "up_nav.gif", true); declareImage(ISharedImages.IMG_TOOL_UP_HOVER, PATH_ELOCALTOOL 253 + "up_nav.gif", true); declareImage(ISharedImages.IMG_TOOL_UP_DISABLED, PATH_DLOCALTOOL 255 + "up_nav.gif", true); 257 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_NEW_PAGE, PATH_EVIEW 258 + "new_persp.gif", false); 260 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_HOME_NAV, 261 PATH_ELOCALTOOL + "home_nav.gif", false); 263 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_DEF_PERSPECTIVE, 264 PATH_EVIEW + "default_persp.gif", false); 266 declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_NEW_WIZ, PATH_WIZBAN 267 + "new_wiz.png", false); 269 273 declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_IMPORT_WIZ, PATH_ETOOL 274 + "import_wiz.gif", false); declareImage(IWorkbenchGraphicConstants.IMG_ETOOL_EXPORT_WIZ, PATH_ETOOL 276 + "export_wiz.gif", false); declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_WIZ, PATH_WIZBAN 278 + "import_wiz.png", false); declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_EXPORT_WIZ, PATH_WIZBAN 280 + "export_wiz.png", false); declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_IMPORT_PREF_WIZ, PATH_WIZBAN 282 + "importpref_wiz.png", false); declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_EXPORT_PREF_WIZ, PATH_WIZBAN 284 + "exportpref_wiz.png", false); 286 declareImage(IWorkbenchGraphicConstants.IMG_WIZBAN_WORKINGSET_WIZ, 287 PATH_WIZBAN + "workset_wiz.png", false); 289 declareImage(IWorkbenchGraphicConstants.IMG_VIEW_DEFAULTVIEW_MISC, 290 PATH_EVIEW + "defaultview_misc.gif", false); 292 declareImage(IWorkbenchGraphicConstants.IMG_OBJ_FONT, PATH_OBJECT 293 + "font.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_THEME_CATEGORY, 295 PATH_OBJECT + "theme_category.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_ACTIVITY, PATH_OBJECT 297 + "activity.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_ACTIVITY_CATEGORY, 299 PATH_OBJECT + "activity_category.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_WORKING_SETS, 301 PATH_OBJECT + "workingsets.gif", true); 303 declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SEPARATOR, 304 PATH_OBJECT + "separator.gif", true); 306 declareImage(IWorkbenchGraphicConstants.IMG_OBJ_NODE, 307 PATH_OBJECT + "generic_elements.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_ELEMENT, 309 PATH_OBJECT + "generic_element.gif", true); 311 declareImage(ISharedImages.IMG_OBJ_FILE, 312 PATH_OBJECT + "file_obj.gif", true); declareImage(ISharedImages.IMG_OBJ_FOLDER, 314 PATH_OBJECT + "fldr_obj.gif", true); declareImage(ISharedImages.IMG_OBJ_ELEMENT, PATH_OBJECT 316 + "elements_obj.gif", true); declareImage(ISharedImages.IMG_DEF_VIEW, PATH_EVIEW 318 + "defaultview_misc.gif", true); 320 declareImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW, 321 PATH_ELOCALTOOL + "close_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_PIN_VIEW, 323 PATH_ELOCALTOOL + "pin_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_MIN_VIEW, 325 PATH_ELOCALTOOL + "min_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU, 327 PATH_ELOCALTOOL + "view_menu.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_LINKTO_HELP, 329 PATH_ELOCALTOOL + "linkto_help.gif", true); 331 declareImage(IWorkbenchGraphicConstants.IMG_LCL_CLOSE_VIEW_THIN, 332 PATH_ELOCALTOOL + "thin_close_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_HIDE_TOOLBAR_THIN, 334 PATH_ELOCALTOOL + "thin_hide_toolbar.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_MAX_VIEW_THIN, 336 PATH_ELOCALTOOL + "thin_max_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_MIN_VIEW_THIN, 338 PATH_ELOCALTOOL + "thin_min_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_RESTORE_VIEW_THIN, 340 PATH_ELOCALTOOL + "thin_restore_view.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_SHOW_TOOLBAR_THIN, 342 PATH_ELOCALTOOL + "thin_show_toolbar.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_LCL_VIEW_MENU_THIN, 344 PATH_ELOCALTOOL + "thin_view_menu.gif", true); 346 347 declareImage(ISharedImages.IMG_OBJS_ERROR_TSK, PATH_OBJECT 348 + "error_tsk.gif", true); declareImage(ISharedImages.IMG_OBJS_WARN_TSK, PATH_OBJECT 350 + "warn_tsk.gif", true); declareImage(ISharedImages.IMG_OBJS_INFO_TSK, PATH_OBJECT 352 + "info_tsk.gif", true); 354 declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_LEFT_SOURCE, 355 PATH_POINTER + "left_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_LEFT_MASK, 357 PATH_POINTER + "left_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_RIGHT_SOURCE, 359 PATH_POINTER + "right_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_RIGHT_MASK, 361 PATH_POINTER + "right_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOP_SOURCE, 363 PATH_POINTER + "top_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOP_MASK, 365 PATH_POINTER + "top_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_BOTTOM_SOURCE, 367 PATH_POINTER + "bottom_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_BOTTOM_MASK, 369 PATH_POINTER + "bottom_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_INVALID_SOURCE, 371 PATH_POINTER + "invalid_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_INVALID_MASK, 373 PATH_POINTER + "invalid_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_STACK_SOURCE, 375 PATH_POINTER + "stack_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_STACK_MASK, 377 PATH_POINTER + "stack_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_OFFSCREEN_SOURCE, 379 PATH_POINTER + "offscreen_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_OFFSCREEN_MASK, 381 PATH_POINTER + "offscreen_mask.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOFASTVIEW_SOURCE, 383 PATH_POINTER + "tofastview_source.bmp", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJS_DND_TOFASTVIEW_MASK, 385 PATH_POINTER + "tofastview_mask.bmp", true); 387 declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_YES, PATH_OBJECT 389 + "signed_yes_tbl.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_NO, PATH_OBJECT 391 + "signed_no_tbl.gif", true); declareImage(IWorkbenchGraphicConstants.IMG_OBJ_SIGNED_UNKNOWN, 393 PATH_OBJECT + "signed_unkn_tbl.gif", true); 395 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 445 public static void declareImage(String 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 ("stack dump")); } 452 else { 453 image.dispose(); 454 } 455 } 456 getDescriptors().put(symbolicName, descriptor); 457 if (shared) { 458 getImageRegistry().put(symbolicName, descriptor); 459 } 460 } 461 462 467 private static Map getDescriptors() { 468 if (descriptors == null) { 469 initializeImageRegistry(); 470 } 471 return descriptors; 472 } 473 474 485 public static Image getImage(String symbolicName) { 486 return getImageRegistry().get(symbolicName); 487 } 488 489 498 public static ImageDescriptor getImageDescriptor(String symbolicName) { 499 return (ImageDescriptor) getDescriptors().get(symbolicName); 500 } 501 502 517 518 public static ImageDescriptor getImageDescriptorFromProgram( 519 String filename, int offset) { 520 Assert.isNotNull(filename); 521 String key = filename + "*" + offset; 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 533 public static ImageRegistry getImageRegistry() { 534 if (imageRegistry == null) { 535 initializeImageRegistry(); 536 } 537 return imageRegistry; 538 } 539 540 567 private static void initializeImageRegistry() { 568 imageRegistry = new ImageRegistry(); 569 descriptors = new HashMap (); 570 declareImages(); 571 } 572 573 579 public static void dispose() { 580 if (imageRegistry != null) { 581 imageRegistry.dispose(); 582 imageRegistry = null; 583 descriptors = null; 584 } 585 } 586 587 593 public static ImageDescriptor getWorkbenchImageDescriptor(String relativePath){ 594 return ImageDescriptor.createFromURL(BundleUtility.find(PlatformUI.PLUGIN_ID, ICONS_PATH + relativePath)); 595 } 596 } 597 | Popular Tags |