...
Registering each image indvidually in the start method of the plugins Activator class tends to be very cumbersome if you have a huge number of images. Besides the many lines of code you have to write, it is requires code changes to update or add new images. Alternatively, you can use image sets to avoid these drawbacks.
An image set is a collection of one or more images that is defined in a XML-serialized Java property file. Each image is represented as a key-value pair consisting of the image ID (as the key) and the relative file path (as the value):
Code Block | ||||
---|---|---|---|---|
| ||||
<?xml version="1.0" encoding="UTF-8" standalone="no"?>
<!DOCTYPE properties SYSTEM "http://java.sun.com/dtd/properties.dtd">
<properties>
<comment>Image set configuration file. Edit only if you know what you are doing</comment>
<entry key="DEFAULT">operator-images/default/gear.png</entry>
<entry key="JOIN">operator-images/default/join2.png</entry>
<!-- more image definitions -->
</properties> |
Similar to single images, you must register an image set at the Image Manager before you can use it:
Code Block | ||||
---|---|---|---|---|
| ||||
@Override
public void start(BundleContext bundleContext) throws Exception {
super.start(bundleContext);
// create instance of ImageManager
imageManager = new ImageManager(bundleContext.getBundle());
// register image set
imageManager.registerImageSet("white", "operator-images/icons_white.xml");
// ...
} |
The registerImageSet(...)
method requires two arguments. The first argument is the name of the image set which can be considered as the namespace of the images contained in the image set. It is added as prefix seperated by a dot (".") to each image id in order to avoid name clashes between different image sets. The second argument is the relative path to the property file that specifies the image set.
The OdysseusRCPPlugIn
class provides different image sets (white
, black
, and default
) each containing a number of illustrating icons for physical operators.