becker.robots.icons
Class AnimatedIcon

java.lang.Object
  extended by becker.robots.icons.Icon
      extended by becker.robots.icons.CompositeIcon
          extended by becker.robots.icons.AnimatedIcon
Direct Known Subclasses:
FlasherIcon

public class AnimatedIcon
extends CompositeIcon

An AnimatedIcon displays a sequence of icons, giving the appearance of movement or action. For example, an object representing a flashing light might use an AnimatedIcon with two icons -- one icon with the light on and one icon with the light off. More complicated sequences are also possible.

Author:
Byron Weber Becker

Field Summary
 
Fields inherited from class becker.robots.icons.Icon
transparent
 
Constructor Summary
AnimatedIcon(Sim owner, Icon[] icons, int millisecondsForEachIcon)
          Construct an AnimatedIcon which displays the Icons in the given array in order.
 
Method Summary
 Color getColor()
          Returns null.
 Image getImage(int width, int height, double rotation)
          Get the image for the current icon.
protected  void renderImage(Graphics2D g2, int width, int height)
          Render the image for the current icon.
 void setColor(Color c)
          Has no effect.
protected  void setCurrentImage(int imageNum)
          Set which image is currently shown.
 void start()
          Start the animation.
 void stop()
          Stop the animation.
 
Methods inherited from class becker.robots.icons.CompositeIcon
applyTransforms, componentIcon, hasChanged, markChanged, numComponents
 
Methods inherited from class becker.robots.icons.Icon
getLabel, getRotation, getSize, getTransparency, paintIcon, setLabel, setSize, setTransparency
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AnimatedIcon

public AnimatedIcon(Sim owner,
                    Icon[] icons,
                    int millisecondsForEachIcon)
Construct an AnimatedIcon which displays the Icons in the given array in order. Each icon is shown for the same amount of time.

Parameters:
owner - the Sim which will be displaying this icon.
icons - the Icons to show, in sequence.
millisecondsForEachIcon - how long to show each icon.
Method Detail

start

public void start()
Start the animation.


stop

public void stop()
Stop the animation.


setCurrentImage

protected void setCurrentImage(int imageNum)
Set which image is currently shown. For example, a subclass may want to show a particular image when the animation is stopped.

Parameters:
imageNum - The index of the image to show. 0 <= imageNum < icons.length

renderImage

protected void renderImage(Graphics2D g2,
                           int width,
                           int height)
Render the image for the current icon.

Overrides:
renderImage in class CompositeIcon
Parameters:
g2 - the graphics context where the icon should be drawn.
width - the number of pixels wide the image will be
height - the number of pixels high the image will be

getImage

public Image getImage(int width,
                      int height,
                      double rotation)
Get the image for the current icon.

Overrides:
getImage in class Icon

getColor

public Color getColor()
Returns null. To get the color of an animated icon, get the color of one of the components of the underlying composite icons:
Color c = animatedIcon.componentIcon(0).getColor();

Overrides:
getColor in class CompositeIcon
Returns:
this icon's current color.

setColor

public void setColor(Color c)
Has no effect. To set the color of an animated icon, set the color of one of the components of the underlying composite icons:
Color c = animatedIcon.componentIcon(0).setColor(newColor);

Overrides:
setColor in class CompositeIcon
Parameters:
c - The new color.