com.miginfocom.ashape.animation.animations
Class AbstractAnimation

java.lang.Object
  extended by com.miginfocom.ashape.animation.animations.AbstractAnimation
All Implemented Interfaces:
Animation, java.io.Serializable
Direct Known Subclasses:
AbsRectAnimation, AtValueAnimation, BasicStrokeAnimation, ColorAnimation, ImageAnimation, NumberAnimation, ShapeGradientPaintAnimation, TexturePaintAnimation

public abstract class AbstractAnimation
extends java.lang.Object
implements Animation

Animation with optional creation and handling of cached objects.
Subclass to make your own Animation type.

See Also:
Serialized Form

Constructor Summary
protected AbstractAnimation(int frameCount, boolean cloneCached)
          Constructor.
 
Method Summary
protected  void createCache(boolean inNewThread)
          Creates the cache array and store it in cFrames.
protected  void createCacheImpl()
          The implementation of createCache(boolean) that does the actual work of creating the cache.
protected abstract  java.lang.Object createObject(float d)
          Returns a newly created object that complies to the same rules as getObject(float).
 boolean equals(java.lang.Object o)
           
 int getFrameCount()
          Returns the optimum frame count.
 java.lang.Object getObject(float d)
          Returns an object that represents the animation at point f.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

AbstractAnimation

protected AbstractAnimation(int frameCount,
                            boolean cloneCached)
Constructor. Doesn't create the cache (if frameCount > 0) until needed.

Parameters:
frameCount - The number of frames to create. 0 creates no cache at all and all object are created when they are asked for.
call createCache(boolean) with true as the last row in sub-constructor to create the cache in a background thread.
cloneCached - If the returned values (if cached) should first be cloned.
Method Detail

getObject

public java.lang.Object getObject(float d)
Description copied from interface: Animation
Returns an object that represents the animation at point f. f should be normally be within 0.0f and 1.0f (inclusive).

Specified by:
getObject in interface Animation
Parameters:
d - 0.0f to 1.0f. 0.0f is the first "frame" and 1.0f is the last.
Returns:
An object that represents the animation at point f. Object should be treated as read-only unless specified othervise by sub classes.

createCache

protected void createCache(boolean inNewThread)
Creates the cache array and store it in cFrames. Calls createObject(float) for every frame to cache.

Parameters:
inNewThread - If the creation should be made in a background thread. If so, the method will return BEFORE the cache has been created! The priority is set to Thread.MIN_PRIORITY.
Note that the SecurityManager has to allow access to theads for the method to start a new thread. Otherwise there will be an automatic fallback to non-threaded cache creation.

createCacheImpl

protected void createCacheImpl()
The implementation of createCache(boolean) that does the actual work of creating the cache.


createObject

protected abstract java.lang.Object createObject(float d)
Returns a newly created object that complies to the same rules as getObject(float). For subclasses to implement.

Parameters:
d - 0.0 to 1.0 0.0 is the first Object/frame and 1.0 is the last.
Returns:
A newly created object that complies to the same rules as getObject(float).

getFrameCount

public int getFrameCount()
Description copied from interface: Animation
Returns the optimum frame count. If the animation is "analog", so to say, return Integer.MAX_VALUE. This max value must be handeled by subclasses so they can't just allocate an array of this size.
Integer.MAX_VALUE should always defer any caching of the objects for instance.

Specified by:
getFrameCount in interface Animation
Returns:
The optimum frame count. Integer.MAX_VALUE == unlimited.

equals

public boolean equals(java.lang.Object o)
Overrides:
equals in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.