com.miginfocom.ashape.animation
Class TimeLine

java.lang.Object
  extended by com.miginfocom.ashape.animation.TimeLine
All Implemented Interfaces:
java.io.Serializable, java.lang.Cloneable

public class TimeLine
extends java.lang.Object
implements java.lang.Cloneable, java.io.Serializable

A class to specify an optionally unlinear time line and how a number of 'ticks', usually frames, relate to that time.

See Also:
showTimelineFrame(), Serialized Form

Field Summary
protected  int duration
           
protected  Function func
           
protected  boolean isTimeBased
           
protected  int lastTick
           
static int REP_CYCLE
          Start over at beginning
static int REP_NONE
          No repeat.
static int REP_REVERSE
          Change direction at ends.
protected  int repeatCount
           
protected  int repeatType
           
protected  int tickCount
           
 
Constructor Summary
TimeLine(int duration, int tickCount)
          Constructor.
TimeLine(int duration, int tickCount, Function func, boolean isTimeBased)
          Constructor.
TimeLine(int duration, int tickCount, int repeatType, int repeatCount)
          Constructor.
TimeLine(int duration, int tickCount, int repeatType, int repeatCount, Function func, boolean isTimeBased)
          Constructor.
 
Method Summary
protected  java.lang.Object clone()
           
 boolean equals(java.lang.Object o)
           
 void freezeValues()
          Calculates all fz_XXX values.
 double getCurrentTick()
          Returns the tick for the time that is now.
 java.lang.Integer getDelayToNextTick()
          Returns the delay to the next tick.
 int getDuration()
          Returns the value sent into the constructor.
 Function getFunction()
          Returns the value sent into the constructor.
 double getLastTick()
          Returns the last tick of the time line.
 int getRepeatCount()
          Returns the value sent into the constructor.
 int getRepeatType()
          Returns the value sent into the constructor.
 int getTickCount()
          Returns the value sent into the constructor.
 boolean getTimeBased()
           
 boolean isFrozen()
          Returns if the values are currently frozen
 boolean isTimeBased()
          Returns the value sent into the constructor.
 void pause(java.lang.Double pos, java.lang.Integer dir)
          Pauses the time line.
 void play(java.lang.Double pos, java.lang.Integer dir)
          Plays the time line.
 void showTimelineFrame()
          Shows a frame with the time line graphically for debug purposes.
 void unfreezeValues()
          Unfreezes the values if freezeCount comes down to 0.
 
Methods inherited from class java.lang.Object
finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

REP_NONE

public static final int REP_NONE
No repeat.

See Also:
Constant Field Values

REP_CYCLE

public static final int REP_CYCLE
Start over at beginning

See Also:
Constant Field Values

REP_REVERSE

public static final int REP_REVERSE
Change direction at ends. One time back and forth is two repeatCounts.

See Also:
Constant Field Values

duration

protected final transient int duration

tickCount

protected final transient int tickCount

func

protected final transient Function func

repeatType

protected final transient int repeatType

repeatCount

protected final transient int repeatCount

isTimeBased

protected final transient boolean isTimeBased

lastTick

protected final transient int lastTick
Constructor Detail

TimeLine

public TimeLine(int duration,
                int tickCount)
Constructor. Forward, paused at position 0.0.

Parameters:
duration - The duration of the timeline in milliseconds
tickCount - The number of ticks between the start and end. Note that if there is a nonlinear funcktion f then the ticks won't have the same delay between them. E.g. for an acceleated time line there will be more ticks/ms at the end of the duration.

TimeLine

public TimeLine(int duration,
                int tickCount,
                Function func,
                boolean isTimeBased)
Constructor. Forward, paused at position 0.0.

Parameters:
duration - The duration of the timeline in milliseconds
tickCount - The number of ticks between the start and end. Note that if there is a nonlinear funcktion f then the ticks won't have the same delay between them. E.g. for an acceleated time line there will be more ticks/ms at the end of the duration.
func - A generic funtion that will get a value 0..1 inclusive and is expected to return a value 0..1 inclusive. Time will progress between start and end and this function will be used to pick a tick in any time in between. Can thus be used to create non-linear animations such as accelerated or retarding ones.

TimeLine

public TimeLine(int duration,
                int tickCount,
                int repeatType,
                int repeatCount)
Constructor. Forward, paused at position 0.0.

Parameters:
duration - The duration of the timeline in milliseconds
tickCount - The number of ticks between the start and end. Note that if there is a nonlinear funcktion f then the ticks won't have the same delay between them. E.g. for an acceleated time line there will be more ticks/ms at the end of the duration.
repeatType - The type of repeat. E.g. REP_CYCLE.
repeatCount - The number of repetitions. 1 will repeat the cylcle one time thus running the time line TWO times.

TimeLine

public TimeLine(int duration,
                int tickCount,
                int repeatType,
                int repeatCount,
                Function func,
                boolean isTimeBased)
Constructor. Forward, paused at position 0.0.

Parameters:
duration - The duration of the timeline in milliseconds
tickCount - The number of ticks between the start and end. Note that if there is a nonlinear funcktion f then the ticks won't have the same delay between them. E.g. for an acceleated time line there will be more ticks/ms at the end of the duration.
repeatType - The type of repeat. E.g. REP_CYCLE.
repeatCount - The number of repetitions. 1 will repeat the cylcle one time thus running the time line TWO times.
func - A generic funtion that will get a value 0..1 inclusive and is expected to return a value 0..1 inclusive. Time will progress between start and end and this function will be used to pick a tick in any time in between. Can thus be used to create non-linear animations such as accelerated or retarding ones.
isTimeBased - If true the time line will have the ticks with at a certain frequency. If false the delay between two ticks is made so that the change of the function will be the indicator instead. For instance 10 ticks for an exponentinal function the first tick might be after 30% of the time, where the value has changed 10%. If false the function MUST be solvable. See Function.isSolvable().
Method Detail

play

public void play(java.lang.Double pos,
                 java.lang.Integer dir)
Plays the time line. The values must not be frozen prior to calling this method.

Parameters:
pos - If != null the time line starts from this position. 0..1
dir - If != null the time line starts in this direction. only -1 or 1.

pause

public void pause(java.lang.Double pos,
                  java.lang.Integer dir)
Pauses the time line. The values must not be frozen prior to calling this method.

Parameters:
pos - If != null the time line pauses at this position. 0..1
dir - If != null the time line pauses in this direction. only -1 or 1.

getDelayToNextTick

public java.lang.Integer getDelayToNextTick()
Returns the delay to the next tick. Will be delay to above or below the previous tick depending on the direction (I.e. revered or not)

Returns:
The delay to the next tick or null if there are no more ticks.
See Also:
System.currentTimeMillis()

getCurrentTick

public double getCurrentTick()
Returns the tick for the time that is now. 0 or lastTick if outside time line.

Returns:
The tick for the time that is now. 0 or lastTick if outside time line. It is a double mainly for animators that are "analog" and therefore can be more precise. Round to int otherwise.
See Also:
Math.round(double)

getLastTick

public double getLastTick()
Returns the last tick of the time line. Will be 0.0 or lastTick (tickCount - 1).

Returns:
The last tick of the time line. Will be 0.0 or lastTick (tickCount - 1).

equals

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

freezeValues

public void freezeValues()
Calculates all fz_XXX values. These values should be used by the other methods. They are calculated in one method instead of in many different places so we won't have problem with the clock making a tick half way through a calulation and than another call to System.currentTimeMillis() will return a "faulty" value that is out of sync with ealier calculations. So basically no other methods sould call System.currentTimeMillis()!.
Do remember to "unfreeze" the values. There is a freezeCount counter that actually only unfreezes the values when as many calls have been made.
Calling this method when the values are already freezed will ONLY result in an increment of the freezeCount, no new values are beeing calculated. to freezeValues() as to unfreezeValues().
No frozen value are dependant on the direction of the time line.


unfreezeValues

public void unfreezeValues()
Unfreezes the values if freezeCount comes down to 0.


isFrozen

public boolean isFrozen()
Returns if the values are currently frozen

Returns:
true if the values are currently frozen

getDuration

public int getDuration()
Returns the value sent into the constructor.

Returns:
The value sent into the constructor.

getTickCount

public int getTickCount()
Returns the value sent into the constructor.

Returns:
The value sent into the constructor.

getRepeatType

public int getRepeatType()
Returns the value sent into the constructor.

Returns:
The value sent into the constructor.

getRepeatCount

public int getRepeatCount()
Returns the value sent into the constructor.

Returns:
The value sent into the constructor.

getFunction

public Function getFunction()
Returns the value sent into the constructor.

Returns:
The value sent into the constructor.

isTimeBased

public boolean isTimeBased()
Returns the value sent into the constructor.

Returns:
The value sent into the constructor.

getTimeBased

public boolean getTimeBased()

showTimelineFrame

public void showTimelineFrame()
Shows a frame with the time line graphically for debug purposes. Only works in debug release though.


clone

protected java.lang.Object clone()
Overrides:
clone in class java.lang.Object


Copyright © 2009 MiG InfoCom AB. All Rights Reserved.