-
Notifications
You must be signed in to change notification settings - Fork 43
ImageService
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.
The Image Service contains the following icons. How to show them in your plugin is explained in chapter Usage.
ImageService.ICON_INFO (platform:/plugin/org.eclipse.jface/org/eclipse/jface/dialogs/images/message_info.png)
ImageService.ICON_WARNING (platform:/plugin/org.eclipse.ui/icons/full/obj16/warn_tsk.png)
ImageService.ICON_ERROR (platform:/plugin/org.eclipse.ui/icons/full/obj16/error_tsk.png)
ImageService.ICON_HELP (platform:/plugin/org.eclipse.ui/icons/full/etool16/help_contents.png)
ImageService.ICON_RESET (platform:/plugin/org.jcryptool.core.util/icons/icon_reset.png)
ImageService.ICON_VISUALIZATIONS (platform:/plugin/org.eclipse.ui/icons/full/eview16/defaultview_misc.png)
ImageService.ICON_ANALYSIS (platform:/plugin/org.jcryptool.core.util/icons/analysis_icon.gif)
ImageService.ICON_CHECKBOX (platform:/plugin/org.jcryptool.core.util/icons/check.png)
ImageService.ICON_SEARCH (platform:/plugin/org.eclipse.search/icons/full/etool16/search.png)
ImageService.ICON_RUN (platform:/plugin/org.jcryptool.core.util/icons/run_exc.png)
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
.
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“.
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.
Now your plugin is ready to use the Image Service.
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:
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:
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
.
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.
Need help? Please visit the public JCT Chatroom or open a new Issue and ask your question. We'll be happy to assist you!