org.robokind.api.common.playable
Class AbstractPlayable

java.lang.Object
  extended by org.robokind.api.common.playable.AbstractPlayable
All Implemented Interfaces:
Playable

public abstract class AbstractPlayable
extends Object
implements Playable

A basic implementation of Playable. Useful as a base class.

Author:
Matthew Stevenson

Field Summary
protected  Long myElapsedPauseTime
          The total elapsed time while paused.
protected  Long myPauseTime
          The time given when last being paused.
protected  List<PlayableListener> myPlayableListeners
          Listeners for PlayState changes
protected  PlayState myPlayState
          The current PlayState.
protected  Long myResumeTime
          The time given when last being resumed.
protected  Long myStartTime
          The time given when starting.
protected  Long myStopTime
          The time given when last being stopped.
 
Constructor Summary
AbstractPlayable()
          Creates a new Playable in a pending state.
 
Method Summary
 void addPlayableListener(PlayableListener listener)
          Adds a PlayableListener to be notified when the PlayState changes.
protected  void afterComplete(long time)
           
 boolean complete(long time)
          Stops the Playable, marking it complete.
protected  void firePlayStateChanged(PlayState prev, PlayState state, long time)
          Notifies listeners of a change in PlayState.
 Long getElapsedPauseTime(long time)
          Returns the elapsed time between the last pause time and the given time.
 Long getElapsedPlayTime(long time)
          Returns the elapsed time between the start time and the given time.
 Long getPauseTime()
          Returns the time given when the Playable was last paused.
 PlayState getPlayState()
          Return the current PlayState of the Playable.
 Long getResumeTime()
          Returns the time given when the Playable was last resumed.
 Long getStartTime()
          Returns the time given when the Playable was started.
 Long getStopTime()
          Returns the time given when the Playable was last stopped.
protected abstract  boolean onComplete(long time)
          Called when the Playable is completed
protected abstract  boolean onPause(long time)
          Called when the Playable is paused
protected abstract  boolean onResume(long time)
          Called when the Playable is resumed
protected abstract  boolean onStart(long time)
          Called when the Playable is started.
protected abstract  boolean onStop(long time)
          Called when the Playable is stopped
 boolean pause(long time)
          Pauses the Playable in its current state.
 void removePlayableListener(PlayableListener listener)
          Removes a PlayableListener from being notified
 boolean resume(long time)
          Resumes a paused Playable.
 boolean start(long time)
          Starts the Playable from its initial state.
 boolean stop(long time)
          Stops a Playable, returning to the initial state.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

myPlayState

protected PlayState myPlayState
The current PlayState.


myStartTime

protected Long myStartTime
The time given when starting.


myPauseTime

protected Long myPauseTime
The time given when last being paused.


myResumeTime

protected Long myResumeTime
The time given when last being resumed.


myStopTime

protected Long myStopTime
The time given when last being stopped.


myPlayableListeners

protected List<PlayableListener> myPlayableListeners
Listeners for PlayState changes


myElapsedPauseTime

protected Long myElapsedPauseTime
The total elapsed time while paused.

Constructor Detail

AbstractPlayable

public AbstractPlayable()
Creates a new Playable in a pending state.

Method Detail

addPlayableListener

public void addPlayableListener(PlayableListener listener)
Description copied from interface: Playable
Adds a PlayableListener to be notified when the PlayState changes.

Specified by:
addPlayableListener in interface Playable
Parameters:
listener - PlayableListener to be added

removePlayableListener

public void removePlayableListener(PlayableListener listener)
Description copied from interface: Playable
Removes a PlayableListener from being notified

Specified by:
removePlayableListener in interface Playable
Parameters:
listener - PlayableListener to remove

getPlayState

public PlayState getPlayState()
Description copied from interface: Playable
Return the current PlayState of the Playable.

Specified by:
getPlayState in interface Playable
Returns:
the current PlayState of the Playable

onStart

protected abstract boolean onStart(long time)
Called when the Playable is started.

Parameters:
time - time the Playable is started, usually current system time UTC
Returns:
true if start is successful, false to cancel

onPause

protected abstract boolean onPause(long time)
Called when the Playable is paused

Parameters:
time - time the Playable is paused, usually current system time UTC
Returns:
true if pause is successful, false to cancel

onResume

protected abstract boolean onResume(long time)
Called when the Playable is resumed

Parameters:
time - time the Playable is resumed, usually current system time UTC
Returns:
true if resume is successful, false to cancel

onStop

protected abstract boolean onStop(long time)
Called when the Playable is stopped

Parameters:
time - time the Playable is stopped, usually current system time UTC
Returns:
true if stop is successful, false to cancel

onComplete

protected abstract boolean onComplete(long time)
Called when the Playable is completed

Parameters:
time - time the Playable is completed, usually current system time UTC
Returns:
true if completion is successful, false to cancel

start

public boolean start(long time)
Description copied from interface: Playable
Starts the Playable from its initial state. If successful, the resulting PlayState is RUNNING.

Specified by:
start in interface Playable
Parameters:
time - when the Playable is started (used to synchronize actions) the time is usually the current system time UTC.
Returns:
true if successful

pause

public boolean pause(long time)
Description copied from interface: Playable
Pauses the Playable in its current state. If successful, the resulting PlayState is PAUSED.

Specified by:
pause in interface Playable
Parameters:
time - when the Playable is paused (used to synchronize actions)
Returns:
true if successful

complete

public boolean complete(long time)
Description copied from interface: Playable
Stops the Playable, marking it complete. If successful, the resulting PlayState is COMPLETED.

Specified by:
complete in interface Playable
Parameters:
time - when the Playable is complete (used to synchronize actions)
Returns:
true if successful

afterComplete

protected void afterComplete(long time)

resume

public boolean resume(long time)
Description copied from interface: Playable
Resumes a paused Playable. If successful, the resulting PlayState is RUNNING.

Specified by:
resume in interface Playable
Parameters:
time - when the Playable is resumed (used to synchronize actions)
Returns:
true if successful

stop

public boolean stop(long time)
Description copied from interface: Playable
Stops a Playable, returning to the initial state. If successful, the resulting PlayState is STOPPED.

Specified by:
stop in interface Playable
Parameters:
time - when the Playable is stopped (used to synchronize actions)
Returns:
true if successful

getStartTime

public Long getStartTime()
Description copied from interface: Playable
Returns the time given when the Playable was started. Returns null if the Playable has not been started.

Specified by:
getStartTime in interface Playable
Returns:
the time given when the Playable was started. Returns null if the Playable has not been started

getPauseTime

public Long getPauseTime()
Description copied from interface: Playable
Returns the time given when the Playable was last paused. Returns null if the Playable has not been paused.

Specified by:
getPauseTime in interface Playable
Returns:
the time given when the Playable was last paused. Returns null if the Playable has not been paused

getResumeTime

public Long getResumeTime()
Description copied from interface: Playable
Returns the time given when the Playable was last resumed. Returns null if the Playable has not been resumed.

Specified by:
getResumeTime in interface Playable
Returns:
the time given when the Playable was last resumed. Returns null if the Playable has not been resumed

getStopTime

public Long getStopTime()
Description copied from interface: Playable
Returns the time given when the Playable was last stopped. Returns null if the Playable has not been stopped.

Specified by:
getStopTime in interface Playable
Returns:
the time given when the Playable was last stopped. Returns null if the Playable has not been stopped

getElapsedPlayTime

public Long getElapsedPlayTime(long time)
Description copied from interface: Playable
Returns the elapsed time between the start time and the given time.

Specified by:
getElapsedPlayTime in interface Playable
Parameters:
time - the time to check
Returns:
the elapsed time between the start time and the given time

getElapsedPauseTime

public Long getElapsedPauseTime(long time)
Description copied from interface: Playable
Returns the elapsed time between the last pause time and the given time.

Specified by:
getElapsedPauseTime in interface Playable
Parameters:
time - the time to check
Returns:
the elapsed time between the last pause time and the given time

firePlayStateChanged

protected void firePlayStateChanged(PlayState prev,
                                    PlayState state,
                                    long time)
Notifies listeners of a change in PlayState.

Parameters:
prev - previous PlayState
state - new PlayState
time - PlayState change time


Copyright © 2011. All Rights Reserved.