Package ghidra.util
Class Swing
java.lang.Object
ghidra.util.Swing
A utility class to handle running code on the AWT Event Dispatch Thread
-
Field Summary
-
Method Summary
Modifier and TypeMethodDescriptionstatic void
Wait until AWT event queue (Swing) has been flushed and no more (to a point) events are pending.static boolean
assertSwingThread
(String errorMessage) Logs a stack trace if the current calling thread is not the Swing threadstatic boolean
Returns true if this is the event dispatch thread.static void
Runs the given runnable now if the caller is on the Swing thread.static void
Calls the given runnable on the Swing thread in the future by putting the request on the back of the event queue.static void
Calls the given runnable on the Swing threadstatic void
Calls the given runnable on the Swing threadstatic <T> T
Calls the given suppler on the Swing thread, blocking with aSwingUtilities.invokeAndWait(Runnable)
if not on the Swing thread.
-
Field Details
-
GSWING_THREAD_POOL_NAME
- See Also:
-
-
Method Details
-
isSwingThread
public static boolean isSwingThread()Returns true if this is the event dispatch thread. Note that this method returns true in headless mode because any thread in headless mode can dispatch its own events. In swing environments, the swing thread is usually used to dispatch events.- Returns:
- true if this is the event dispatch thread -OR- is in headless mode.
-
allowSwingToProcessEvents
public static void allowSwingToProcessEvents()Wait until AWT event queue (Swing) has been flushed and no more (to a point) events are pending. -
assertSwingThread
Logs a stack trace if the current calling thread is not the Swing thread- Parameters:
errorMessage
- The message to display when not on the Swing thread- Returns:
- true if the calling thread is the Swing thread
-
runLater
Calls the given runnable on the Swing thread in the future by putting the request on the back of the event queue.- Parameters:
r
- the runnable
-
runIfSwingOrRunLater
Runs the given runnable now if the caller is on the Swing thread. Otherwise, the runnable will be posted later.- Parameters:
r
- the runnable
-
runNow
Calls the given suppler on the Swing thread, blocking with aSwingUtilities.invokeAndWait(Runnable)
if not on the Swing thread.Use this method when you are not on the Swing thread and you need to get a value that is managed/synchronized by the Swing thread.
String value = runNow(() -> label.getText());
- Parameters:
s
- the supplier that will be called on the Swing thread- Returns:
- the result of the supplier
- See Also:
-
runNow
Calls the given runnable on the Swing thread- Parameters:
r
- the runnable- See Also:
-
runNow
Calls the given runnable on the Swing threadThis method will throw an exception if the Swing thread is not available within the given timeout. This method is useful for preventing deadlocks.
- Parameters:
r
- the runnabletimeout
- the timeout valueunit
- the time unit of the timeout value- Throws:
UnableToSwingException
- if the timeout was reach waiting for the Swing thread- See Also:
-