com.sdm.quasar.client.swing.common.util
Class ImageCache

java.lang.Object
  extended bycom.sdm.quasar.client.swing.common.util.ImageCache

public class ImageCache
extends java.lang.Object

An image cache, that stores ImageIcon used by an application so, that thei will be freeed from memory, when the memory runs out of space and will be recreated, when used again.

Version:
1.$Revision: 1.2 $
Author:
Thomas Wolf

Nested Class Summary
static class ImageCache.ImageCreator
          This class holds an image with a soft reference to it.
 
Constructor Summary
ImageCache()
          Creates a new ImageCache.
 
Method Summary
 void clearImageReference(java.lang.String name)
          Frees up the space consumed by the image specified within the image cache.
static ImageCache getGlobalImageCache()
          Returns a global ImageCache instance.
 javax.swing.ImageIcon getImageIcon(java.lang.String name)
          Returns an image with the unique name given from the cache.
 void registerImageCreator(java.lang.String name, ImageCache.ImageCreator imageCreator)
          Registers an ImageCache.ImageCreator for the given image name.
 void removeImageCreator(java.lang.String name)
          Removes a previously registered ImageCache.ImageCreator from this ImageCache.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCache

public ImageCache()
Creates a new ImageCache.

Method Detail

getImageIcon

public javax.swing.ImageIcon getImageIcon(java.lang.String name)
Returns an image with the unique name given from the cache. This assumes, that #registerImageCreator(String,ImageCreator) is called before. If this is not the case, null will be returned.

Parameters:
name - the name of the ImageIcon to return
Returns:
the ImageIcon created or null, if no valid ImageCache.ImageCreator was registered for the image name.

clearImageReference

public void clearImageReference(java.lang.String name)
Frees up the space consumed by the image specified within the image cache. The next time, the image is requested via getImageIcon(String), it well reallocate the memory needed.

Parameters:
name - the name of the ImageIcon to clear

registerImageCreator

public void registerImageCreator(java.lang.String name,
                                 ImageCache.ImageCreator imageCreator)
Registers an ImageCache.ImageCreator for the given image name.

Parameters:
name - the image name to register the ImageCache.ImageCreator under
imageCreator - the ImageCache.ImageCreator to be used for the name

removeImageCreator

public void removeImageCreator(java.lang.String name)
Removes a previously registered ImageCache.ImageCreator from this ImageCache.

Parameters:
name - the unique name of the image to remove a ImageCache.ImageCreator for

getGlobalImageCache

public static ImageCache getGlobalImageCache()
Returns a global ImageCache instance.