Package ghidra.util.task
Class AbstractSwingUpdateManager
- java.lang.Object
-
- ghidra.util.task.AbstractSwingUpdateManager
-
- Direct Known Subclasses:
BufferedSwingRunner
,SwingUpdateManager
public abstract class AbstractSwingUpdateManager extends java.lang.Object
A base class to allow clients to buffer events. UI components may receive numbers events to make changes to their underlying data model. Further, for many of these clients, it is sufficient to perform one update to capture all of the changes. In this scenario, the client can use this class to keep pushing off internal updates until: 1) the flurry of events has settled down, or 2) some specified amount of time has expired.The various methods dictate when the client will get a callback:
update()
- if this is the first call toupdate
, then do the work immediately; otherwise, buffer the update request until the timeout has expired.updateNow()
- perform the callback now.updateLater()
- buffer the update request until the timeout has expired.- Non-blocking update now - this is a conceptual use-case, where the client wishes to perform an
immediate update, but not during the current Swing event. To achieve
this, you could call something like:
SwingUtilities.invokeLater(() -> updateManager.updateNow());
This class is safe to use in a multi-threaded environment. State variables are guarded via synchronization on this object. The Swing thread is used to perform updates, which guarantees that only one update will happen at a time.
-
-
Field Summary
Fields Modifier and Type Field Description static int
DEFAULT_MAX_DELAY
static int
DEFAULT_MIN_DELAY
protected static java.lang.String
DEFAULT_NAME
protected boolean
isWorking
protected static int
MIN_DELAY_FLOOR
protected static long
NONE
protected javax.swing.Timer
timer
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractSwingUpdateManager()
Constructs a new SwingUpdateManager with default values for min and max delay.protected
AbstractSwingUpdateManager(int minDelay)
Constructs a new AbstractSwingUpdateManagerprotected
AbstractSwingUpdateManager(int minDelay, int maxDelay)
Constructs a new AbstractSwingUpdateManagerprotected
AbstractSwingUpdateManager(int minDelay, int maxDelay, java.lang.String name)
Constructs a new AbstractSwingUpdateManager
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
checkForWork()
void
dispose()
void
flush()
Causes this run manager to run if it has a pending updateboolean
hasPendingUpdates()
Returns true if there is a pending request that hasn't started yet.boolean
isBusy()
Returns true if any work is being performed or if there is buffered workboolean
isDisposed()
protected void
scheduleCheckForWork()
void
stop()
Signals to stop any buffered work.protected abstract void
swingDoWork()
The subclass callback to perform work.java.lang.String
toString()
java.lang.String
toStringDebug()
protected void
update()
Signals to perform an update.protected void
updateLater()
Signals to perform an update.protected void
updateNow()
Signals to perform an update.
-
-
-
Field Detail
-
NONE
protected static final long NONE
- See Also:
- Constant Field Values
-
DEFAULT_MAX_DELAY
public static final int DEFAULT_MAX_DELAY
- See Also:
- Constant Field Values
-
MIN_DELAY_FLOOR
protected static final int MIN_DELAY_FLOOR
- See Also:
- Constant Field Values
-
DEFAULT_MIN_DELAY
public static final int DEFAULT_MIN_DELAY
- See Also:
- Constant Field Values
-
DEFAULT_NAME
protected static final java.lang.String DEFAULT_NAME
-
timer
protected final javax.swing.Timer timer
-
isWorking
protected boolean isWorking
-
-
Constructor Detail
-
AbstractSwingUpdateManager
protected AbstractSwingUpdateManager()
Constructs a new SwingUpdateManager with default values for min and max delay. SeeDEFAULT_MIN_DELAY
and 30000.
-
AbstractSwingUpdateManager
protected AbstractSwingUpdateManager(int minDelay)
Constructs a new AbstractSwingUpdateManagerNote: The
minDelay
will always be at leastMIN_DELAY_FLOOR
, regardless of the given value.- Parameters:
minDelay
- the minimum number of milliseconds to wait once the event stream stops coming in before actually updating the screen
-
AbstractSwingUpdateManager
protected AbstractSwingUpdateManager(int minDelay, int maxDelay)
Constructs a new AbstractSwingUpdateManagerNote: The
minDelay
will always be at leastMIN_DELAY_FLOOR
, regardless of the given value.- Parameters:
minDelay
- the minimum number of milliseconds to wait once the event stream stops coming in before actually updating the screen.maxDelay
- the maximum amount of time to wait between gui updates.
-
AbstractSwingUpdateManager
protected AbstractSwingUpdateManager(int minDelay, int maxDelay, java.lang.String name)
Constructs a new AbstractSwingUpdateManagerNote: The
minDelay
will always be at leastMIN_DELAY_FLOOR
, regardless of the given value.- Parameters:
minDelay
- the minimum number of milliseconds to wait once the event stream stops coming in before actually updating the screen.maxDelay
- the maximum amount of time to wait between gui updates.name
- The name of this update manager; this allows for selective trace logging
-
-
Method Detail
-
swingDoWork
protected abstract void swingDoWork()
The subclass callback to perform work.
-
update
protected void update()
Signals to perform an update. See the class header for the usage of the various update methods.
-
updateLater
protected void updateLater()
Signals to perform an update. See the class header for the usage of the various update methods.
-
updateNow
protected void updateNow()
Signals to perform an update. See the class header for the usage of the various update methods.
-
flush
public void flush()
Causes this run manager to run if it has a pending update
-
stop
public void stop()
Signals to stop any buffered work. This will not stop any in-progress work.
-
hasPendingUpdates
public boolean hasPendingUpdates()
Returns true if there is a pending request that hasn't started yet. Any currently executing requests will not affect this call.- Returns:
- true if there is a pending request that hasn't started yet.
-
isBusy
public boolean isBusy()
Returns true if any work is being performed or if there is buffered work- Returns:
- true if any work is being performed or if there is buffered work
-
dispose
public void dispose()
-
isDisposed
public boolean isDisposed()
-
toString
public java.lang.String toString()
- Overrides:
toString
in classjava.lang.Object
-
toStringDebug
public java.lang.String toStringDebug()
-
checkForWork
protected void checkForWork()
-
scheduleCheckForWork
protected void scheduleCheckForWork()
-
-