org.jscience.swing.spinner
Class SharableTimer

java.lang.Object
  extended by javax.swing.Timer
      extended by org.jscience.swing.spinner.SharableTimer
All Implemented Interfaces:
java.io.Serializable

public class SharableTimer
extends javax.swing.Timer

This Timer is optimized for sharable usage from different contexts, for example: Two Objects want to share one Timer. (This is similar to a Model-View-Architecture.)

To start this timer, the starting context must call one of the following methods:

and give this Timer the delay, the coalesce state and all relevant ActionListeners listening to this Timer. Before beginning to send ActionEvents to the Listeners, this Timer will add the specified ActionListeners. A call to stop() will remove these added ActionListeners. Of course, all other ActionListeners which were added by the inherited method Timer.addActionListener(ActionListener) wont be removed.

Further more this Timer fires a ChangeEvent to all added ChangeListeners whenever it has been started or stopped.

As an example you can check up both Joggle and TimerControlPanel.

See Also:
Serialized Form

Field Summary
protected  javax.swing.event.EventListenerList changeListenerList
           
 
Fields inherited from class javax.swing.Timer
listenerList
 
Constructor Summary
SharableTimer()
          Creates a new SharableTimer with a delay of 0 and no ActionListener.
 
Method Summary
 void addChangeListener(javax.swing.event.ChangeListener l)
          Adds a listener to the list that is notified each time this Timer will be started or stopped.
protected  void fireStateChanged()
          Sends a ChangeEvent, whose source is this Timer, to each ChangeListener which was added to this Timer.
 void removeChangeListener(javax.swing.event.ChangeListener l)
          Removes a ChangeListener from this Timer.
 void start()
          Does nothing - please use one of the other start methods to start this Timer.
 void start(int delay, java.awt.event.ActionListener[] listenerToAdd, boolean coalesce)
          Adds all listenerToAdd, starts this Timer and calls fireStateChanged().
 void start(int delay, java.awt.event.ActionListener listenerToAdd, boolean coalesce)
          Similar to start(int,ActionListener[],boolean), but expecting only one ActionListener to add.
 void stop()
          Stops this Timer, removes the added ActionListeners recently given to one of the start-methods and calls fireStateChanged().
 
Methods inherited from class javax.swing.Timer
addActionListener, fireActionPerformed, getActionCommand, getActionListeners, getDelay, getInitialDelay, getListeners, getLogTimers, isCoalesce, isRepeats, isRunning, removeActionListener, restart, setActionCommand, setCoalesce, setDelay, setInitialDelay, setLogTimers, setRepeats
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

changeListenerList

protected javax.swing.event.EventListenerList changeListenerList
Constructor Detail

SharableTimer

public SharableTimer()
Creates a new SharableTimer with a delay of 0 and no ActionListener.

Method Detail

start

public void start(int delay,
                  java.awt.event.ActionListener[] listenerToAdd,
                  boolean coalesce)
Adds all listenerToAdd, starts this Timer and calls fireStateChanged(). If this timer is already running it will previously be stopped and starts running with the new parameters - in other words: this Timer will be restarted.

Parameters:
delay - the timer delay.
listenerToAdd - all ActionListeners to add before starting this timer.
coalesce - the coalesce state this Timer should work with.
See Also:
Timer.setDelay(int), Timer.setCoalesce(boolean), Timer.addActionListener(ActionListener)

start

public void start(int delay,
                  java.awt.event.ActionListener listenerToAdd,
                  boolean coalesce)
Similar to start(int,ActionListener[],boolean), but expecting only one ActionListener to add.

Parameters:
delay - the timer delay.
listenerToAdd - an ActionListener to add before starting this timer.
coalesce - the coalesce state this Timer should work with.

start

public void start()
Does nothing - please use one of the other start methods to start this Timer.

Overrides:
start in class javax.swing.Timer
See Also:
start(int,ActionListener[],boolean), start(int,ActionListener,boolean)

stop

public void stop()
Stops this Timer, removes the added ActionListeners recently given to one of the start-methods and calls fireStateChanged(). If this Timer is already stopped, this method does nothing.

Overrides:
stop in class javax.swing.Timer

addChangeListener

public void addChangeListener(javax.swing.event.ChangeListener l)
Adds a listener to the list that is notified each time this Timer will be started or stopped.

Parameters:
l - the ChangeListener to add

removeChangeListener

public void removeChangeListener(javax.swing.event.ChangeListener l)
Removes a ChangeListener from this Timer.

Parameters:
l - the listener to remove.

fireStateChanged

protected void fireStateChanged()
Sends a ChangeEvent, whose source is this Timer, to each ChangeListener which was added to this Timer. This method is called each time this Timer will be started or stopped.

See Also:
#addChangeListener(ChangeListenerl)