jview
Class BlinkingImage

java.lang.Object
  extended by jview.BlinkingImage
All Implemented Interfaces:
ActionListener, RenderedImage, EventListener

public class BlinkingImage
extends Object
implements ActionListener, RenderedImage

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 BlinkingImage.Test
          For testing.
 
Field Summary
private  boolean afteroff
          If true we draw the off image after animation, otherwise on.
private static 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 static 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  BufferedImage off
          The off-image.
private  Point offset
          The offset where to draw the blinking image.
private  BufferedImage 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.
 
Constructor Summary
BlinkingImage(Image high, Image low, Component observer)
          Creates a new blinking image instance.
BlinkingImage(Image high, Image low, int delay, Component observer)
          Creates a new blinking image instance.
 
Method Summary
 void actionPerformed(ActionEvent ae)
          Does the blinking.
 WritableRaster copyData(WritableRaster raster)
           
private static Timer createTimer()
          For all blinking images, we have a single timer.
private  BufferedImage getActualImage()
          Returns the actual image.
 ColorModel getColorModel()
           
 Raster getData()
           
 Raster getData(Rectangle rect)
           
 int getHeight()
           
 int getMinTileX()
           
 int getMinTileY()
           
 int getMinX()
           
 int getMinY()
           
 int getNumXTiles()
           
 int getNumYTiles()
           
 Object getProperty(String name)
           
 String[] getPropertyNames()
           
 SampleModel getSampleModel()
           
 Vector getSources()
           
 Raster getTile(int tileX, int tileY)
           
 int getTileGridXOffset()
           
 int getTileGridYOffset()
           
 int getTileHeight()
           
 int getTileWidth()
           
 Point getUpperLeftCorner()
          Returns the offset.
 int getWidth()
           
 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.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 BufferedImage on
The on-image.


off

private BufferedImage 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 static Timer flash
The timer used to produce action events for the blinking.


count

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


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.

Constructor Detail

BlinkingImage

public BlinkingImage(Image high,
                     Image low,
                     Component observer)
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.

BlinkingImage

public BlinkingImage(Image high,
                     Image low,
                     int delay,
                     Component observer)
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

createTimer

private static Timer createTimer()
For all blinking images, we have a single timer. This timer subclasses the standard swing timer in a way that it also records its invokation count.


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

copyData

public WritableRaster copyData(WritableRaster raster)
Specified by:
copyData in interface RenderedImage

getColorModel

public ColorModel getColorModel()
Specified by:
getColorModel in interface RenderedImage

getData

public Raster getData()
Specified by:
getData in interface RenderedImage

getData

public Raster getData(Rectangle rect)
Specified by:
getData in interface RenderedImage

getHeight

public int getHeight()
Specified by:
getHeight in interface RenderedImage

getMinTileX

public int getMinTileX()
Specified by:
getMinTileX in interface RenderedImage

getMinTileY

public int getMinTileY()
Specified by:
getMinTileY in interface RenderedImage

getMinX

public int getMinX()
Specified by:
getMinX in interface RenderedImage

getMinY

public int getMinY()
Specified by:
getMinY in interface RenderedImage

getNumXTiles

public int getNumXTiles()
Specified by:
getNumXTiles in interface RenderedImage

getNumYTiles

public int getNumYTiles()
Specified by:
getNumYTiles in interface RenderedImage

getProperty

public Object getProperty(String name)
Specified by:
getProperty in interface RenderedImage

getPropertyNames

public String[] getPropertyNames()
Specified by:
getPropertyNames in interface RenderedImage

getSampleModel

public SampleModel getSampleModel()
Specified by:
getSampleModel in interface RenderedImage

getSources

public Vector getSources()
Specified by:
getSources in interface RenderedImage

getTile

public Raster getTile(int tileX,
                      int tileY)
Specified by:
getTile in interface RenderedImage

getTileGridXOffset

public int getTileGridXOffset()
Specified by:
getTileGridXOffset in interface RenderedImage

getTileGridYOffset

public int getTileGridYOffset()
Specified by:
getTileGridYOffset in interface RenderedImage

getTileHeight

public int getTileHeight()
Specified by:
getTileHeight in interface RenderedImage

getTileWidth

public int getTileWidth()
Specified by:
getTileWidth in interface RenderedImage

getWidth

public int getWidth()
Specified by:
getWidth in interface RenderedImage

getActualImage

private BufferedImage getActualImage()
Returns the actual image.