Package generic.timer
Class ExpiringSwingTimer
java.lang.Object
generic.timer.GhidraSwingTimer
generic.timer.ExpiringSwingTimer
- All Implemented Interfaces:
GhidraTimer
,ActionListener
,EventListener
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 the
GhidraTimer
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
ConstructorDescriptionExpiringSwingTimer
(int delay, int expireMs, BooleanSupplier isReady, Runnable runnable) Constructor -
Method Summary
Modifier and TypeMethodDescriptionboolean
didRun()
Returns true if the client runnable was runstatic <T> ExpiringSwingTimer
Calls the given consumer with the non-null value returned from the given supplier.boolean
Returns true the initial expiration period has passedstatic ExpiringSwingTimer
runWhen
(BooleanSupplier isReady, int expireMs, 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 Details
-
ExpiringSwingTimer
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
expireMs
- the amount of time past which the code will not be runisReady
- true if the code should be runrunnable
- the code to run
-
-
Method Details
-
runWhen
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
-
get
Calls the given consumer with the non-null value returned from the given supplier. 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.- Type Parameters:
T
- the type used by the supplier and consumer- Parameters:
supplier
- the supplier of the desired valueexpireMs
- the amount of time past which the code will not be runconsumer
- the consumer to be called with the supplier's value- 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
- Specified by:
setTimerCallback
in interfaceGhidraTimer
- Overrides:
setTimerCallback
in classGhidraSwingTimer
-