Eclipse Platform
Release 3.1

org.eclipse.jface.resource
Class ImageRegistry

java.lang.Object
  extended byorg.eclipse.jface.resource.ImageRegistry

public class ImageRegistry
extends Object

An image registry maintains a mapping between symbolic image names and SWT image objects or special image descriptor objects which defer the creation of SWT image objects until they are needed.

An image registry owns all of the image objects registered with it, and automatically disposes of them when the SWT Display that creates the images is disposed. Because of this, clients do not need to (indeed, must not attempt to) dispose of these images themselves.

Clients may instantiate this class (it was not designed to be subclassed).

Unlike the FontRegistry, it is an error to replace images. As a result there are no events that fire when values are changed in the registry


Constructor Summary
ImageRegistry()
          Creates an empty image registry.
ImageRegistry(Display display)
          Creates an empty image registry.
ImageRegistry(ResourceManager manager)
          Creates an empty image registry using the given resource manager to allocate images.
 
Method Summary
 void dispose()
          Disposes this image registry, disposing any images that were allocated for it, and clearing its entries.
 Image get(String key)
          Returns the image associated with the given key in this registry, or null if none.
 ImageDescriptor getDescriptor(String key)
          Returns the descriptor associated with the given key in this registry, or null if none.
 void put(String key, Image image)
          Adds an image to this registry.
 void put(String key, ImageDescriptor descriptor)
          Adds (or replaces) an image descriptor to this registry.
 void remove(String key)
          Removes an image from this registry.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageRegistry

public ImageRegistry()
Creates an empty image registry.

There must be an SWT Display created in the current thread before calling this method.


ImageRegistry

public ImageRegistry(ResourceManager manager)
Creates an empty image registry using the given resource manager to allocate images.

Parameters:
manager - the resource manager used to allocate images
Since:
3.1

ImageRegistry

public ImageRegistry(Display display)
Creates an empty image registry.

Parameters:
display - this Display must not be null and must not be disposed in order to use this registry
Method Detail

get

public Image get(String key)
Returns the image associated with the given key in this registry, or null if none.

Parameters:
key - the key
Returns:
the image, or null if none

getDescriptor

public ImageDescriptor getDescriptor(String key)
Returns the descriptor associated with the given key in this registry, or null if none.

Parameters:
key - the key
Returns:
the descriptor, or null if none
Since:
2.1

put

public void put(String key,
                ImageDescriptor descriptor)
Adds (or replaces) an image descriptor to this registry. The first time this new entry is retrieved, the image descriptor's image will be computed (via ImageDescriptor.createImage) and remembered. This method replaces an existing image descriptor associated with the given key, but fails if there is a real image associated with it.

Parameters:
key - the key
descriptor - the ImageDescriptor
Throws:
IllegalArgumentException - if the key already exists

put

public void put(String key,
                Image image)
Adds an image to this registry. This method fails if there is already an image or descriptor for the given key.

Note that an image registry owns all of the image objects registered with it, and automatically disposes of them when the SWT Display is disposed. Because of this, clients must not register an image object that is managed by another object.

Parameters:
key - the key
image - the image
Throws:
IllegalArgumentException - if the key already exists

remove

public void remove(String key)
Removes an image from this registry. If an SWT image was allocated, it is disposed. This method has no effect if there is no image or descriptor for the given key.

Parameters:
key - the key

dispose

public void dispose()
Disposes this image registry, disposing any images that were allocated for it, and clearing its entries.

Since:
3.1

Eclipse Platform
Release 3.1

Guidelines for using Eclipse APIs.

Copyright (c) IBM Corp. and others 2000, 2005. All rights reserved.