prefuse.render
Class ImageFactory

java.lang.Object
  extended by prefuse.render.ImageFactory

public class ImageFactory
extends java.lang.Object

Utility class that manages loading and storing images. Includes a configurable LRU cache for managing loaded images. Also supports optional image scaling of loaded images to cut down on memory and visualization operation costs.

By default images are loaded upon first request. Use the preloadImages(Iterator, String) method to load images before they are requested for rendering.

Author:
alan newberger, jeffrey heer

Field Summary
protected  java.awt.Component component
           
protected  java.util.Map imageCache
           
protected  java.util.Map loadMap
           
protected  boolean m_asynch
           
protected  int m_imageCacheSize
           
protected  int m_maxImageHeight
           
protected  int m_maxImageWidth
           
protected  int nextTrackerID
           
protected  java.awt.MediaTracker tracker
           
 
Constructor Summary
ImageFactory()
          Create a new ImageFactory.
ImageFactory(int maxImageWidth, int maxImageHeight)
          Create a new ImageFactory.
 
Method Summary
 java.awt.Image addImage(java.lang.String location, java.awt.Image image)
          Adds an image associated with a location string to this factory's cache.
 java.awt.Image getImage(java.lang.String imageLocation)
          Get the image associated with the given location string.
protected  java.awt.Image getScaledImage(java.awt.Image img)
          Scales an image to fit within the current size thresholds.
 boolean isAsynchronous()
          Indicates if this ImageFactory loads images asynchronously (true by default)
 boolean isInCache(java.lang.String imageLocation)
          Indicates if the given string location corresponds to an image currently stored in this ImageFactory's cache.
 void preloadImages(java.util.Iterator iter, java.lang.String field)
          Preloads images for use in a visualization.
 void setAsynchronous(boolean b)
          Sets if this ImageFactory loads images asynchronously.
 void setImageCacheSize(int size)
          Sets the capacity of this factory's image cache
 void setMaxImageDimensions(int width, int height)
          Sets the maximum image dimensions of loaded images, images larger than these limits will be scaled to fit within bounds.
protected  void waitForImage(java.awt.Image image)
          Wait for an image to load.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

m_imageCacheSize

protected int m_imageCacheSize

m_maxImageWidth

protected int m_maxImageWidth

m_maxImageHeight

protected int m_maxImageHeight

m_asynch

protected boolean m_asynch

imageCache

protected java.util.Map imageCache

loadMap

protected java.util.Map loadMap

component

protected final java.awt.Component component

tracker

protected final java.awt.MediaTracker tracker

nextTrackerID

protected int nextTrackerID
Constructor Detail

ImageFactory

public ImageFactory()
Create a new ImageFactory. Assumes no scaling of loaded images.


ImageFactory

public ImageFactory(int maxImageWidth,
                    int maxImageHeight)
Create a new ImageFactory. This instance will scale loaded images if they exceed the threshold arguments.

Parameters:
maxImageWidth - the maximum width of input images (-1 means no limit)
maxImageHeight - the maximum height of input images (-1 means no limit)
Method Detail

isAsynchronous

public boolean isAsynchronous()
Indicates if this ImageFactory loads images asynchronously (true by default)

Returns:
true for asynchronous (background) loading, false for synchronous (blocking) loading

setAsynchronous

public void setAsynchronous(boolean b)
Sets if this ImageFactory loads images asynchronously.

Parameters:
b - true for asynchronous (background) loading, false for synchronous (blocking) loading

setMaxImageDimensions

public void setMaxImageDimensions(int width,
                                  int height)
Sets the maximum image dimensions of loaded images, images larger than these limits will be scaled to fit within bounds.

Parameters:
width - the maximum width of input images (-1 means no limit)
height - the maximum height of input images (-1 means no limit)

setImageCacheSize

public void setImageCacheSize(int size)
Sets the capacity of this factory's image cache

Parameters:
size - the new size of the image cache

isInCache

public boolean isInCache(java.lang.String imageLocation)
Indicates if the given string location corresponds to an image currently stored in this ImageFactory's cache.

Parameters:
imageLocation - the image location string
Returns:
true if the location is a key for a currently cached image, false otherwise.

getImage

public java.awt.Image getImage(java.lang.String imageLocation)

Get the image associated with the given location string. If the image has already been loaded, it simply will return the image, otherwise it will load it from the specified location.

The imageLocation argument must be a valid resource string pointing to either (a) a valid URL, (b) a file on the classpath, or (c) a file on the local filesystem. The location will be resolved in that order.

Parameters:
imageLocation - the image location as a resource string.
Returns:
the corresponding image, if available

addImage

public java.awt.Image addImage(java.lang.String location,
                               java.awt.Image image)
Adds an image associated with a location string to this factory's cache. The image will be scaled as dictated by this current factory settings.

Parameters:
location - the location string uniquely identifying the image
image - the actual image
Returns:
the final image added to the cache. This may be a scaled version of the original input image.

waitForImage

protected void waitForImage(java.awt.Image image)
Wait for an image to load.

Parameters:
image - the image to wait for

getScaledImage

protected java.awt.Image getScaledImage(java.awt.Image img)
Scales an image to fit within the current size thresholds.

Parameters:
img - the image to scale
Returns:
the scaled image

preloadImages

public void preloadImages(java.util.Iterator iter,
                          java.lang.String field)

Preloads images for use in a visualization. Images to load are determined by taking objects from the given iterator and retrieving the value of the specified field. The items in the iterator must be instances of the Tuple class.

Images are loaded in the order specified by the iterator until the the iterator is empty or the maximum image cache size is met. Thus higher priority images should appear sooner in the iteration.

Parameters:
iter - an Iterator of Tuple instances
field - the data field that contains the image location


Copyright © 2007 Regents of the University of California