Versions Compared

Key

  • This line was added.
  • This line was removed.
  • Formatting was changed.

Image Manager

The ImageManager class is the recommended way to load and display images in Odysseus Studio. It provides advanced features like lazy loading and caching while it is still easy to use.

If you want to provide images with your bundle, the bundle's Activator class should manage an instance of the ImageManager. Before you can use the image manager to access the images, you must create the instance and register your images in the bundle's start method.

Code Block
languagejava
titleSet up image manager
@Override
public void start(BundleContext bundleContext) throws Exception {
    super.start(bundleContext);

	// create instance of ImageManager
	imageManager = new ImageManager(bundleContext.getBundle());

	// register image
	imageManager.register("someImageID", "icons/someImage.png");

	// ...
}

You must pass the current bundle to the constructor of the image manager. Otherwise it won't be able to access the image files located in your bundle. After the initialization of the image manager, you need to register each image using the register(...) method. The first parameter is the image ID which must be unique for the image manager instance. The second parameter is the path of your image file inside your bundle.

After you've registered your images, you can easily access and load the image. All you need to do is to access the image manager from your bundle (or any other available bundle's activator providing an image manager) and call the get(...) method passing the image ID of the requested image.

Code Block
languagejava
titleRetrieving image from image manager
Image image = MyRCPPlugIn.getImageManager().get("someImageID");

Image sets

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.