org.formaria.swing.animation
Class Animation

java.lang.Object
  extended by org.formaria.swing.animation.Animation
All Implemented Interfaces:
java.awt.image.ImageObserver, java.lang.Runnable

public class Animation
extends java.lang.Object
implements java.lang.Runnable, java.awt.image.ImageObserver

"Mix-in" Animation Support. This mix-in will draw on the owner's surface at specified intervals. The owner must specify where the image is to be drawn and then this class will load and render the image. Where multiple images are available an animation will result.

Copyright (c) Formaria Ltd., 2008, This software is licensed under the GNU Public License (GPL), please see license.txt for more details. If you make commercial use of this software you must purchase a commercial license from Formaria.

$Revision: 1.5 $


Field Summary
protected  Project currentProject
          The owner project and the context in which this object operates.
 
Fields inherited from interface java.awt.image.ImageObserver
ABORT, ALLBITS, ERROR, FRAMEBITS, HEIGHT, PROPERTIES, SOMEBITS, WIDTH
 
Constructor Summary
Animation()
          Create a new animation
 
Method Summary
 void add(int index, java.lang.String fileName)
          Adds a picture to the current animation.
 void add(int index, java.lang.String fileName, boolean fetchNow)
          Adds a picture to the current animation.
 void displayImage(java.awt.Graphics g)
          Draws the image at an offset of 0, 0.
 void displayImage(java.awt.Graphics g, int xOff, int yOff)
          Draw the current image at the specified offsets.
 void first()
          Sets the image index to the first image.
 int getIncrement()
          Gets the interval between images in the animation.
 int getIndex()
          Get the current image index
 int getNumImages()
          Get the number of images in this animation
 void imageUpdate()
          Update the image/component
 boolean imageUpdate(java.awt.Image img, int infoflags, int x, int y, int width, int height)
          This method is called when information about an image which was previously requested using an asynchronous interface becomes available.
 void last()
          Sets the image index to the last image.
 void next()
          Sets the image index to the next image.
 void paintComponent(java.awt.Graphics g)
          Draws any images on the specified graphics context.
 void prev()
          Sets the image index to the prev image.
 void purge()
          Removes all images from the current animation.
 void remove(int index)
          Removes the specified image from the list of images.
 void run()
          Functions required for multi-threading.
 void setIncrement(int inc)
          Sets the interval between images in the animation.
 void setIndex(int newPos)
          Sets the index of the image to display.
 void setSleepTime(int st)
          Sets the amount of time to wait before refreshing the image.
 void setValue(int index, java.lang.String fileName)
          Sets the image at the specified index.
 void startAnimation()
          Starts the animation
 void stopAnimation()
          Stops the animation.
 void update()
          Causes the animation to repaint itself.
 void update(java.awt.Graphics g)
          No need to clear anything; just paint.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

currentProject

protected Project currentProject
The owner project and the context in which this object operates.

Constructor Detail

Animation

public Animation()
Create a new animation

Method Detail

setSleepTime

public void setSleepTime(int st)
Sets the amount of time to wait before refreshing the image. A minimum of 100 milliseconds is enforced.

Parameters:
st - the time to sleep.

paintComponent

public void paintComponent(java.awt.Graphics g)
Draws any images on the specified graphics context.

Parameters:
g - the graphics context.

displayImage

public void displayImage(java.awt.Graphics g)
Draws the image at an offset of 0, 0.

Parameters:
g - the graphics context.

displayImage

public void displayImage(java.awt.Graphics g,
                         int xOff,
                         int yOff)
Draw the current image at the specified offsets.

Parameters:
g - the graphics context.
xOff - the x offset,
yOff - the y offset.

imageUpdate

public boolean imageUpdate(java.awt.Image img,
                           int infoflags,
                           int x,
                           int y,
                           int width,
                           int height)
This method is called when information about an image which was previously requested using an asynchronous interface becomes available. Asynchronous interfaces are method calls such as getWidth(ImageObserver) and drawImage(img, x, y, ImageObserver) which take an ImageObserver object as an argument. Those methods register the caller as interested either in information about the overall image itself (in the case of getWidth(ImageObserver)) or about an output version of an image (in the case of the drawImage(img, x, y, [w, h,] ImageObserver) call).

This method should return true if further updates are needed or false if the required information has been acquired. The image which was being tracked is passed in using the img argument. Various constants are combined to form the infoflags argument which indicates what information about the image is now available. The interpretation of the x, y, width, and height arguments depends on the contents of the infoflags argument.

The infoflags argument should be the bitwise inclusive OR of the following flags: WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT.

Specified by:
imageUpdate in interface java.awt.image.ImageObserver
Parameters:
img - the image being observed.
infoflags - the bitwise inclusive OR of the following flags: WIDTH, HEIGHT, PROPERTIES, SOMEBITS, FRAMEBITS, ALLBITS, ERROR, ABORT.
x - the x coordinate.
y - the y coordinate.
width - the width.
height - the height.
Returns:
false if the infoflags indicate that the image is completely loaded; true otherwise.
See Also:
ImageObserver.WIDTH, ImageObserver.HEIGHT, ImageObserver.PROPERTIES, ImageObserver.SOMEBITS, ImageObserver.FRAMEBITS, ImageObserver.ALLBITS, ImageObserver.ERROR, ImageObserver.ABORT, Image.getWidth(java.awt.image.ImageObserver), Image.getHeight(java.awt.image.ImageObserver), Graphics.drawImage(java.awt.Image, int, int, java.awt.image.ImageObserver)

run

public void run()
Functions required for multi-threading. Loads the image(s) and animates if more than one image is loaded.

Specified by:
run in interface java.lang.Runnable

add

public void add(int index,
                java.lang.String fileName)
Adds a picture to the current animation. Fetches the image immediately

Parameters:
index - the position at which the image is to be inserted
fileName - the name of the file to display.

add

public void add(int index,
                java.lang.String fileName,
                boolean fetchNow)
Adds a picture to the current animation.

Parameters:
index - the position at which the image is to be inserted
fileName - the name of the file to display.
fetchNow - get teh image now or wait till more images are added

first

public void first()
Sets the image index to the first image.


prev

public void prev()
Sets the image index to the prev image.


next

public void next()
Sets the image index to the next image.


last

public void last()
Sets the image index to the last image.


remove

public void remove(int index)
Removes the specified image from the list of images. The index is forced to be in the range of valid images and if no images exist then no action is taken.

Parameters:
index - the image index

setIncrement

public void setIncrement(int inc)
Sets the interval between images in the animation.

Parameters:
inc - the time in milliseconds between images.

getIncrement

public int getIncrement()
Gets the interval between images in the animation.

Returns:
the time in milliseconds between images.

setIndex

public void setIndex(int newPos)
Sets the index of the image to display. The index is forced to be in the range of valid images and if no images exist then no action is taken.

Parameters:
newPos - the index of the image.

setValue

public void setValue(int index,
                     java.lang.String fileName)
Sets the image at the specified index. The index is forced to be in the range of valid images and if no images exist then no action is taken.

Parameters:
index - the number of the image to be changed
fileName - the name of the new image.

getNumImages

public int getNumImages()
Get the number of images in this animation

Returns:
the number of images

getIndex

public int getIndex()
Get the current image index

Returns:
the current image index

startAnimation

public void startAnimation()
Starts the animation


stopAnimation

public void stopAnimation()
Stops the animation.


update

public void update()
Causes the animation to repaint itself.


imageUpdate

public void imageUpdate()
Update the image/component


update

public void update(java.awt.Graphics g)
No need to clear anything; just paint.

Parameters:
g - the graphics context

purge

public void purge()
Removes all images from the current animation.