Class SeparateTextGUIThread

  • All Implemented Interfaces:
    AsynchronousTextGUIThread, TextGUIThread

    public class SeparateTextGUIThread
    extends AbstractTextGUIThread
    implements AsynchronousTextGUIThread
    Default implementation of TextGUIThread, this class runs the GUI event processing on a dedicated thread. The GUI needs to be explicitly started in order for the event processing loop to begin, so you must call start() for this. The GUI thread will stop if stop() is called, the input stream returns EOF or an exception is thrown from inside the event handling loop.

    Here is an example of how to use this TextGUIThread:

         
         MultiWindowTextGUI textGUI = new MultiWindowTextGUI(new SeparateTextGUIThread.Factory(), screen);
         // ... add components ...
         ((AsynchronousTextGUIThread)textGUI.getGUIThread()).start();
         // ... this thread will continue while the GUI runs on a separate thread ...
         
     
    See Also:
    TextGUIThread, SameTextGUIThread
    • Field Detail

      • textGUIThread

        private final java.lang.Thread textGUIThread
      • waitLatch

        private final java.util.concurrent.CountDownLatch waitLatch
    • Constructor Detail

      • SeparateTextGUIThread

        private SeparateTextGUIThread​(TextGUI textGUI)
    • Method Detail

      • waitForStop

        public void waitForStop()
                         throws java.lang.InterruptedException
        Description copied from interface: AsynchronousTextGUIThread
        Blocks until the GUI loop has stopped
        Specified by:
        waitForStop in interface AsynchronousTextGUIThread
        Throws:
        java.lang.InterruptedException - In case this thread was interrupted while waiting for the GUI thread to exit
      • waitForStop

        public void waitForStop​(long time,
                                java.util.concurrent.TimeUnit unit)
                         throws java.lang.InterruptedException
        Description copied from interface: AsynchronousTextGUIThread
        Blocks until the GUI loop has stopped
        Specified by:
        waitForStop in interface AsynchronousTextGUIThread
        Throws:
        java.lang.InterruptedException - In case this thread was interrupted while waiting for the GUI thread to exit
      • getThread

        public java.lang.Thread getThread()
        Description copied from interface: TextGUIThread
        Returns the Java thread which is processing GUI events and updating the screen
        Specified by:
        getThread in interface TextGUIThread
        Returns:
        Thread which is processing events and updating the screen
      • invokeLater

        public void invokeLater​(java.lang.Runnable runnable)
                         throws java.lang.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
        Overrides:
        invokeLater in class AbstractTextGUIThread
        Parameters:
        runnable - Code to run asynchronously
        Throws:
        java.lang.IllegalStateException - If the GUI thread is not running
      • mainGUILoop

        private void mainGUILoop()