com.sun.lwuit.animations
Class Motion

java.lang.Object
  extended by com.sun.lwuit.animations.Motion

public class Motion
extends java.lang.Object

Abstracts the notion of physical motion over time from a numeric location to another. This class can be subclassed to implement any motion equation for appropriate physics effects.

This class relies on the System.currentTimeMillis() method to provide transitions between coordinates. The motion can be subclassed to provide every type of motion feel from parabolic motion to spline and linear motion. The default implementation provides a simple algorithm giving the feel of acceleration and deceleration.


Constructor Summary
protected Motion(int sourceValue, float initVelocity, float friction)
          Construct a velocity motion
protected Motion(int sourceValue, int destinationValue, int duration)
          Construct a point/destination motion
 
Method Summary
static Motion createFrictionMotion(int sourceValue, int maxValue, float initVelocity, float friction)
          Creates a friction motion starting from source with initial speed and the friction
static Motion createLinearMotion(int sourceValue, int destinationValue, int duration)
          Creates a linear motion starting from source value all the way to destination value
static Motion createSplineMotion(int sourceValue, int destinationValue, int duration)
          Creates a spline motion starting from source value all the way to destination value
 long getCurrentMotionTime()
          Returns the current time within the motion relative to start time
 int getDestinationValue()
          The number to which we will reach when the motion is finished
 int getDuration()
          Returns the animation duration
 int getSourceValue()
          The number from which we are starting (usually indicating animation start position)
protected  long getStartTime()
          The value of System.currentTimemillis() when motion was started
 int getValue()
          Returns the value for the motion for the current clock time.
 boolean isFinished()
          Returns true if the motion has run its course and has finished meaning the current time is greater than startTime + duration.
 void setCurrentMotionTime(long currentMotionTime)
          Allows overriding the getCurrentMotionTime method value with a manual value to provide full developer control over animation speed/position.
 void setSourceValue(int sourceValue)
          The number from which we are starting (usually indicating animation start position)
 void setStartTime(long startTime)
          Sets the start time of the motion
 void start()
          Sets the start time to the current time
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Motion

protected Motion(int sourceValue,
                 int destinationValue,
                 int duration)
Construct a point/destination motion

Parameters:
sourceValue - starting value
destinationValue - destination value
duration - motion duration

Motion

protected Motion(int sourceValue,
                 float initVelocity,
                 float friction)
Construct a velocity motion

Parameters:
sourceValue - starting value
initVelocity - initial velocity
friction - degree of friction
Method Detail

createLinearMotion

public static Motion createLinearMotion(int sourceValue,
                                        int destinationValue,
                                        int duration)
Creates a linear motion starting from source value all the way to destination value

Parameters:
sourceValue - the number from which we are starting (usually indicating animation start position)
destinationValue - the number to which we are heading (usually indicating animation destination)
duration - the length in milliseconds of the motion (time it takes to get from sourceValue to destinationValue)
Returns:
new motion object

createSplineMotion

public static Motion createSplineMotion(int sourceValue,
                                        int destinationValue,
                                        int duration)
Creates a spline motion starting from source value all the way to destination value

Parameters:
sourceValue - the number from which we are starting (usually indicating animation start position)
destinationValue - the number to which we are heading (usually indicating animation destination)
duration - the length in milliseconds of the motion (time it takes to get from sourceValue to destinationValue)
Returns:
new motion object

createFrictionMotion

public static Motion createFrictionMotion(int sourceValue,
                                          int maxValue,
                                          float initVelocity,
                                          float friction)
Creates a friction motion starting from source with initial speed and the friction

Parameters:
sourceValue - the number from which we are starting (usually indicating animation start position)
maxValue - the maximum value for the friction
initVelocity - the starting velocity
friction - the motion friction
Returns:
new motion object

start

public void start()
Sets the start time to the current time


getCurrentMotionTime

public long getCurrentMotionTime()
Returns the current time within the motion relative to start time

Returns:
long value representing System.currentTimeMillis() - startTime

setCurrentMotionTime

public void setCurrentMotionTime(long currentMotionTime)
Allows overriding the getCurrentMotionTime method value with a manual value to provide full developer control over animation speed/position.

Parameters:
currentMotionTime - the time in milliseconds for the motion.

setStartTime

public void setStartTime(long startTime)
Sets the start time of the motion

Parameters:
startTime - the starting time

isFinished

public boolean isFinished()
Returns true if the motion has run its course and has finished meaning the current time is greater than startTime + duration.

Returns:
true if System.currentTimeMillis() > duration + startTime or the last returned value is the destination value

getValue

public int getValue()
Returns the value for the motion for the current clock time. The value is dependent on the Motion type.

Returns:
a value that is relative to the source value

getSourceValue

public int getSourceValue()
The number from which we are starting (usually indicating animation start position)

Returns:
the source value

getDestinationValue

public int getDestinationValue()
The number to which we will reach when the motion is finished

Returns:
the source value

setSourceValue

public void setSourceValue(int sourceValue)
The number from which we are starting (usually indicating animation start position)

Parameters:
sourceValue - the source value

getStartTime

protected long getStartTime()
The value of System.currentTimemillis() when motion was started

Returns:
the start time

getDuration

public int getDuration()
Returns the animation duration

Returns:
animation duration in milliseconds