org.springframework.richclient.image
Class DefaultImageSource

java.lang.Object
  extended by org.springframework.richclient.image.DefaultImageSource
All Implemented Interfaces:
ImageSource

public class DefaultImageSource
extends Object
implements ImageSource

A collection of image resources, each indexed by a common key alias.

For example, action.edit.copy = /images/edit/copy.gif

This class by default performs caching of all loaded image resources using soft references (TODO it just lazy loads them, but it doesn't use SoftReference).

An image Handler is available that handles the 'image' protocol. Check the javadocs of the handler to know how to use/register it.

Author:
Keith Donald

Field Summary
protected static org.apache.commons.logging.Log logger
           
 
Constructor Summary
DefaultImageSource(boolean installUrlHandler, Map imageResources)
          Creates a image resource bundle containing the specified map of keys to resource paths.
DefaultImageSource(Map imageResources)
          Creates a image resource bundle containing the specified map of keys to resource paths.
 
Method Summary
 boolean containsKey(Object key)
           
 Image getImage(String key)
          Loads the image with the specified key.
 Image getImageAtLocation(Resource location)
           
 AwtImageResource getImageResource(String key)
          Returns the image resource indexed by the specified key.
 void setBrokenImageIndicator(Resource resource)
           
 int size()
           
 String toString()
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

logger

protected static final org.apache.commons.logging.Log logger
Constructor Detail

DefaultImageSource

public DefaultImageSource(Map imageResources)
Creates a image resource bundle containing the specified map of keys to resource paths.

A custom URL protocol handlerwill be installed for the "image:" protocol. This allows for images in this image source to be located using the Java URL classes:
URL imageUrl = new URL("image:the.image.key")

Parameters:
imageResources - a map of key-to-image-resources.

DefaultImageSource

public DefaultImageSource(boolean installUrlHandler,
                          Map imageResources)
Creates a image resource bundle containing the specified map of keys to resource paths.

Parameters:
installUrlHandler - should a URL handler be installed.
imageResources - a map of key-to-image-resources.
Method Detail

getImage

public Image getImage(String key)
Description copied from interface: ImageSource
Loads the image with the specified key. Caching may or may not be performed.

If the load is successful, the image resource is returned. If the load fails, a broken image indicator is returned if it is set for this source. If not set, an exception is thrown.

Specified by:
getImage in interface ImageSource
Parameters:
key - The image key
Returns:
The image.

getImageResource

public AwtImageResource getImageResource(String key)
Description copied from interface: ImageSource
Returns the image resource indexed by the specified key. A resource is a lightweight pointer to the image in the classpath, filesystem, or network, and not the actual loaded image itself.

Specified by:
getImageResource in interface ImageSource
Parameters:
key - The image key.
Returns:
The image resource.

containsKey

public boolean containsKey(Object key)

getImageAtLocation

public Image getImageAtLocation(Resource location)

size

public int size()

setBrokenImageIndicator

public void setBrokenImageIndicator(Resource resource)

toString

public String toString()
Overrides:
toString in class Object


Copyright © 2004-2008 The Spring Framework. All Rights Reserved.