com.croftsoft.core.animation.icon
Class ResourceImageIcon

java.lang.Object
  extended by com.croftsoft.core.animation.icon.ResourceImageIcon
All Implemented Interfaces:
Icon

public final class ResourceImageIcon
extends Object
implements Icon

When contents lost, reloads the VolatileImage from the ClassLoader.

This class only works with opaque (non-transparent) images.

Example code:

 Icon  heroIcon = new ResourceImageIcon (
   HERO_IMAGE_FILENAME,
   getClass ( ).getClassLoader ( ),
   new Dimension (
     ( int ) scalingRatio * HERO_IMAGE_WIDTH,
     ( int ) scalingRatio * HERO_IMAGE_HEIGHT ),
   animatedComponent );
 

Since:
2003-02-18
Version:
2003-02-18
See Also:
VolatileImage
Author:
David Wallace Croft

Constructor Summary
ResourceImageIcon(String imageFilename)
           
ResourceImageIcon(String imageFilename, ClassLoader classLoader, Dimension scaleDimension, Component component)
          Main constructor.
 
Method Summary
 int getIconHeight()
           
 int getIconWidth()
           
 void paintIcon(Component component, Graphics graphics, int x, int y)
          If VolatileImage contents are lost, calls prepareVolatileImage().
 void prepareVolatileImage(Component component)
          Loads the VolatileImage.
 void setHeight(int height)
           
 void setSize(Dimension size)
           
 void setWidth(int width)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ResourceImageIcon

public ResourceImageIcon(String imageFilename,
                         ClassLoader classLoader,
                         Dimension scaleDimension,
                         Component component)
Main constructor.

Parameters:
imageFilename - The image path and filename, usually pulled from a JAR.
classLoader - The ClassLoader to use to load the image as a resource file.
scaleDimension - If not null, used to pre-scale the VolatileImage.
component - If not null, prepareVolatileImage() is called during construction.

ResourceImageIcon

public ResourceImageIcon(String imageFilename)
Method Detail

getIconWidth

public int getIconWidth()
Specified by:
getIconWidth in interface Icon

getIconHeight

public int getIconHeight()
Specified by:
getIconHeight in interface Icon

paintIcon

public void paintIcon(Component component,
                      Graphics graphics,
                      int x,
                      int y)
If VolatileImage contents are lost, calls prepareVolatileImage().

Specified by:
paintIcon in interface Icon

prepareVolatileImage

public void prepareVolatileImage(Component component)
Loads the VolatileImage.

Call this method to load the image after construction but before the first call to paint(). This is useful if you cannot perform this operation when the main constructor is called because the Component is not ready at the time and you do not want to wait until the first paint() because the load may stall animation.

Example code:

 ResourceImageIcon  heroIcon = new ResourceImageIcon (
   HERO_IMAGE_FILENAME,
   getClass ( ).getClassLoader ( ),
   ( Dimension ) null, // no scaling
   ( Component ) null );

 [...wait until Component is ready...]

 heroIcon.prepareVolatileImage ( animatedComponent );
 


setWidth

public void setWidth(int width)

setHeight

public void setHeight(int height)

setSize

public void setSize(Dimension size)

CroftSoft Javadoc

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