jview
Class BlinkImage

java.lang.Object
  extended by java.awt.Image
      extended by jview.BlinkImage
All Implemented Interfaces:
ActionListener, EventListener

public class BlinkImage
extends Image
implements ActionListener

A blinking image is used to allow blinking of icons or other images. This class can work also on parts of a graphics object, so it is possible to differently animate compunds of the entire component.

This class expects two images, the on and off image in its constructor, along with the swing component within which this image animation should be drwan. If the user wants to specify a different location than (0,0) for the image to be displayed, call the method setUpperLeftCorner(java.awt.Point) prior to starting the blinker with startBlink(). Because this implementation uses a swing timer to perform the blinking, the time intervall between the on and off state are equal.


Nested Class Summary
static class BlinkImage.Test
          For testing.
 
Field Summary
private  boolean afteroff
          If true we draw the off image after animation, otherwise on.
private  int count
          The current invocation number in the action performed method.
private  boolean current
          True if the on image should be isplayed.
private static int DEFBLINK
          The default blinking time, in ms.
private  boolean draw
          A boolean determining whether the blinker is drawing.
private  Timer flash
          The timer used to produce action events for the blinking.
private  int frequency
          The number of action events to drop for the next frame.
private  Image off
          The off-image.
private  Point offset
          The offset where to draw the blinking image.
private  Image on
          The on-image.
private  Component pane
          The component where to get the graphics object from.
private  boolean prioron
          If true we draw the on image prior to animation start, otherwise off.
private  Dimension size
          The dimension of the images.
 
Fields inherited from class java.awt.Image
accelerationPriority, SCALE_AREA_AVERAGING, SCALE_DEFAULT, SCALE_FAST, SCALE_REPLICATE, SCALE_SMOOTH, UndefinedProperty
 
Constructor Summary
BlinkImage(Image high, Image low, Component observer, Timer time)
          Creates a new blinking image instance.
BlinkImage(Image high, Image low, int delay, Component observer, Timer time)
          Creates a new blinking image instance.
 
Method Summary
 void actionPerformed(ActionEvent ae)
          Does the blinking.
 void flush()
           
private  Image getActualImage()
          Returns the actual image.
 Graphics getGraphics()
           
 int getHeight(ImageObserver observer)
           
 Object getProperty(String name, ImageObserver observer)
           
 Image getScaledInstance(int width, int height, int hints)
           
 ImageProducer getSource()
           
 Point getUpperLeftCorner()
          Returns the offset.
 int getWidth(ImageObserver observer)
           
 boolean isActive()
          Queries this component whether it is drawing.
 void setBlinkIntervall(int delay)
          Sets the blinking intervall.
 void setPriorAndAfterState(boolean onprior, boolean offafter)
          Determines which images are to displayed prior to the animation and after stopping it.
 void setUpperLeftCorner(Point ul)
          Sets an offset where this blinking image should be displayed on the observer's graphics object.
 void startBlink()
          Starts the blinking.
 void stopBlink()
          Stops the blinking.
 
Methods inherited from class java.awt.Image
getAccelerationPriority, getCapabilities, setAccelerationPriority
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFBLINK

private static final int DEFBLINK
The default blinking time, in ms.

See Also:
Constant Field Values

on

private Image on
The on-image.


off

private Image off
The off-image. This is in most cases the background of the component.


current

private boolean current
True if the on image should be isplayed.


flash

private Timer flash
The timer used to produce action events for the blinking.


pane

private Component pane
The component where to get the graphics object from.


offset

private Point offset
The offset where to draw the blinking image. Defaults to 0,0 .


size

private Dimension size
The dimension of the images.


draw

private boolean draw
A boolean determining whether the blinker is drawing.


prioron

private boolean prioron
If true we draw the on image prior to animation start, otherwise off.


afteroff

private boolean afteroff
If true we draw the off image after animation, otherwise on.


frequency

private int frequency
The number of action events to drop for the next frame.


count

private int count
The current invocation number in the action performed method.

Constructor Detail

BlinkImage

public BlinkImage(Image high,
                  Image low,
                  Component observer,
                  Timer time)
Creates a new blinking image instance. The image does not blink until the method startBlink() is explicedly called.

Parameters:
high - The image to display in the on state or prior to start.
low - The image to display in the off state or after stop.
observer - The component whose graphics is used to draw the image.
time - The timer to allow synchronous blinking for multiple blinking images.

BlinkImage

public BlinkImage(Image high,
                  Image low,
                  int delay,
                  Component observer,
                  Timer time)
Creates a new blinking image instance. The delay time between on and off states is explicetly given and matched to the timer's delay. The image does not blink until the method startBlink() is explicedly called.

Parameters:
high - The image to display in the on state or prior to start.
low - The image to display in the off state or after stop.
observer - The component whose graphics is used to draw the image.
delay - The target blinking delay. If not a straight multiple of the timer's delay, round to closest multiple.
time - The timer to allow synchronous blinking for multiple blinking images.
Method Detail

setPriorAndAfterState

public void setPriorAndAfterState(boolean onprior,
                                  boolean offafter)
Determines which images are to displayed prior to the animation and after stopping it. Per default, the on image is displayed before start and the off after stopping.

Parameters:
onprior - If false, use the off image before animation
offafter - If false, use the on image after animation.

setUpperLeftCorner

public void setUpperLeftCorner(Point ul)
Sets an offset where this blinking image should be displayed on the observer's graphics object.


getUpperLeftCorner

public Point getUpperLeftCorner()
Returns the offset.


setBlinkIntervall

public void setBlinkIntervall(int delay)
Sets the blinking intervall.


startBlink

public void startBlink()
Starts the blinking.


stopBlink

public void stopBlink()
Stops the blinking.


isActive

public boolean isActive()
Queries this component whether it is drawing.


actionPerformed

public void actionPerformed(ActionEvent ae)
Does the blinking.

Specified by:
actionPerformed in interface ActionListener

flush

public void flush()
Overrides:
flush in class Image

getGraphics

public Graphics getGraphics()
Specified by:
getGraphics in class Image

getHeight

public int getHeight(ImageObserver observer)
Specified by:
getHeight in class Image

getProperty

public Object getProperty(String name,
                          ImageObserver observer)
Specified by:
getProperty in class Image

getScaledInstance

public Image getScaledInstance(int width,
                               int height,
                               int hints)
Overrides:
getScaledInstance in class Image

getSource

public ImageProducer getSource()
Specified by:
getSource in class Image

getWidth

public int getWidth(ImageObserver observer)
Specified by:
getWidth in class Image

getActualImage

private Image getActualImage()
Returns the actual image.