net.sf.fmj.ejmf.toolkit.util
Class SourcedTimer

java.lang.Object
  extended by net.sf.fmj.ejmf.toolkit.util.SourcedTimer
All Implemented Interfaces:
java.awt.event.ActionListener, java.util.EventListener

public class SourcedTimer
extends java.lang.Object
implements java.awt.event.ActionListener

The SourcedTimer class implements a timer dependent on a named source. This is a generalization of a timer simply dependent on a monotonically increasing clock. An instance of SourcedTimer creates a java.swing.Timer and becomes a listener on that timer. This timer is called the base timer. Every time the base timer fires, the SourcedTimer object asks its source what time it is and then notifies its listeners. This class is used by the TimerPlayer to track media time. From the book: Essential JMF, Gordon, Talley (ISBN 0130801046). Used with permission. see java.awt.swing.Timer see ejmf.toolkit.TimeSource see ejmf.examples.timerplayer.TimerPlayer

Version:
1.0
Author:
Rob Gordon & Steve Talley

Field Summary
protected static int _defaultGran
          How often in milliseconds the baseTimer triggers
 
Constructor Summary
SourcedTimer(TimeSource src)
          Create a SourcedTimer for the given source using default granularity.
SourcedTimer(TimeSource src, int granularity)
          Create a SourcedTimer for the given source with the specified granularity.
SourcedTimer(TimeSource src, javax.swing.Timer timer)
          Create a SourcedTimer for the given source.
 
Method Summary
 void actionPerformed(java.awt.event.ActionEvent e)
          Called in response to an ActionEvent from the associated base timer.
 void addSourcedTimerListener(SourcedTimerListener l)
          Add a listener to this object.
 long getConversionDivisor()
          A client of SourcedTimer may need to convert source timer time from raw units to some other units for display purposes.
 void start()
          Start the timer.
 void stop()
          Stop the timer.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

_defaultGran

protected static int _defaultGran
How often in milliseconds the baseTimer triggers

Constructor Detail

SourcedTimer

public SourcedTimer(TimeSource src)
Create a SourcedTimer for the given source using default granularity.

Parameters:
src - An object that implements the TimeSource interface.

SourcedTimer

public SourcedTimer(TimeSource src,
                    javax.swing.Timer timer)
Create a SourcedTimer for the given source. Use the Timer passed as an argument for the base timer.

Parameters:
src - An object that implements the TimeSource interface.
timer - A java.swing.Timer object for use as base timer.

SourcedTimer

public SourcedTimer(TimeSource src,
                    int granularity)
Create a SourcedTimer for the given source with the specified granularity.

Parameters:
src - An object that implements the TimeSource interface.
granularity - Periood in milliseconds that base timer should fire.
Method Detail

start

public void start()
Start the timer. The associated base timer is started if it is not already running.


stop

public void stop()
Stop the timer. The associated base timer is stopped.


actionPerformed

public void actionPerformed(java.awt.event.ActionEvent e)
Called in response to an ActionEvent from the associated base timer. Nominally this method is called every granularity milliseconds.

Specified by:
actionPerformed in interface java.awt.event.ActionListener
Parameters:
e - ActionEvent from base timer.

addSourcedTimerListener

public void addSourcedTimerListener(SourcedTimerListener l)
Add a listener to this object.

Parameters:
l - An object that implements SourcedTimerListener interface.

getConversionDivisor

public long getConversionDivisor()
A client of SourcedTimer may need to convert source timer time from raw units to some other units for display purposes. This method is available to listeners who have a reference to a SourcedTimer but not necessarily the source itself. It simply delegates to the source and asks what number are raw units divider by to arrive at seconds.

Returns:
A number used to divide base timer time for conversion to seconds.