EchoPoint
1.0

echopoint
Class Timer

java.lang.Object
  extended bynextapp.echo.Component
      extended byechopoint.Timer
All Implemented Interfaces:
ReflectionSetter, java.io.Serializable

public class Timer
extends nextapp.echo.Component
implements ReflectionSetter

The Timer class is a Component that causes an action to occur at a predefined rate.
Each Timer has a list of ActionListeners and a delay ( the time between actionPerfomed() calls).
When delay milliseconds have passed, a Timer sends the actionPerformed() message to its listeners.
This cycle repeats until stop() is called, or halts immediately if the Timer is configured to send its message just once.
Note that this is a very coarse timer. The timer is run on the client and the timeout must travel back to the server before any other code can be notified of this event. Therefore the granuality of the timer cannot be gaurunteed, as it depends on the client speed and the network speed between the client and server.
This class is mostly useful for causing the client to update without having to have the user click on anything.
You can only have one effective Timer on a Window at a time. This is because once the lowest delay timer has popped, any screen updates will cause all Timers on that Window to be reset to their respective starting delays, regardless of how much time has passed since the last event happened on a given timer.
The reason the Timer is fired on the client rather than via a thread on the server, is to help support many clients (thousands). Each client is running their own timers, using their own processing power. If a single thread was created for all Timers (or worse one per client) then the system would eventually grind to a halt.

Author:
Brad Baker
See Also:
Serialized Form

Field Summary
static java.lang.String TIMER_CHANGED_PROPERTY
           
 
Fields inherited from class nextapp.echo.Component
BACKGROUND_CHANGED_PROPERTY, CHILDREN_CHANGED_PROPERTY, ENABLED_CHANGED_PROPERTY, FONT_CHANGED_PROPERTY, FOREGROUND_CHANGED_PROPERTY, IDENTIFIER_CHANGED_PROPERTY, listenerList, LOCALE_CHANGED_PROPERTY, MODEL_CHANGED_PROPERTY, STYLE_BACKGROUND, STYLE_FONT, STYLE_FOREGROUND, UPDATE_PROPERTY, VISIBLE_CHANGED_PROPERTY
 
Constructor Summary
Timer()
          Creates a Timer that will notify its listeners every 1000 milliseconds.
Timer(int delay)
          Creates a Timer that will notify its listeners every delay milliseconds.
Timer(int delay, nextapp.echo.event.ActionListener actionListener)
          Creates a Timer that will notify its listeners every delay milliseconds.
 
Method Summary
 void addActionListener(nextapp.echo.event.ActionListener l)
          Adds an ActionListener to the Timer.
 void fireActionPerformed(nextapp.echo.event.ActionEvent e)
          Notifies all listeners that have registered for this event type.
 java.lang.String getActionCommand()
           
 int getDelay()
           
 int getInitialDelay()
           
 boolean hasFired()
           
 boolean isRepeats()
          Returns true if the Timer will send a actionPerformed() message to its listeners multiple times.
 boolean isRunning()
           
 void removeActionListener(nextapp.echo.event.ActionListener l)
          Removes an ActionListener from the Timer.
 void restart()
          Restarts a Timer, canceling any pending firings, and causing it to fire with its initial dely.
 java.lang.Object set(java.lang.reflect.Field field, java.lang.Object newValue)
          Called to save the old value of a field, set in a new value and return the old value of a field.
 void setActionCommand(java.lang.String newValue)
          Sets the Timer's action command.
 void setDelay(int newValue)
          Sets the Timer's delay, the number of milliseconds between successive actionPerfomed() messages to its listeners
This methods fires a PropertyChangeEvent with a getPropertyName() value of Timer.TIMER_CHANGED_PROPERTY
 void setInitialDelay(int newValue)
          Sets the Timer's initial delay.
 void setRepeats(boolean newValue)
          Instructs the Timer to send actionPerformed() to its listeners only once, and then stop.
 void start()
          Starts the Timer, causing it to send actionPerformed() messages to its listeners.
 void stop()
          Stops the Timer, causing it to stop sending actionPerformed() messages to its listeners.
 
Methods inherited from class nextapp.echo.Component
add, add, addHierarchyListener, addPropertyChangeListener, applyStyle, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getBackground, getComponent, getComponentCount, getComponents, getEchoInstance, getFont, getForeground, getIdentifier, getLocale, getParent, indexOf, init, isAncestorOf, isEnabled, isRegistered, isShowing, isVisible, remove, remove, removeAll, removeHierarchyListener, removePropertyChangeListener, setBackground, setEnabled, setFont, setForeground, setIdentifier, setLocale, setVisible, update, validate
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

TIMER_CHANGED_PROPERTY

public static final java.lang.String TIMER_CHANGED_PROPERTY
See Also:
Constant Field Values
Constructor Detail

Timer

public Timer()
Creates a Timer that will notify its listeners every 1000 milliseconds.


Timer

public Timer(int delay)
Creates a Timer that will notify its listeners every delay milliseconds.


Timer

public Timer(int delay,
             nextapp.echo.event.ActionListener actionListener)
Creates a Timer that will notify its listeners every delay milliseconds.

Method Detail

addActionListener

public void addActionListener(nextapp.echo.event.ActionListener l)
Adds an ActionListener to the Timer.

Parameters:
l - The ActionListener to be added.

fireActionPerformed

public void fireActionPerformed(nextapp.echo.event.ActionEvent e)
Notifies all listeners that have registered for this event type.

Parameters:
e - The ActionEvent to send.

getActionCommand

public java.lang.String getActionCommand()
Returns:
the action command for the Timer

getDelay

public int getDelay()
Returns:
The delay in milliseconds of the Timer.

getInitialDelay

public int getInitialDelay()
Returns:
The initial delay in milliseconds of the Timer.

hasFired

public boolean hasFired()
Returns:
true if the Timer has fired before

isRepeats

public boolean isRepeats()
Returns true if the Timer will send a actionPerformed() message to its listeners multiple times.


isRunning

public boolean isRunning()
Returns:
true of the Timer is running.

removeActionListener

public void removeActionListener(nextapp.echo.event.ActionListener l)
Removes an ActionListener from the Timer.

Parameters:
l - The ActionListener to be removed.

restart

public void restart()
Restarts a Timer, canceling any pending firings, and causing it to fire with its initial dely.


setActionCommand

public void setActionCommand(java.lang.String newValue)
Sets the Timer's action command.

Parameters:
newValue - The new action command for this timer.

setDelay

public void setDelay(int newValue)
Sets the Timer's delay, the number of milliseconds between successive actionPerfomed() messages to its listeners
This methods fires a PropertyChangeEvent with a getPropertyName() value of Timer.TIMER_CHANGED_PROPERTY


setInitialDelay

public void setInitialDelay(int newValue)
Sets the Timer's initial delay. This will be used for the first "ringing" of the Timer only. Subsequent ringings will be spaced using the delay property.
This methods fires a PropertyChangeEvent with a getPropertyName() value of Timer.TIMER_CHANGED_PROPERTY


setRepeats

public void setRepeats(boolean newValue)
Instructs the Timer to send actionPerformed() to its listeners only once, and then stop.
This methods fires a PropertyChangeEvent with a getPropertyName() value of Timer.TIMER_CHANGED_PROPERTY


start

public void start()
Starts the Timer, causing it to send actionPerformed() messages to its listeners.


stop

public void stop()
Stops the Timer, causing it to stop sending actionPerformed() messages to its listeners.


set

public java.lang.Object set(java.lang.reflect.Field field,
                            java.lang.Object newValue)
                     throws java.lang.Exception
Description copied from interface: ReflectionSetter
Called to save the old value of a field, set in a new value and return the old value of a field. This interface allows a field set operation to be "delegated" back into the class that has permission to perform the field set.

 public Object set(Field f, Object newValue) throws Exception {
      Object oldValue = f.get(this);
      f.set(this,newValue);
      return oldValue;
 }
 

Specified by:
set in interface ReflectionSetter
Parameters:
field - - the field to be set
newValue - - the new value to be set
Returns:
the oldValue of the field
Throws:
java.lang.Exception
See Also:
ReflectionSetter.set(Field, Object)

EchoPoint
1.0