com.alee.utils.swing
Class WebTimer

java.lang.Object
  extended by com.alee.utils.swing.WebTimer
Direct Known Subclasses:
ComponentUpdater

public class WebTimer
extends java.lang.Object

This timer is a small extension for standart javax.swing.Timer. Instead of running in a single queue it creates separate Threads for each timer and does not affect event-dispatching thread, until events are dispatched. This basically means that you can use any number of Timer instances and you can run them alltogether without having any issues.

Also this Timer implementation offers a variety of additional features and improvements which standard timer doesn't have (for example you can dispatch events in a separate non-EDT thread and as a result avoid using EDT at all where it is not necessary).

Author:
Mikle Garin
See Also:
Timer, TimerActionListener

Field Summary
protected  java.lang.String actionCommand
          Action command for fired events.
protected  boolean coalesce
          Whether each action should be fired from a separate invoke and wait call or not.
protected  int cycleCount
          Number of executed cycles;
protected  int cyclesLimit
          Timer cycles execution limit.
static int defaultCyclesLimit
          Default cycles number limit.
static java.lang.String defaultThreadName
          Default name for timer thread.
protected  long delay
          Delay between timer cycles in milliseconds.
protected  java.lang.Thread exec
          Last timer thread.
protected  int id
          Unique (within one timer instance) ID of currently running thread.
protected  long initialDelay
          Delay before the first timer cycle run in milliseconds.
protected  int lastId
          ID of previously executed thread.
protected  java.util.List<java.awt.event.ActionListener> listeners
          Timer event listeners list.
protected  java.lang.String name
          Internal timer thread name.
protected  boolean nonBlockingStop
          Whether or not timer should use non-blocking stop method behavior.
protected  boolean repeats
          Whether timer repeat its cycles or not.
protected  java.util.Map<java.lang.Integer,java.lang.Boolean> running
          Map of marks for currently active threads.
protected  long sleepStart
          Last timer cycle start time.
protected  long sleepTime
          Last timer cycle delay time.
protected  boolean useDaemonThread
          Whether should use daemon thread instead of user one or not.
static boolean useEdtByDefault
          Whether EDT should be used as the default timer action execution thread.
protected  boolean useEventDispatchThread
          Whether actions should be fired from Event Dispatch Thread or not.
 
Constructor Summary
WebTimer(long delay)
          Constructs timer with specified delay.
WebTimer(long delay, java.awt.event.ActionListener listener)
          Constructs timer with specified delay and action listener.
WebTimer(long delay, long initialDelay)
          Constructs timer with specified delay and initial delay.
WebTimer(long delay, long initialDelay, java.awt.event.ActionListener listener)
          Constructs timer with specified delay, initial delay and action listener.
WebTimer(java.lang.String delay)
          Constructs timer with specified delay.
WebTimer(java.lang.String delay, java.awt.event.ActionListener listener)
          Constructs timer with specified delay and action listener.
WebTimer(java.lang.String name, long delay)
          Constructs timer with specified internal thread name and delay.
WebTimer(java.lang.String name, long delay, java.awt.event.ActionListener listener)
          Constructs timer with specified internal thread name, delay and action listener.
WebTimer(java.lang.String name, long delay, long initialDelay)
          Constructs timer with specified internal thread name, delay and initial delay.
WebTimer(java.lang.String name, long delay, long initialDelay, java.awt.event.ActionListener listener)
          Constructs timer with specified internal thread name, delay, initial delay and action listener.
WebTimer(java.lang.String name, java.lang.String delay)
          Constructs timer with specified internal thread name and delay.
WebTimer(java.lang.String name, java.lang.String delay, java.awt.event.ActionListener listener)
          Constructs timer with specified internal thread name, delay and action listener.
WebTimer(java.lang.String name, java.lang.String delay, java.lang.String initialDelay, java.awt.event.ActionListener listener)
          Constructs timer with specified internal thread name, delay, initial delay and action listener.
 
Method Summary
 WebTimer addActionListener(java.awt.event.ActionListener listener)
          Adds new action listener.
protected  void cleanUp(int id)
          Cleans thread ID cache.
protected  java.awt.event.ActionEvent createActionEvent()
          Returns action event.
static WebTimer delay(long delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(long delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(java.lang.String delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(java.lang.String delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(java.lang.String name, long delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(java.lang.String name, long delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(java.lang.String name, java.lang.String delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
static WebTimer delay(java.lang.String name, java.lang.String delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.
 void fireActionPerformed(int id)
          Fires action events.
 java.lang.String getActionCommand()
          Returns action command for fired events.
 int getCycleCount()
          Returns executed cycles count.
 int getCycleNumber()
          Returns current cycle number.
 int getCyclesLimit()
          Returns timer cycles execution limit.
 long getCycleTimeLeft()
          Returns time left in milliseconds until current cycle action exection.
 long getCycleTimePassed()
          Returns time passed in milliseconds since curent cycle start.
 long getDelay()
          Returns delay between timer cycles in milliseconds.
 long getInitialDelay()
          Returns delay before the first timer cycle run in milliseconds.
 java.lang.String getInitialStringDelay()
          Returns delay before the first timer cycle run.
 java.util.List<java.awt.event.ActionListener> getListeners()
          Returns available action listeners list.
 java.lang.String getName()
          Returns internal timer thread name.
 java.lang.String getStringDelay()
          Returns delay between timer cycles.
 boolean isCoalesce()
          Returns whether each action should be fired from a separate invoke and wait call or not.
 boolean isLastCycle()
          Return whether last cycle exection is ongoing or not.
 boolean isNonBlockingStop()
          Returns whether or not timer should use non-blocking stop method behavior.
 boolean isRepeats()
          Returns whether timer repeat its cycles or not.
 boolean isRunning()
          Returns whether this timer is running or not.
 boolean isUseDaemonThread()
          Returns whether should use daemon thread instead of user one or not.
 boolean isUseEventDispatchThread()
          Returns whether actions should be fired from Event Dispatch Thread or not.
 WebTimer removeActionListener(java.awt.event.ActionListener listener)
          Removes an action listener.
static WebTimer repeat(boolean useDaemonThread, java.lang.String name, long delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(boolean useDaemonThread, java.lang.String name, long delay, long initialDelay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(boolean useDaemonThread, java.lang.String name, long delay, long initialDelay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(long delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(long delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(long delay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(long delay, int cyclesLimit, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(long delay, long initialDelay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(long delay, long initialDelay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(long delay, long initialDelay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(long delay, long initialDelay, int cyclesLimit, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(java.lang.String delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String delay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String delay, int cyclesLimit, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, int cyclesLimit, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, long initialDelay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, long initialDelay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, long initialDelay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(java.lang.String name, long delay, long initialDelay, int cyclesLimit, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.
static WebTimer repeat(java.lang.String name, java.lang.String delay, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, java.lang.String delay, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, java.lang.String delay, int cyclesLimit, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
static WebTimer repeat(java.lang.String name, java.lang.String delay, int cyclesLimit, boolean useEventDispatchThread, java.awt.event.ActionListener listener)
          Returns newly created and started timer that repeats and has the specified delay and action listener.
 WebTimer restart()
          Restarts timer execution.
 WebTimer restart(long delay)
          Restarts timer execution and modifies timer delay.
 WebTimer restart(long initialDelay, long delay)
          Restarts timer execution and modifies timer delays.
 WebTimer restart(java.lang.String delay)
          Restarts timer execution and modifies timer delay.
 WebTimer restart(java.lang.String initialDelay, java.lang.String delay)
          Restarts timer execution and modifies timer delays.
 WebTimer setActionCommand(java.lang.String actionCommand)
          Sets action command for fired events.
protected  void setAlive(int id, boolean alive)
          Sets whether thread under specified ID is alive or not.
 WebTimer setCoalesce(boolean coalesce)
          Sets whether each action should be fired from a separate invoke and wait call or not.
 WebTimer setCyclesLimit(int cyclesLimit)
          Sets timer cycles execution limit.
 WebTimer setDelay(long delay)
          Sets delay between timer cycles in milliseconds.
 WebTimer setDelay(java.lang.String delay)
          Sets delay between timer cycles.
 WebTimer setInitialDelay(long initialDelay)
          Sets delay before the first timer cycle run in milliseconds.
 WebTimer setInitialDelay(java.lang.String initialDelay)
          Sets delay before the first timer cycle run.
 WebTimer setName(java.lang.String name)
          Sets internal timer thread name.
 WebTimer setNonBlockingStop(boolean nonBlockingStop)
          Sets whether or not timer should use non-blocking stop method behavior.
 WebTimer setRepeats(boolean repeats)
          Sets whether timer should repeat its cycles or not.
 WebTimer setUseDaemonThread(boolean useDaemonThread)
          Returns whether should use daemon thread instead of user one or not.
 WebTimer setUseEventDispatchThread(boolean useEventDispatchThread)
          Sets whether actions should be fired from Event Dispatch Thread or not.
protected  boolean shouldContinue(int cycle, int id)
          Returns whether thread with specified ID should continue execution or not.
 WebTimer start()
          Starts timer execution.
protected  void startExec()
          Starts timer execution thread.
 WebTimer stop()
          Stops timer execution.
protected  void stopExec()
          Stops timer execution.
 java.lang.String toString()
          
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

defaultThreadName

public static java.lang.String defaultThreadName
Default name for timer thread.


defaultCyclesLimit

public static int defaultCyclesLimit
Default cycles number limit.


useEdtByDefault

public static boolean useEdtByDefault
Whether EDT should be used as the default timer action execution thread.


listeners

protected final java.util.List<java.awt.event.ActionListener> listeners
Timer event listeners list.


id

protected int id
Unique (within one timer instance) ID of currently running thread.


lastId

protected int lastId
ID of previously executed thread.


running

protected final java.util.Map<java.lang.Integer,java.lang.Boolean> running
Map of marks for currently active threads.


sleepStart

protected long sleepStart
Last timer cycle start time.


sleepTime

protected long sleepTime
Last timer cycle delay time.


cycleCount

protected int cycleCount
Number of executed cycles;


exec

protected java.lang.Thread exec
Last timer thread.


delay

protected long delay
Delay between timer cycles in milliseconds.


initialDelay

protected long initialDelay
Delay before the first timer cycle run in milliseconds.


repeats

protected boolean repeats
Whether timer repeat its cycles or not.


coalesce

protected boolean coalesce
Whether each action should be fired from a separate invoke and wait call or not. This might be useful if you are going to use multiply action listeners and make some interface changes on each action.


useEventDispatchThread

protected boolean useEventDispatchThread
Whether actions should be fired from Event Dispatch Thread or not. This might be useful if operations you want to perform within timer cycles have nothing to do with Event Dispatch Thread.


useDaemonThread

protected boolean useDaemonThread
Whether should use daemon thread instead of user one or not. Daemon thread will allow JVM to shutdown even if timer is still running. This option should be set before starting timer to have any effect.


nonBlockingStop

protected boolean nonBlockingStop
Whether or not timer should use non-blocking stop method behavior. Blocking behavior will join execution thread (and possibly EDT with it). Non-blockng behavior will simply send abort commands and continue without waiting for actual exection to stop.


actionCommand

protected java.lang.String actionCommand
Action command for fired events.


name

protected java.lang.String name
Internal timer thread name.


cyclesLimit

protected int cyclesLimit
Timer cycles execution limit. Zero and less = unlimited amount of execution cycles.

Constructor Detail

WebTimer

public WebTimer(java.lang.String delay)
Constructs timer with specified delay.

Parameters:
delay - delay between timer cycles

WebTimer

public WebTimer(long delay)
Constructs timer with specified delay.

Parameters:
delay - delay between timer cycles in milliseconds

WebTimer

public WebTimer(java.lang.String name,
                java.lang.String delay)
Constructs timer with specified internal thread name and delay.

Parameters:
name - internal thread name
delay - delay between timer cycles

WebTimer

public WebTimer(java.lang.String name,
                long delay)
Constructs timer with specified internal thread name and delay.

Parameters:
name - internal thread name
delay - delay between timer cycles in milliseconds

WebTimer

public WebTimer(long delay,
                long initialDelay)
Constructs timer with specified delay and initial delay.

Parameters:
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds

WebTimer

public WebTimer(java.lang.String name,
                long delay,
                long initialDelay)
Constructs timer with specified internal thread name, delay and initial delay.

Parameters:
name - internal thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds

WebTimer

public WebTimer(java.lang.String delay,
                java.awt.event.ActionListener listener)
Constructs timer with specified delay and action listener.

Parameters:
delay - delay between timer cycles
listener - action listener

WebTimer

public WebTimer(long delay,
                java.awt.event.ActionListener listener)
Constructs timer with specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
listener - action listener

WebTimer

public WebTimer(java.lang.String name,
                java.lang.String delay,
                java.awt.event.ActionListener listener)
Constructs timer with specified internal thread name, delay and action listener.

Parameters:
name - internal thread name
delay - delay between timer cycles
listener - action listener

WebTimer

public WebTimer(java.lang.String name,
                long delay,
                java.awt.event.ActionListener listener)
Constructs timer with specified internal thread name, delay and action listener.

Parameters:
name - internal thread name
delay - delay between timer cycles in milliseconds
listener - action listener

WebTimer

public WebTimer(long delay,
                long initialDelay,
                java.awt.event.ActionListener listener)
Constructs timer with specified delay, initial delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
listener - action listener

WebTimer

public WebTimer(java.lang.String name,
                java.lang.String delay,
                java.lang.String initialDelay,
                java.awt.event.ActionListener listener)
Constructs timer with specified internal thread name, delay, initial delay and action listener.

Parameters:
name - internal thread name
delay - delay between timer cycles
initialDelay - delay before the first timer cycle run
listener - action listener

WebTimer

public WebTimer(java.lang.String name,
                long delay,
                long initialDelay,
                java.awt.event.ActionListener listener)
Constructs timer with specified internal thread name, delay, initial delay and action listener.

Parameters:
name - internal thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
listener - action listener
Method Detail

getInitialDelay

public long getInitialDelay()
Returns delay before the first timer cycle run in milliseconds.

Returns:
delay before the first timer cycle run in milliseconds

getInitialStringDelay

public java.lang.String getInitialStringDelay()
Returns delay before the first timer cycle run.

Returns:
delay before the first timer cycle run

setInitialDelay

public WebTimer setInitialDelay(java.lang.String initialDelay)
Sets delay before the first timer cycle run.

Parameters:
initialDelay - delay before the first timer cycle run
Returns:
this timer

setInitialDelay

public WebTimer setInitialDelay(long initialDelay)
Sets delay before the first timer cycle run in milliseconds.

Parameters:
initialDelay - delay before the first timer cycle run in milliseconds
Returns:
this timer

getDelay

public long getDelay()
Returns delay between timer cycles in milliseconds.

Returns:
delay between timer cycles in milliseconds

getStringDelay

public java.lang.String getStringDelay()
Returns delay between timer cycles.

Returns:
delay between timer cycles

setDelay

public WebTimer setDelay(java.lang.String delay)
Sets delay between timer cycles.

Parameters:
delay - delay between timer cycles
Returns:
this timer

setDelay

public WebTimer setDelay(long delay)
Sets delay between timer cycles in milliseconds.

Parameters:
delay - delay between timer cycles in milliseconds
Returns:
this timer

isRepeats

public boolean isRepeats()
Returns whether timer repeat its cycles or not.

Returns:
true if timer repeat its cycles, false otherwise

setRepeats

public WebTimer setRepeats(boolean repeats)
Sets whether timer should repeat its cycles or not.

Parameters:
repeats - whether timer should repeat its cycles or not
Returns:
this timer

isCoalesce

public boolean isCoalesce()
Returns whether each action should be fired from a separate invoke and wait call or not.

Returns:
true if each action should be fired from a separate invoke and wait call, false otherwise

setCoalesce

public WebTimer setCoalesce(boolean coalesce)
Sets whether each action should be fired from a separate invoke and wait call or not.

Parameters:
coalesce - whether each action should be fired from a separate invoke and wait call or not
Returns:
this timer

isUseEventDispatchThread

public boolean isUseEventDispatchThread()
Returns whether actions should be fired from Event Dispatch Thread or not.

Returns:
true if actions should be fired from Event Dispatch Thread, false otherwise

setUseEventDispatchThread

public WebTimer setUseEventDispatchThread(boolean useEventDispatchThread)
Sets whether actions should be fired from Event Dispatch Thread or not.

Parameters:
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
Returns:
this timer

isUseDaemonThread

public boolean isUseDaemonThread()
Returns whether should use daemon thread instead of user one or not.

Returns:
true if should use daemon thread instead of user one, false otherwise

setUseDaemonThread

public WebTimer setUseDaemonThread(boolean useDaemonThread)
Returns whether should use daemon thread instead of user one or not. If set to true it will allow JVM to shutdown even if timer is still running. This option should be set before starting timer to have any effect.

Parameters:
useDaemonThread - whether should use daemon thread instead of user one or not
Returns:
this timer

isNonBlockingStop

public boolean isNonBlockingStop()
Returns whether or not timer should use non-blocking stop method behavior.

Returns:
true if timer should use non-blocking stop method behavior, false otherwise

setNonBlockingStop

public WebTimer setNonBlockingStop(boolean nonBlockingStop)
Sets whether or not timer should use non-blocking stop method behavior.

Parameters:
nonBlockingStop - whether or not timer should use non-blocking stop method behavior
Returns:
this timer

getActionCommand

public java.lang.String getActionCommand()
Returns action command for fired events.

Returns:
action command for fired events

setActionCommand

public WebTimer setActionCommand(java.lang.String actionCommand)
Sets action command for fired events.

Parameters:
actionCommand - action command for fired events
Returns:
this timer

getCyclesLimit

public int getCyclesLimit()
Returns timer cycles execution limit.

Returns:
timer cycles execution limit

setCyclesLimit

public WebTimer setCyclesLimit(int cyclesLimit)
Sets timer cycles execution limit. Zero and less = unlimited amount of execution cycles.

Parameters:
cyclesLimit - timer cycles execution limit
Returns:
this timer

getName

public java.lang.String getName()
Returns internal timer thread name.

Returns:
internal timer thread name

setName

public WebTimer setName(java.lang.String name)
Sets internal timer thread name.

Parameters:
name - internal timer thread name
Returns:
this timer

getCycleTimePassed

public long getCycleTimePassed()
Returns time passed in milliseconds since curent cycle start. Cycle includes its delay time and execution time.

Returns:
time passed in milliseconds since curent cycle start

getCycleTimeLeft

public long getCycleTimeLeft()
Returns time left in milliseconds until current cycle action exection.

Returns:
time left in milliseconds until current cycle action exection

getCycleCount

public int getCycleCount()
Returns executed cycles count. This number changes only after cycle execution (including action execution).

Returns:
executed cycles count

getCycleNumber

public int getCycleNumber()
Returns current cycle number. This number changes only after cycle execution (including action execution).

Returns:
current cycle number

isLastCycle

public boolean isLastCycle()
Return whether last cycle exection is ongoing or not.

Returns:
true if last cycle exection is ongoing, false otherwise

start

public WebTimer start()
Starts timer execution.

Returns:
this timer

stop

public WebTimer stop()
Stops timer execution.

Returns:
this timer

restart

public WebTimer restart()
Restarts timer execution.

Returns:
this timer

restart

public WebTimer restart(long delay)
Restarts timer execution and modifies timer delay.

Parameters:
delay - delay between timer cycles
Returns:
this timer

restart

public WebTimer restart(long initialDelay,
                        long delay)
Restarts timer execution and modifies timer delays.

Parameters:
initialDelay - delay before the first timer cycle run
delay - delay between timer cycles
Returns:
this timer

restart

public WebTimer restart(java.lang.String delay)
Restarts timer execution and modifies timer delay.

Parameters:
delay - delay between timer cycles
Returns:
this timer

restart

public WebTimer restart(java.lang.String initialDelay,
                        java.lang.String delay)
Restarts timer execution and modifies timer delays.

Parameters:
initialDelay - delay before the first timer cycle run
delay - delay between timer cycles
Returns:
this timer

isRunning

public boolean isRunning()
Returns whether this timer is running or not.

Returns:
true if this timer is running, false otherwise

startExec

protected void startExec()
Starts timer execution thread.


shouldContinue

protected boolean shouldContinue(int cycle,
                                 int id)
Returns whether thread with specified ID should continue execution or not.

Parameters:
cycle - cycle number
id - execution thread ID
Returns:
true if thread with specified ID should continue execution, false otherwise

setAlive

protected void setAlive(int id,
                        boolean alive)
Sets whether thread under specified ID is alive or not.

Parameters:
id - thread ID
alive - whether thread is alive or not

cleanUp

protected void cleanUp(int id)
Cleans thread ID cache.

Parameters:
id - thread ID

stopExec

protected void stopExec()
Stops timer execution.


addActionListener

public WebTimer addActionListener(java.awt.event.ActionListener listener)
Adds new action listener. You can use TimerActionListener instead of simple ActionListener to simplify interaction with timer.

Parameters:
listener - new action listener
Returns:
this timer

removeActionListener

public WebTimer removeActionListener(java.awt.event.ActionListener listener)
Removes an action listener.

Parameters:
listener - action listener
Returns:
this timer

getListeners

public java.util.List<java.awt.event.ActionListener> getListeners()
Returns available action listeners list.

Returns:
available action listeners list

fireActionPerformed

public void fireActionPerformed(int id)
Fires action events.

Parameters:
id - execution thread ID

createActionEvent

protected java.awt.event.ActionEvent createActionEvent()
Returns action event.

Returns:
action event

toString

public java.lang.String toString()

Overrides:
toString in class java.lang.Object

delay

public static WebTimer delay(java.lang.String delay,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(long delay,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(java.lang.String name,
                             java.lang.String delay,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(java.lang.String name,
                             long delay,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(java.lang.String delay,
                             boolean useEventDispatchThread,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(long delay,
                             boolean useEventDispatchThread,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(java.lang.String name,
                             java.lang.String delay,
                             boolean useEventDispatchThread,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

delay

public static WebTimer delay(java.lang.String name,
                             long delay,
                             boolean useEventDispatchThread,
                             java.awt.event.ActionListener listener)
Returns newly created and started timer that doesn't repeat and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String delay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String delay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              java.lang.String delay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              java.lang.String delay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String delay,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String delay,
                              int cyclesLimit,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles
cyclesLimit - timer cycles execution limit
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              int cyclesLimit,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
cyclesLimit - timer cycles execution limit
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              java.lang.String delay,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              java.lang.String delay,
                              int cyclesLimit,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles
cyclesLimit - timer cycles execution limit
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              int cyclesLimit,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
cyclesLimit - timer cycles execution limit
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              long initialDelay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              long initialDelay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              long initialDelay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              long initialDelay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              long initialDelay,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(long delay,
                              long initialDelay,
                              int cyclesLimit,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
cyclesLimit - timer cycles execution limit
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              long initialDelay,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(java.lang.String name,
                              long delay,
                              long initialDelay,
                              int cyclesLimit,
                              boolean useEventDispatchThread,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
name - thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
cyclesLimit - timer cycles execution limit
useEventDispatchThread - whether actions should be fired from Event Dispatch Thread or not
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(boolean useDaemonThread,
                              java.lang.String name,
                              long delay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
useDaemonThread - whether should use daemon thread instead of user one or not
name - thread name
delay - delay between timer cycles in milliseconds
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(boolean useDaemonThread,
                              java.lang.String name,
                              long delay,
                              long initialDelay,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
useDaemonThread - whether should use daemon thread instead of user one or not
name - thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
listener - action listener
Returns:
newly created and started timer

repeat

public static WebTimer repeat(boolean useDaemonThread,
                              java.lang.String name,
                              long delay,
                              long initialDelay,
                              int cyclesLimit,
                              java.awt.event.ActionListener listener)
Returns newly created and started timer that repeats and has the specified delay, initial delay and action listener.

Parameters:
useDaemonThread - whether should use daemon thread instead of user one or not
name - thread name
delay - delay between timer cycles in milliseconds
initialDelay - delay before the first timer cycle run in milliseconds
cyclesLimit - timer cycles execution limit
listener - action listener
Returns:
newly created and started timer