com.croftsoft.core.awt.image
Class ImageCache

java.lang.Object
  extended by com.croftsoft.core.awt.image.ImageCache

public final class ImageCache
extends Object

Caches loaded images by file name.

Since:
2002-02-05
Version:
2003-07-24
Author:
David Wallace Croft

Constructor Summary
ImageCache()
          Convenience constructor.
ImageCache(int transparency, Component component, ClassLoader classLoader, String mediaDir)
           
ImageCache(int transparency, Component component, ClassLoader classLoader, String mediaDir, Map imageMap)
          Main constructor.
ImageCache(Map imageMap)
          Convenience constructor.
 
Method Summary
 void clear()
           
 boolean containsKey(String imageFilename)
           
 BufferedImage get(String imageFilename)
           
 Image remove(String imageFilename)
           
 Image validate(String imageFilename)
          Validates the image without waiting to ensure load completion.
 Image validate(String imageFilename, Component component, long maxWaitTimeMs)
          Validates the image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCache

public ImageCache(int transparency,
                  Component component,
                  ClassLoader classLoader,
                  String mediaDir,
                  Map imageMap)
Main constructor.

Parameters:
imageMap - A Map of images keyed by filenames. You may wish to consider using a WeakHashMap instead of the default HashMap created by the convenience constructor.
See Also:
WeakHashMap

ImageCache

public ImageCache(int transparency,
                  Component component,
                  ClassLoader classLoader,
                  String mediaDir)

ImageCache

public ImageCache(Map imageMap)
Convenience constructor.


ImageCache

public ImageCache()
Convenience constructor. this(new HashMap());

Method Detail

clear

public void clear()

containsKey

public boolean containsKey(String imageFilename)

get

public BufferedImage get(String imageFilename)
                  throws IOException
Throws:
IOException

remove

public Image remove(String imageFilename)

validate

public Image validate(String imageFilename,
                      Component component,
                      long maxWaitTimeMs)
               throws IOException,
                      InterruptedException
Validates the image.

Checks to see if the image is already loaded. If not, loads the file as a class resource byte stream and converts to an image. If component is not null, creates a MediaTracker to wait until the image is completely loaded before returning.

Parameters:
imageFilename - The image filename and cache key. Filenames are relative to the root of the classpath or JAR file. Example: if the classpath is "J:\lib", this method would load "/images/image.png" from "J:\lib\images\image.png".
component - If null, a MediaTracker will not be used to ensure load completion before returning.
maxWaitTimeMs - The maximum time in milliseconds to wait for an image to finish loading before returning. Passed as the argument to MediaTracker.waitForAll().
Throws:
IOException
InterruptedException
See Also:
MediaTracker, ClassLib.getResourceAsImage(java.lang.Class, java.lang.String)

validate

public Image validate(String imageFilename)
               throws IOException
Validates the image without waiting to ensure load completion. Calls validate(imageFilename,null,0).

Throws:
IOException

CroftSoft Javadoc

CroftSoft Core Javadoc (2008-09-28 20:58:02)