Class AbstractTextGUIThread

java.lang.Object
com.googlecode.lanterna.gui2.AbstractTextGUIThread
All Implemented Interfaces:
TextGUIThread
Direct Known Subclasses:
SameTextGUIThread, SeparateTextGUIThread

public abstract class AbstractTextGUIThread extends Object implements TextGUIThread
Abstract implementation of TextGUIThread with common logic for both available concrete implementations.
  • Field Details

  • Constructor Details

  • Method Details

    • invokeLater

      public void invokeLater(Runnable runnable) throws IllegalStateException
      Description copied from interface: TextGUIThread
      Invokes custom code on the GUI thread. Even if the current thread is the GUI thread, the code will be executed at a later time when the event processing is done.
      Specified by:
      invokeLater in interface TextGUIThread
      Parameters:
      runnable - Code to run asynchronously
      Throws:
      IllegalStateException - If the GUI thread is not running
    • setExceptionHandler

      public void setExceptionHandler(TextGUIThread.ExceptionHandler exceptionHandler)
      Description copied from interface: TextGUIThread
      Updates the exception handler used by this TextGUIThread. The exception handler will be invoked when an exception occurs in the main event loop. You can then decide how to log this exception and if you want to terminate the thread or not.
      Specified by:
      setExceptionHandler in interface TextGUIThread
      Parameters:
      exceptionHandler - Handler to inspect exceptions
    • processEventsAndUpdate

      public boolean processEventsAndUpdate() throws IOException
      Description copied from interface: TextGUIThread
      Main method to call when you are managing the event/input/update loop yourself. This method will run one round through the GUI's event/input queue and update the visuals if required. If the operation did nothing (returning false) you could sleep for a millisecond and then try again. If you use SameTextGUIThread you must either call this method directly to make the GUI update or use one of the methods on WindowBasedTextGUI that blocks until a particular window has closed.
      Specified by:
      processEventsAndUpdate in interface TextGUIThread
      Returns:
      true if there was anything to process or the GUI was updated, otherwise false
      Throws:
      IOException - If there was an I/O error when processing and updating the GUI
    • invokeAndWait

      public void invokeAndWait(Runnable runnable) throws IllegalStateException, InterruptedException
      Description copied from interface: TextGUIThread
      Schedules custom code to be executed on the GUI thread and waits until the code has been executed before returning. If this is run on the GUI thread, it will immediately run the Runnable and then return.
      Specified by:
      invokeAndWait in interface TextGUIThread
      Parameters:
      runnable - Code to be run and waited for completion before this method returns
      Throws:
      IllegalStateException - If the GUI thread is not running
      InterruptedException - If the caller thread was interrupted while waiting for the task to be executed