All Downloads are FREE. Search and download functionalities are using the official Maven repository.

us.ihmc.simulationconstructionset.gui.EventDispatchThreadHelper Maven / Gradle / Ivy

There is a newer version: 0.25.2
Show newest version
package us.ihmc.simulationconstructionset.gui;

import javax.swing.SwingUtilities;

public class EventDispatchThreadHelper
{
   public static void checkThatInEventDispatchThread()
   {
      if (!SwingUtilities.isEventDispatchThread())
      {
         throw new RuntimeException("Should only call this method from the Swing Event Dispatch Thread");
      }
   }

   public static void invokeAndWait(Runnable runnable)
   {
      if (SwingUtilities.isEventDispatchThread())
      {
         runnable.run();
      }
      else
      {
         try
         {
            SwingUtilities.invokeAndWait(runnable);
         }
         catch (Exception e)
         {
            throw new RuntimeException(e);
         }
      }
   }

   public static void justRun(Runnable runnable)
   {
      runnable.run();
   }

   public static void invokeLater(Runnable runnable)
   {
      if (SwingUtilities.isEventDispatchThread())
      {
         runnable.run();
      }
      else
      {
         SwingUtilities.invokeLater(runnable);
      }
   }
}




© 2015 - 2024 Weber Informatics LLC | Privacy Policy