Package org.reactfx.util
Class FxTimer
- java.lang.Object
-
- org.reactfx.util.FxTimer
-
-
Field Summary
Fields Modifier and Type Field Description private java.lang.Runnable
action
private javafx.util.Duration
actionTime
private long
seq
private javafx.animation.Timeline
timeline
-
Constructor Summary
Constructors Modifier Constructor Description private
FxTimer(java.time.Duration actionTime, java.time.Duration period, java.lang.Runnable action, int cycles)
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description static Timer
create(java.time.Duration delay, java.lang.Runnable action)
Prepares a (stopped) timer that lasts fordelay
and whose action runs when timer ends.static Timer
createPeriodic(java.time.Duration interval, java.lang.Runnable action)
Prepares a (stopped) timer that lasts forinterval
and that executes the given action periodically when the timer ends.static Timer
createPeriodic0(java.time.Duration interval, java.lang.Runnable action)
Prepares a (stopped) timer that lasts forinterval
and that executes the given action periodically when the timer starts.void
restart()
Schedules the associated action to be executed after the associated delay.static Timer
runLater(java.time.Duration delay, java.lang.Runnable action)
Equivalent tocreate(delay, action).restart()
.static Timer
runPeriodically(java.time.Duration interval, java.lang.Runnable action)
Equivalent tocreatePeriodic(interval, action).restart()
.static Timer
runPeriodically0(java.time.Duration interval, java.lang.Runnable action)
Equivalent tocreatePeriodic0(interval, action).restart()
.void
stop()
If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all.
-
-
-
Method Detail
-
create
public static Timer create(java.time.Duration delay, java.lang.Runnable action)
Prepares a (stopped) timer that lasts fordelay
and whose action runs when timer ends.
-
runLater
public static Timer runLater(java.time.Duration delay, java.lang.Runnable action)
Equivalent tocreate(delay, action).restart()
.
-
createPeriodic
public static Timer createPeriodic(java.time.Duration interval, java.lang.Runnable action)
Prepares a (stopped) timer that lasts forinterval
and that executes the given action periodically when the timer ends.
-
runPeriodically
public static Timer runPeriodically(java.time.Duration interval, java.lang.Runnable action)
Equivalent tocreatePeriodic(interval, action).restart()
.
-
createPeriodic0
public static Timer createPeriodic0(java.time.Duration interval, java.lang.Runnable action)
Prepares a (stopped) timer that lasts forinterval
and that executes the given action periodically when the timer starts.
-
runPeriodically0
public static Timer runPeriodically0(java.time.Duration interval, java.lang.Runnable action)
Equivalent tocreatePeriodic0(interval, action).restart()
.
-
restart
public void restart()
Description copied from interface:Timer
Schedules the associated action to be executed after the associated delay. If the action is already scheduled but hasn't been executed yet, the timeout is reset, so that the action won't be executed before the full delay from now.
-
stop
public void stop()
Description copied from interface:Timer
If the associated action has been scheduled for execution but not yet executed, this method prevents it from being executed at all. This is also true in case the timer's timeout has already expired, but the associated action hasn't had a chance to be executed on the associated thread. Note that this is a stronger guarantee than the one given byAnimation.stop()
:Timeline timeline = new Timeline(new KeyFrame( Duration.millis(1000), ae -> System.out.println("FIRED ANYWAY"))); timeline.play(); // later on the JavaFX application thread, // but still before the action has been executed timeline.stop(); // later, "FIRED ANYWAY" may still be printed
FxTimer
, the action is guaranteed not to be executed afterstop()
:Timer timer = FxTimer.runLater( Duration.ofMillis(1000), () -> System.out.println("FIRED")); // later on the JavaFX application thread, // but still before the action has been executed timer.stop(); // "FIRED" is guaranteed *not* to be printed
-
-