Class AwtUtils

java.lang.Object
org.pepsoft.util.AwtUtils

public class AwtUtils extends Object
Utility methods for working with the AWT. Created by pepijn on 16-04-15.
  • Constructor Details

    • AwtUtils

      public AwtUtils()
  • Method Details

    • resultOfOnEventThread

      public static <T> T resultOfOnEventThread(Callable<T> task)
      Execute a task on the event dispatch thread and return the result. The task may be executed on a different thread, so it must be thread-safe. Since it will block the event thread it should be short and to the point.
      Type Parameters:
      T - The type of the result to return.
      Parameters:
      task - The task to execute.
      Returns:
      The result of the task.
    • doOnEventThread

      public static void doOnEventThread(Runnable task)
      Execute a task on the even dispatch thread. The task may be executed on a different thread, so it must be thread-safe. Since it will block the event thread it should be short and to the point. If the current thread is not the event dispatch thread this method does not wait for the task to finish.
      Parameters:
      task - The task to execute.
    • doOnEventThreadAndWait

      public static void doOnEventThreadAndWait(Runnable task)
      Execute a task on the even dispatch thread and wait for it to finish. The task may be executed on a different thread, so it must be thread-safe. Since it will block the event thread it should be short and to the point.
      Parameters:
      task - The task to execute.
    • doLaterOnEventThread

      public static void doLaterOnEventThread(Runnable task)
      Schedule a task for later execution on the event dispatch thread and return immediately. The task may be executed on a different thread, so it must be thread-safe. Since it will block the event thread it should be short and to the point.
      Parameters:
      task - The task to execute.
    • doLaterOnEventThread

      public static void doLaterOnEventThread(String key, int delay, Runnable task)
      Schedule a task for later execution on the event dispatch thread and return immediately. The task may be executed on a different thread, so it must be thread-safe. Since it will block the event thread it should be short and to the point.

      If a task with the same key is already scheduled and has not yet executed that will be superseded.

      Parameters:
      key - The unique key of the task. Scheduling a task will supersede a task with the same key that is already scheduled.
      delay - The minimum number of milliseconds after which the task should be executed.
      task - The task to execute.