Skip to content
Thorben Groos edited this page Apr 11, 2020 · 8 revisions

The ImageService is an easy to use service for showing images and icons in your plugin. You can either use the plugin to show one of the standard icons (Info, Warning, Error, etc.) or load your own image and show it in your plugin.

Standard icons

The Image Service contains the following icons. How to show them in your plugin is explained in chapter Usage.

Info Icon ImageService.ICON_INFO (platform:/plugin/org.eclipse.jface/org/eclipse/jface/dialogs/images/message_info.png)

Warning Icon ImageService.ICON_WARNING (platform:/plugin/org.eclipse.ui/icons/full/obj16/warn_tsk.png)

Error Icon ImageService.ICON_ERROR (platform:/plugin/org.eclipse.ui/icons/full/obj16/error_tsk.png)

Help Icon ImageService.ICON_HELP (platform:/plugin/org.eclipse.ui/icons/full/etool16/help_contents.png)

Reset Icon ImageService.ICON_RESET (platform:/plugin/org.jcryptool.core.util/icons/icon_reset.png)

Visualizations Icon ImageService.ICON_VISUALIZATIONS (platform:/plugin/org.eclipse.ui/icons/full/eview16/defaultview_misc.png)

Analysis Icon ImageService.ICON_ANALYSIS (platform:/plugin/org.jcryptool.core.util/icons/analysis_icon.gif)

Checkbox Icon ImageService.ICON_CHECKBOX (platform:/plugin/org.jcryptool.core.util/icons/check.png)

Search Icon ImageService.ICON_SEARCH (platform:/plugin/org.eclipse.search/icons/full/etool16/search.png)

Run Icon ImageService.ICON_RUN (platform:/plugin/org.jcryptool.core.util/icons/run_exc.png)

File Icon ImageService.ICON_FILE (platform:/plugin/org.jcryptool.core.util/icons/fileType_filter.png)

The link in brackets (platform:/...) can be used in the plugin.xml to get the specific icon.

The icon service can either provide an Image or an ImageDescriptor, depending on what you need. The previous examples show how to get the Image. If you need an ImageDescriptor just use ImageService.IMAGEDESCRIPTOR_INFO instead of ImageService.ICON_INFO.

Usage

Prerequisites

Now you may question yourself „How can I use that cool feature?“. The answer is quite simple. As starting position it is assumed that you have a plugin with like the one shown on the next screenshot. For example I use the Chinese Remainder Theorem Plugin (org.jcryptool.visual.crt). There you have, as in all other plugin too, a „src“ folder containing the program code and a „META-INF“ folder containing a file called „META-INF“.

Package Explorer

The first step is to add org.jcryptool.core.utils to the MANIFEST.MF under “Required-Bundle”. The following Screenshot shows a MANIFEST.MF with the necessary entry.

MANIFEST.MF with org.jcryptool.util added

Now your plugin is ready to use the Image Service.

Code Examples for default Icons/Images

The following code snippet shows how you can add an image to Label.

Label label = new Label(parent, SWT.NONE);
label.setImage(ImageService.ICON_INFO);

The result is this: Label showing info icon

If you want to show a text and image in one Label you must use CLabel. The normal Label does not support this possibility.

CLabel clabel = new CLabel(parent, SWT.NONE);
clabel.setText(“d wurde neu berechnet.”);
clabel.setImage(ImageService.ICON_INFO);

The result is this: Label showing text and an icon

Code Examples for own Icons/Images

To load an image from a folder inside your plugin just call

ImageService.getImage(PLUGIN_ID, filepath);

You can find your PLUGIN_ID in the class of your plugin that extends the AbstractUIPlugin. A PLUGIN_ID looks like org.jcryptool.visual.crt.

The filepath looks like images/myFile.png.

Misc

The Image Service follows the @2x convention. The @2x convention ensures that high-resolution images are displayed on high-resolution displays. For more information about the @2x convention see https://www.eclipse.org/eclipse/news/4.6/platform_isv.php#high-dpi-icons.