ewe.graphics
Class AnimatedIcon

java.lang.Object
  extended byewe.fx.mImage
      extended byewe.graphics.AniImage
          extended byewe.graphics.AnimatedIcon
All Implemented Interfaces:
ByteEncodable, IImage, OnScreenImage, Runnable

public class AnimatedIcon
extends AniImage
implements Runnable


Nested Class Summary
 
Nested classes inherited from class ewe.graphics.AniImage
AniImage.ImageRefresher
 
Field Summary
protected  Hashtable images
           
protected  Vector loops
           
protected  Task loopTask
          This is the thread that is running the animation.
 boolean startOnDraw
           
 
Fields inherited from class ewe.graphics.AniImage
displayControl, limits, mosaic, refresher, relativeToOrigin
 
Fields inherited from class ewe.fx.mImage
AlwaysOnTop, backgroundColor, bitmask, CompletelyIn, drawable, drawMode, HasBorder, HasChanged, HasMoved, hotArea, hotPolygon, image, imageMayChange, InUse, IsAnimated, IsEmpty, IsInvisible, IsLocked, IsMoveable, IsNotHot, IsNotStill, IsPrepared, IsPreparing, KeepOnScreen, lastDrawn, location, mask, MouseMustBeOver, properties, RelativeToOrigin, sourceImage, sourceMask, transparentColor
 
Fields inherited from interface ewe.fx.IImage
DISABLED, OUTLINED
 
Constructor Summary
AnimatedIcon()
          Create a blank AnimatedIcon.
AnimatedIcon(ImageInfo[] images)
           
AnimatedIcon(Stream imageFile)
           
AnimatedIcon(String loopString)
           
AnimatedIcon(String loopString, Dimension size)
           
AnimatedIcon(String loopString, String prependString, Dimension size)
           
 
Method Summary
 void addImage(String name, IImage image)
          This adds an image to the internal Hashtable using with the specified name.
 void addLoopSegment(String imageName, int pauseTimeInMillis)
           
 void closing()
          This simply calls the stop() method.
 void doDraw(Graphics g, int options)
          Bottom level draw.
 void doLoop(Handle h)
          This actually does the looping of the images.
protected  IImage fetchForName(String name)
           
 void free()
          Override this to free used resources.
static IImage getAnimatedImageFromGIF(Stream imageFile)
          This checks an encoded GIF byte Stream to see if the image contains is an animated GIF or a single Image GIF.
 IImage getImage(String name)
          Get a named image from the list of images.
 void run()
          Override this to do custom animation.
 void setLoop(String loopString)
          If you call this directly to specify the loop string, then you will have had to already add images to the internal Hashtable using addImage().
 void shown()
          This simply calls the start() method.
 void start()
          By default this calls startLoop().
 Handle startLoop()
          This starts a new mThread that calls doLoop() method.
 void stop()
          Requests that the animation stop but does not free resources.
 
Methods inherited from class ewe.graphics.AniImage
animateMoveTo, canGo, change, change, change, changed, getMovedBounds, getNew, hasARefresher, isCompletelyWithin, isDraggedOver, isIn, isTouching, isWithin, move, refresh, refreshNow, resize, setLocation, translate, updated
 
Methods inherited from class ewe.fx.mImage
changeRefresher, compareTo, copyFrom, decodeBytes, draw, draw, drawBorder, drawn, encodeBytes, fixColors, freeIfNotOriginal, freeSource, getBackground, getBrokenImage, getCopy, getDefaultImage, getDim, getFullCopy, getHeight, getHotArea, getLocation, getPixels, getRefresher, getSize, getUnknownImage, getUnusedColor, getWidth, imageSet, makeOpaqueHotArea, onHotArea, refresh, scale, setHotAreaInImage, setImage, setImage, setImage, setImage, setImage, setImage, setImage, setMImage, setRefresher, toAlphaImage, toCursor, toString, usesAlpha
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode
 

Field Detail

startOnDraw

public boolean startOnDraw

loops

protected Vector loops

loopTask

protected Task loopTask
This is the thread that is running the animation.


images

protected Hashtable images
Constructor Detail

AnimatedIcon

public AnimatedIcon()
Create a blank AnimatedIcon.


AnimatedIcon

public AnimatedIcon(Stream imageFile)
             throws IllegalArgumentException

AnimatedIcon

public AnimatedIcon(ImageInfo[] images)

AnimatedIcon

public AnimatedIcon(String loopString)

AnimatedIcon

public AnimatedIcon(String loopString,
                    Dimension size)

AnimatedIcon

public AnimatedIcon(String loopString,
                    String prependString,
                    Dimension size)
Method Detail

getAnimatedImageFromGIF

public static IImage getAnimatedImageFromGIF(Stream imageFile)
                                      throws IllegalArgumentException
This checks an encoded GIF byte Stream to see if the image contains is an animated GIF or a single Image GIF. If it is animated then an AnimatedIcon is returned, otherwise an mImage is returned.

Parameters:
imageFile - The encoded GIF stored in a Stream of bytes. If you have a byte array containing the data you can use ewe.io.MemoryFile to convert it into a ewe.io.Stream by using new MemoryFile(byte[] data, int start, int length, String mode).
Throws:
IllegalArgumentException - if there is an error decoding the GIF.

setLoop

public void setLoop(String loopString)
If you call this directly to specify the loop string, then you will have had to already add images to the internal Hashtable using addImage().

Parameters:
loopString - The string in the format: "Image1|PauseTime1|Image2|PauseTime2|..."

addLoopSegment

public void addLoopSegment(String imageName,
                           int pauseTimeInMillis)

fetchForName

protected IImage fetchForName(String name)

shown

public void shown()
This simply calls the start() method.

Overrides:
shown in class AniImage

closing

public void closing()
This simply calls the stop() method.

Overrides:
closing in class AniImage

stop

public void stop()
Requests that the animation stop but does not free resources.


doLoop

public void doLoop(Handle h)
This actually does the looping of the images. You would not normally call this directly, rather you would call start() or you could create a new Thread for this class and the run() method would then call doLoop().

This loop will exit if the passed Handle has its stop() method called or if the ImageRefresher is set to null or has been garbage collected.


start

public void start()
By default this calls startLoop().


startLoop

public Handle startLoop()
This starts a new mThread that calls doLoop() method.


free

public void free()
Override this to free used resources.

Specified by:
free in interface IImage
Overrides:
free in class mImage

run

public void run()
Override this to do custom animation. Call the change() or move() methods to change/move the image and then call refresh() to update it on the screen.

Specified by:
run in interface Runnable

addImage

public void addImage(String name,
                     IImage image)
This adds an image to the internal Hashtable using with the specified name.

Parameters:
image - The image.
name - The name used as the key for the image - it does not need to be the file/resource name of the image.

getImage

public IImage getImage(String name)
Get a named image from the list of images. By default this gets the image from the Hashtable, but you can construct the image from scratch here if you want.

Parameters:
name - The key name for the image as specified in addImage().
Returns:
The image if found.

doDraw

public void doDraw(Graphics g,
                   int options)
Description copied from class: mImage
Bottom level draw. Override to change how the image is drawn. Will still allow borders to be drawn and allow invisible to have effect.

Overrides:
doDraw in class mImage