com.webcab.chat.gui
Class ImageCache

java.lang.Object
  |
  +--com.webcab.chat.gui.ImageCache

public class ImageCache
extends java.lang.Object

This class encapsulates all data a java.awt.Image holds, by caching it into memory. It is an alternative to the way Images created with java.awt.Toolkit.getImage are drawn.

When an image is created with awt's methods, the bytes loaded from the specified image URL might suffer from low band width. ImageCache has a very stable loading method, which ensures no data losses occur. This prevents errors like missing chunks or mismatched colors.

Author:
WebCab Components

Constructor Summary
ImageCache(java.net.URL imageURL, java.lang.String imageFile)
          This constructor loads the image data into memory.
ImageCache(java.net.URL imageURL, java.lang.String imageFile, java.applet.Applet app)
          This constructor loads the image data into memory.
 
Method Summary
static java.awt.Image readImage(java.lang.String imageFile, java.awt.Component component)
          A static method provided by this class as a convenience.
static java.awt.Image readImage(java.net.URL imageURL, java.awt.Component component)
          A static method provided by this class as a convenience.
static java.awt.Image readImage(java.net.URL imageURL, java.lang.String imageFile, java.awt.Component component)
          A static method provided by this class as a convenience.
 java.awt.Image toImage(java.awt.Component component)
          Creates the image from memory.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageCache

public ImageCache(java.net.URL imageURL,
                  java.lang.String imageFile)
This constructor loads the image data into memory. In order to retrive the Image itself call toImage.
Parameters:
imageURL - the URL base where the image is located
imageFile - the name of the file
See Also:
toImage(java.awt.Component), ImageCache(URL, String, Applet), readImage(URL, Component)

ImageCache

public ImageCache(java.net.URL imageURL,
                  java.lang.String imageFile,
                  java.applet.Applet app)
This constructor loads the image data into memory. In order to retrive the Image itself call toImage.
Parameters:
imageURL - the URL base where the image is located
imageFile - the name of the file
app - the invoking applet, if there is one, otherwise a null pointer. This paramter is provided in order to allow a "Caching image" text be displayed in the browser's status bar.
See Also:
toImage(java.awt.Component), ImageCache(URL, String), readImage(URL, Component)
Method Detail

toImage

public java.awt.Image toImage(java.awt.Component component)
Creates the image from memory.
Parameters:
component - The ImageObserver to check if the image is ready for use.
Returns:
The created image, ready to be deployed inside the component.
See Also:
readImage(URL, Component)

readImage

public static java.awt.Image readImage(java.net.URL imageURL,
                                       java.awt.Component component)
A static method provided by this class as a convenience. The functionality is similar to that of java.awt.Toolkit.getImage, offering a more secure transfer and less data loss.
Parameters:
imageURL - the URL of the image to be loaded
component - the Component which is going to encapsulate the Image (for example a java.awt.Canvas)
Returns:
The image which gets its data from the specified resource, ready to be deployed inside the component.
See Also:
ImageCache(URL, String), readImage(String, Component), readImage(URL, String, Component)

readImage

public static java.awt.Image readImage(java.lang.String imageFile,
                                       java.awt.Component component)
A static method provided by this class as a convenience. The functionality is similar to that of java.awt.Toolkit.getImage, offering a more secure transfer and less data loss.
Parameters:
imageFile - the name of the URL where the image to be loaded is located
component - the Component which is going to encapsulate the Image (for example a java.awt.Canvas)
Returns:
The image which gets its data from the specified resource, ready to be deployed inside the component.
See Also:
ImageCache(URL, String), readImage(URL, Component), readImage(URL, String, Component)

readImage

public static java.awt.Image readImage(java.net.URL imageURL,
                                       java.lang.String imageFile,
                                       java.awt.Component component)
A static method provided by this class as a convenience. The functionality is similar to that of java.awt.Toolkit.getImage, offering a more secure transfer and less data loss.
Parameters:
imageURl - the URL base of the image location
imageFile - the name of the image
component - the Component which is going to encapsulate the Image (for example a java.awt.Canvas)
Returns:
The image which gets its data from the specified resource, ready to be deployed inside the component.
See Also:
ImageCache(URL, String), readImage(URL, Component), readImage(String, Component)