org.wings.util
Class Timer

java.lang.Object
  extended by org.wings.util.Timer
All Implemented Interfaces:
Serializable

public final class Timer
extends Object
implements Serializable

Author:
Armin Haaf
See Also:
Serialized Form

Constructor Summary
Timer(long delay, ActionListener listener)
          Creates a Timer that will notify its listeners every delay milliseconds.
 
Method Summary
 void addActionListener(ActionListener listener)
          Adds an actionListener to the Timer
protected  void fireActionPerformed(ActionEvent e)
          Notify all listeners that have registered interest for notification on this event type.
 long getDelay()
          Returns the Timer's delay.
 long getInitialDelay()
          Returns the Timer's initial delay.
static boolean getLogTimers()
          Returns true if logging is enabled.
 boolean isCoalesce()
          Returns true if the Timer coalesces multiple pending performCommand() messages.
 boolean isRepeats()
          Returns true if the Timer will send a actionPerformed() message to its listeners multiple times.
 boolean isRunning()
          Returns true if the Timer is running.
 void removeActionListener(ActionListener listener)
          Removes an ActionListener from the Timer.
 void restart()
          Restarts a Timer, canceling any pending firings, and causing it to fire with its initial dely.
 void setActionCommand(String command)
          Sets action command for this timer.
 void setCoalesce(boolean flag)
          Sets whether the Timer coalesces multiple pending ActionEvent firings.
 void setDelay(long delay)
          Sets the Timer's delay, the number of milliseconds between successive actionPerfomed() messages to its listeners
 void setInitialDelay(int initialDelay)
          Sets the Timer's initial delay.
static void setLogTimers(boolean flag)
          Enables or disables the timer log.
 void setRepeats(boolean flag)
          If flag is false, 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 a Timer, causing it to stop sending actionPerformed() messages to its Target.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

Timer

public Timer(long delay,
             ActionListener listener)
Creates a Timer that will notify its listeners every delay milliseconds.

Parameters:
delay - The number of milliseconds between listener notification
listener - An initial listener
See Also:
setInitialDelay(int), setRepeats(boolean)
Method Detail

addActionListener

public void addActionListener(ActionListener listener)
Adds an actionListener to the Timer


removeActionListener

public void removeActionListener(ActionListener listener)
Removes an ActionListener from the Timer.


setActionCommand

public void setActionCommand(String command)
Sets action command for this timer.


fireActionPerformed

protected void fireActionPerformed(ActionEvent e)
Notify all listeners that have registered interest for notification on this event type. The event instance is lazily created using the parameters passed into the fire method.


setLogTimers

public static void setLogTimers(boolean flag)
Enables or disables the timer log. When enabled, a message is posted to System.out whenever the timer goes off.

Parameters:
flag - true to enable logging
See Also:
getLogTimers()

getLogTimers

public static boolean getLogTimers()
Returns true if logging is enabled.

Returns:
true if logging is enabled
See Also:
setLogTimers(boolean)

setDelay

public void setDelay(long delay)
Sets the Timer's delay, the number of milliseconds between successive actionPerfomed() messages to its listeners

See Also:
setInitialDelay(int)

getDelay

public long getDelay()
Returns the Timer's delay.

See Also:
setDelay(long)

setInitialDelay

public void setInitialDelay(int initialDelay)
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.

See Also:
setDelay(long)

getInitialDelay

public long getInitialDelay()
Returns the Timer's initial delay.

See Also:
setDelay(long)

setRepeats

public void setRepeats(boolean flag)
If flag is false, instructs the Timer to send actionPerformed() to its listeners only once, and then stop.


isRepeats

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

See Also:
setRepeats(boolean)

setCoalesce

public void setCoalesce(boolean flag)
Sets whether the Timer coalesces multiple pending ActionEvent firings. A busy application may not be able to keep up with a Timer's message generation, causing multiple actionPerformed() message sends to be queued. When processed, the application sends these messages one after the other, causing the Timer's listeners to receive a sequence of actionPerformed() messages with no delay between them. Coalescing avoids this situation by reducing multiple pending messages to a single message send. Timers coalesce their message sends by default.


isCoalesce

public boolean isCoalesce()
Returns true if the Timer coalesces multiple pending performCommand() messages.

See Also:
setCoalesce(boolean)

start

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

See Also:
stop()

isRunning

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

See Also:
start()

stop

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

See Also:
start()

restart

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



wingS Swings ;-)