Package generic.timer
Class ExpiringSwingTimer
- java.lang.Object
-
- generic.timer.GhidraSwingTimer
-
- generic.timer.ExpiringSwingTimer
-
- All Implemented Interfaces:
GhidraTimer
,java.awt.event.ActionListener
,java.util.EventListener
public class ExpiringSwingTimer extends GhidraSwingTimer
This class allows clients to run swing action at some point in the future, when the given condition is met, allowing for the task to timeout. While this class implements theGhidraTimer
interface, it is really meant to be used to execute a code snippet one time at some point in the future.Both the call to check for readiness and the actual client code will be run on the Swing thread.
-
-
Constructor Summary
Constructors Constructor Description ExpiringSwingTimer(int delay, int expireMs, java.util.function.BooleanSupplier isReady, java.lang.Runnable runnable)
Constructor
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
didRun()
Returns true if the client runnable was runboolean
isExpired()
Returns true the initial expiration period has passedstatic ExpiringSwingTimer
runWhen(java.util.function.BooleanSupplier isReady, int expireMs, java.lang.Runnable runnable)
Runs the given client runnable when the given condition returns true.void
setTimerCallback(TimerCallback callback)
void
start()
-
Methods inherited from class generic.timer.GhidraSwingTimer
actionPerformed, getDelay, getInitialDelay, isRepeats, isRunning, setDelay, setInitialDelay, setRepeats, stop
-
-
-
-
Constructor Detail
-
ExpiringSwingTimer
public ExpiringSwingTimer(int delay, int expireMs, java.util.function.BooleanSupplier isReady, java.lang.Runnable runnable)
ConstructorNote: this class sets the parent's initial delay to 0. This is to allow the client code to be executed without delay when the ready condition is true.
- Parameters:
delay
- the delay between calls to checkisReady
isReady
- true if the code should be runexpireMs
- the amount of time past which the code will not be runrunnable
- the code to run
-
-
Method Detail
-
runWhen
public static ExpiringSwingTimer runWhen(java.util.function.BooleanSupplier isReady, int expireMs, java.lang.Runnable runnable)
Runs the given client runnable when the given condition returns true. The returned timer will be running.Once the timer has performed the work, any calls to start the returned timer will not perform any work. You can check
didRun()
to see if the work has been completed.- Parameters:
isReady
- true if the code should be runexpireMs
- the amount of time past which the code will not be runrunnable
- the code to run- Returns:
- the timer object that is running, which will execute the given code when ready
-
didRun
public boolean didRun()
Returns true if the client runnable was run- Returns:
- true if the client runnable was run
-
start
public void start()
- Specified by:
start
in interfaceGhidraTimer
- Overrides:
start
in classGhidraSwingTimer
-
isExpired
public boolean isExpired()
Returns true the initial expiration period has passed- Returns:
- true if expired
-
setTimerCallback
public void setTimerCallback(TimerCallback callback)
- Specified by:
setTimerCallback
in interfaceGhidraTimer
- Overrides:
setTimerCallback
in classGhidraSwingTimer
-
-