Package ghidra.util

Class Swing

java.lang.Object
ghidra.util.Swing

public class Swing extends Object
A utility class to handle running code on the AWT Event Dispatch Thread
  • Field Details

  • 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

      public static boolean assertSwingThread(String errorMessage)
      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

      public static void runLater(Runnable r)
      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

      public static void runIfSwingOrRunLater(Runnable r)
      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

      public static <T> T runNow(Supplier<T> s)
      Calls the given suppler on the Swing thread, blocking with a SwingUtilities.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

      public static void runNow(Runnable r)
      Calls the given runnable on the Swing thread
      Parameters:
      r - the runnable
      See Also:
    • runNow

      public static void runNow(Runnable r, long timeout, TimeUnit unit) throws UnableToSwingException
      Calls the given runnable on the Swing thread

      This 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 runnable
      timeout - the timeout value
      unit - the time unit of the timeout value
      Throws:
      UnableToSwingException - if the timeout was reach waiting for the Swing thread
      See Also: