nu.dll.mm
Class FileImageLoader

java.lang.Object
  |
  +--nu.dll.mm.FileImageLoader
All Implemented Interfaces:
ImageLoader, java.awt.image.ImageObserver

public class FileImageLoader
extends java.lang.Object
implements ImageLoader, java.awt.image.ImageObserver

Class for loading and storing images available either through files, InputStreams or class loader input streams. See loadImage(String, String) method for more details. It also keeps an internal mapping of the generated Image objects and their "labels", so that you can store several images in this class in a convenient way. This class is, in contrary to the java.awt.Toolkit.createImage() and their likes, synchronous. This means that the loadImage() methods does not return until the image has been fully loaded (or the loading failed for some reason, in which an ImageLoaderException or IOException might be thrown).

See Also:
loadImage(InputStream, String), loadImage(String, String)

Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
FileImageLoader(java.awt.Toolkit toolkit)
          Costructs a new FileImageLoader object which will use the given java.awt.Toolkit object to create the images.
 
Method Summary
 java.awt.Image getImage(java.lang.String name)
          Returns a previously loaded image by its key label.
 boolean imageUpdate(java.awt.Image image, int infoflags, int x, int y, int width, int height)
          This method is an implementation detail.
 java.awt.Image loadImage(java.io.InputStream stream, java.lang.String name)
          Synchronously loads an image from the supplied input stream, then returnes the fully loaded Image object (or null if the loading failed, but if there was an I/O error reading from the stream, you will probably get an IOException instead).
 java.awt.Image loadImage(java.lang.String file, java.lang.String name)
          Attempts to locate an image given its file name in the following order and presedense (sp?)
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

FileImageLoader

public FileImageLoader(java.awt.Toolkit toolkit)
Costructs a new FileImageLoader object which will use the given java.awt.Toolkit object to create the images.
Method Detail

loadImage

public java.awt.Image loadImage(java.io.InputStream stream,
                                java.lang.String name)
                         throws java.io.IOException
Synchronously loads an image from the supplied input stream, then returnes the fully loaded Image object (or null if the loading failed, but if there was an I/O error reading from the stream, you will probably get an IOException instead). It should be noted that the entire stream is read to memory before the data is passed onto the AWT subsystem to generate the Image object.

loadImage

public java.awt.Image loadImage(java.lang.String file,
                                java.lang.String name)
                         throws java.io.IOException
Attempts to locate an image given its file name in the following order and presedense (sp?):
  1. Prepend "images/", then pass it on to the ClassLoader's getResourceAsStream() method. See ClassLoader.getResource(String).
  2. If that fails, check for the existance of the file in the "images" directory of the CWD.
  3. If that fails, check for the existance of the file in the CWD.
  4. If that fails, a ImageLoaderException will be thrown (XXX: new exception/IOException?)
Specified by:
loadImage in interface ImageLoader
Following copied from interface: nu.dll.mm.ImageLoader
Throws:
java.io.IOException - if an I/O error occurs while loading the image

getImage

public java.awt.Image getImage(java.lang.String name)
Returns a previously loaded image by its key label. If an image (any image) is concurrently being loaded into this object, this method will block until it is done loading.
Specified by:
getImage in interface ImageLoader
Following copied from interface: nu.dll.mm.ImageLoader
Parameters:
name - The label which the image has been given in the loadImage() call

imageUpdate

public boolean imageUpdate(java.awt.Image image,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
This method is an implementation detail. Do not call.
Specified by:
imageUpdate in interface java.awt.image.ImageObserver