Sharkysoft home

lava.gui
Class ImageLoader

java.lang.Object
  |
  +--lava.gui.ImageLoader

public class ImageLoader
extends java.lang.Object

Loads application images.

Details: ImageLoader loads and caches images through a ResourceLoader.

Since:
2000.02.01

Field Summary
protected  ResourceLoader rl
          Used for loading images.
 
Constructor Summary
ImageLoader(ResourceLoader rl)
          Sets ResourceLoader.
 
Method Summary
 java.awt.Image getImage(java.lang.String key)
          Loads image.
protected  java.awt.Image loadImage(java.lang.String key)
          Loads uncached image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

rl

protected final ResourceLoader rl
Used for loading images.

Details: rl is the ResourceLoader that this ImageLoader uses to convert keys into image and load the images.

Constructor Detail

ImageLoader

public ImageLoader(ResourceLoader rl)
Sets ResourceLoader.

Details: This constructor binds this new ImageLoader to the given ResourceLoader. All images loaded by this ImageLoader will come through rl.

Parameters:
rl - the ResourceLoader
Method Detail

getImage

public java.awt.Image getImage(java.lang.String key)
Loads image.

Details: getImage uses the ResourceLoader (provided in the constructor) to translate the given key (key) into an image. If the given key has already been used in a previous getImage call, then this method simply retrieves the image from the cache instead of reloading it. If the image is not in the cache, however, it is loaded through the loadImage method.

Normally, the AWT attempts to postpone image loading as late as possible. getImage circumvents this behavior by forcing the image to begin loading. getImage does not return until the image's dimensions are available through the Image's getWidth and getHeight methods. If the image cannot be loaded, getImage returns null.

Parameters:
the - key into the ResourceLoader
Returns:
the image

loadImage

protected java.awt.Image loadImage(java.lang.String key)
Loads uncached image.

Details: loadImage retrieves an image from the ResourceLoader, using the given key, but only after verifying that the key points to an actually existing resource. It then caches the image and returns it, or null if the image cannot be loaded.

This method is called by getImage. Subclasses may override this method to generate verbose information about image loading status, etc., but overriding implementations should call super.loadImage.

Parameters:
key - the key
Returns:
the image

Sharkysoft home