de.fhg.igd.ui
Class AnimatedIcon

java.lang.Object
  extended byjavax.swing.ImageIcon
      extended byde.fhg.igd.ui.AnimatedIcon
All Implemented Interfaces:
Accessible, Icon, Runnable, Serializable

public class AnimatedIcon
extends ImageIcon
implements Runnable

This icon uses animations to communicate its states. The states are enabled, disabled, looping, and oneshot.

Version:
"$Id: AnimatedIcon.java 1913 2007-08-08 02:41:53Z jpeters $"
Author:
Volker Roth
See Also:
Serialized Form

Nested Class Summary
 
Nested classes inherited from class javax.swing.ImageIcon
ImageIcon.AccessibleImageIcon
 
Field Summary
protected  int[] anim_
          The oneshot animation frame spec, given as a sequence of image numbers.
protected  int current_
          The current frame's number.
protected  long delay_
          The frame rate given as the number of millis between frame changes.
private  int height_
          The cached width of the image.
protected  Image[] image_
          The animation images.
protected  int off_
          The number of the image that represents disabled state.
protected  int offset_
          The direction in which the animation is looping, either backwards (-1) or forwards (1).
protected  int on_
          The number of the image that represents enabled state.
protected  JComponent parent_
          The parent component.
protected  Thread thread_
          The thread that animates this icon.
protected  int toFrame_
          The target frame number or -1 if looping.
private  int width_
          The cached width of the image.
 
Fields inherited from class javax.swing.ImageIcon
component, tracker
 
Constructor Summary
private AnimatedIcon()
          Creates an uninitialized instance.
  AnimatedIcon(String name)
          Creates an instance with the given animation.
 
Method Summary
 Object clone()
          Returns a clone of this animation.
protected  int frameNumber(int inum)
          Returns a frame number that displays the image with the given image number.
 long getDelay()
          Returns the delay time of this icon.
 int getIconHeight()
          Get the height of the Icon
 int getIconWidth()
          Get the width of the Icon
 int getImageLoadStatus()
          Returns COMPLETE.
 void init(String name)
          Initializes the animation from resource data.
protected  void loadImage(Image image)
          Load the given image.
static void main(String[] argv)
          Shows an animation.
 void run()
          The main loop of the animator thread.
 void setEnabled(boolean enable)
          Puts the icon into enabled or disabled state.
 void setLooping()
          Puts the icon into looping state.
 void setOneShot()
          Puts the icon into one shot state.
 void setParentComponent(JComponent component)
          Sets the parent component.
 void start()
          Starts the animation thread.
 boolean stepOne()
          Steps once in the direction in which we are looping and displays the next frame.
 void stop()
           
 
Methods inherited from class javax.swing.ImageIcon
getAccessibleContext, getDescription, getImage, getImageObserver, paintIcon, setDescription, setImage, setImageObserver, toString
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

current_

protected int current_
The current frame's number.


toFrame_

protected int toFrame_
The target frame number or -1 if looping.


delay_

protected long delay_
The frame rate given as the number of millis between frame changes.


anim_

protected int[] anim_
The oneshot animation frame spec, given as a sequence of image numbers. In looping state, this animation is iterated over and over again.


off_

protected int off_
The number of the image that represents disabled state.


on_

protected int on_
The number of the image that represents enabled state.


offset_

protected int offset_
The direction in which the animation is looping, either backwards (-1) or forwards (1).


image_

protected Image[] image_
The animation images.


thread_

protected Thread thread_
The thread that animates this icon.


width_

private int width_
The cached width of the image.


height_

private int height_
The cached width of the image.


parent_

protected JComponent parent_
The parent component.

Constructor Detail

AnimatedIcon

public AnimatedIcon(String name)
             throws InterruptedException,
                    IOException
Creates an instance with the given animation.

Parameters:
name - The name of the image and animation file resources.

AnimatedIcon

private AnimatedIcon()
Creates an uninitialized instance.

Method Detail

clone

public Object clone()
Returns a clone of this animation. The clone does not have a parent component, and it does not have a thread.

Returns:
The clone.

setParentComponent

public void setParentComponent(JComponent component)
Sets the parent component. The parent component is repainted whenever a new frame of the animation is shown.

Parameters:
component - The parent component.

run

public void run()
The main loop of the animator thread.

Specified by:
run in interface Runnable

start

public void start()
Starts the animation thread.


stop

public void stop()

getDelay

public long getDelay()
Returns the delay time of this icon.

Returns:
The delay time in millis.

setEnabled

public void setEnabled(boolean enable)
Puts the icon into enabled or disabled state.

Parameters:
enable - true if this icon should go to enabled state, and false if it should go to disabled state.

setLooping

public void setLooping()
Puts the icon into looping state.


setOneShot

public void setOneShot()
Puts the icon into one shot state.


stepOne

public boolean stepOne()
Steps once in the direction in which we are looping and displays the next frame.

Called by the timer thread to display the next frame of the animation.

Returns:
true if the target image was reached.

frameNumber

protected int frameNumber(int inum)
Returns a frame number that displays the image with the given image number.

Parameters:
inum - The image number of the target frame.
Returns:
The frame number of the frame that displays the image with the given image number.

init

public void init(String name)
          throws IOException,
                 InterruptedException
Initializes the animation from resource data. name denotes the path to the resource images. Image names must have the form: <name><num>.<extension> where <num> is the running number of the animation frame, and <extension> is taken from the animation definition file. Animation frame numbers must start with zero.

The animation sequence given as array of image numbers must be given as a string of space or comma separated numbers in a resource file with name <name>.anim; the first token must be the extension of the image frames, then the frame delay in milliseconds, then two numbers that define the off and on frames, followed by the complete animation sequence.

Parameters:
name - The name prefix of the images.
Throws:
IOException - if guess what.
InterruptedException - if the image loading is interrupted.

loadImage

protected void loadImage(Image image)
Load the given image. This method does nothing, all images are preloaded by this class.

Parameters:
image - The image to load; this parameter is ignored but for exception checking.
Throws:
NullPointerException - if image is null.

getIconWidth

public int getIconWidth()
Get the width of the Icon

Specified by:
getIconWidth in interface Icon

getIconHeight

public int getIconHeight()
Get the height of the Icon

Specified by:
getIconHeight in interface Icon

getImageLoadStatus

public int getImageLoadStatus()
Returns COMPLETE.


main

public static void main(String[] argv)
Shows an animation. one argument must be passed to this method: The base name of the animation. This method is interactive, the letters 'e', 'd', 'o', and 'l' can be typed (followed by a return) in order to manipulate the way the animation is presented.



Copyright © Fraunhofer Gesellschaft. All Rights Reserved.