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

Nested Class Summary
protected static class WebTimer.PartType
          Time part type enumeration used to parse string delay.
 
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.
static int msInDay
          Timer constants for calculations.
static int msInHour
           
static int msInMinute
           
static int msInSecond
           
protected  java.lang.String name
          Internal timer thread name.
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.
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()
          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.
static void invokeAndWait(java.lang.Runnable runnable)
          Will invoke the specified action in EDT in case it is called from non-EDT thread.
 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 isRepeats()
          Returns whether timer repeat its cycles or not.
 boolean isRunning()
          Returns whether this timer is running or not.
 boolean isUseEventDispatchThread()
          Returns whether actions should be fired from Event Dispatch Thread or not.
static long parseDelay(java.lang.String delay)
          Either returns delay retrieved from string or throws an exception if it cannot be parsed.
 WebTimer removeActionListener(java.awt.event.ActionListener listener)
          Removes an 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 setRepeats(boolean repeats)
          Sets whether timer should repeat its cycles 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()
          
static java.lang.String toStringDelay(long delay)
          Returns delay string representation.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Field Detail

msInDay

public static final int msInDay
Timer constants for calculations.

See Also:
Constant Field Values

msInHour

public static final int msInHour
See Also:
Constant Field Values

msInMinute

public static final int msInMinute
See Also:
Constant Field Values

msInSecond

public static final int msInSecond
See Also:
Constant Field Values

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.


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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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

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 - 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()
Fires action events.


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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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
See Also:
parseDelay(String)

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

parseDelay

public static long parseDelay(java.lang.String delay)
                       throws DelayFormatException
Either returns delay retrieved from string or throws an exception if it cannot be parsed. Full string format is "Xd Yh Zm s ms" but you can skip any part of it. Yet you must specify atleast one value. For example string "2h 5s" will be a valid delay declaration and will be converted into (2*60*60*1000+5*1000) long value.

Parameters:
delay - string delay
Returns:
delay retrieved from string
Throws:
DelayFormatException

toStringDelay

public static java.lang.String toStringDelay(long delay)
Returns delay string representation.

Parameters:
delay - delay to process
Returns:
delay string representation

invokeAndWait

public static void invokeAndWait(java.lang.Runnable runnable)
                          throws java.lang.InterruptedException,
                                 java.lang.reflect.InvocationTargetException
Will invoke the specified action in EDT in case it is called from non-EDT thread.

Parameters:
runnable - runnable
Throws:
java.lang.InterruptedException
java.lang.reflect.InvocationTargetException