- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractTextGUIThread
-
- com.googlecode.lanterna.gui2.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 callstart()for this. The GUI thread will stop ifstop()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
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classSeparateTextGUIThread.FactoryFactory class for creating SeparateTextGUIThread objects-
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.AsynchronousTextGUIThread
AsynchronousTextGUIThread.State
-
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.TextGUIThread
TextGUIThread.ExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description private AsynchronousTextGUIThread.Statestateprivate java.lang.ThreadtextGUIThreadprivate java.util.concurrent.CountDownLatchwaitLatch-
Fields inherited from class com.googlecode.lanterna.gui2.AbstractTextGUIThread
customTasks, exceptionHandler, textGUI
-
-
Constructor Summary
Constructors Modifier Constructor Description privateSeparateTextGUIThread(TextGUI textGUI)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsynchronousTextGUIThread.StategetState()Returns the current status of this GUI threadjava.lang.ThreadgetThread()Returns the Java thread which is processing GUI events and updating the screenvoidinvokeLater(java.lang.Runnable runnable)Invokes custom code on the GUI thread.private voidmainGUILoop()voidstart()Starts the AsynchronousTextGUIThread, typically meaning that the event processing loop will start.voidstop()Requests that the AsynchronousTextGUIThread stops, typically meaning that the event processing loop will exitvoidwaitForStop()Blocks until the GUI loop has stoppedvoidwaitForStop(long time, java.util.concurrent.TimeUnit unit)Blocks until the GUI loop has stopped-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractTextGUIThread
invokeAndWait, processEventsAndUpdate, setExceptionHandler
-
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
-
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUIThread
invokeAndWait, processEventsAndUpdate, setExceptionHandler
-
-
-
-
Field Detail
-
state
private volatile AsynchronousTextGUIThread.State state
-
textGUIThread
private final java.lang.Thread textGUIThread
-
waitLatch
private final java.util.concurrent.CountDownLatch waitLatch
-
-
Constructor Detail
-
SeparateTextGUIThread
private SeparateTextGUIThread(TextGUI textGUI)
-
-
Method Detail
-
start
public void start()
Description copied from interface:AsynchronousTextGUIThreadStarts the AsynchronousTextGUIThread, typically meaning that the event processing loop will start.- Specified by:
startin interfaceAsynchronousTextGUIThread
-
stop
public void stop()
Description copied from interface:AsynchronousTextGUIThreadRequests that the AsynchronousTextGUIThread stops, typically meaning that the event processing loop will exit- Specified by:
stopin interfaceAsynchronousTextGUIThread
-
waitForStop
public void waitForStop() throws java.lang.InterruptedExceptionDescription copied from interface:AsynchronousTextGUIThreadBlocks until the GUI loop has stopped- Specified by:
waitForStopin interfaceAsynchronousTextGUIThread- 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.InterruptedExceptionDescription copied from interface:AsynchronousTextGUIThreadBlocks until the GUI loop has stopped- Specified by:
waitForStopin interfaceAsynchronousTextGUIThread- Throws:
java.lang.InterruptedException- In case this thread was interrupted while waiting for the GUI thread to exit
-
getState
public AsynchronousTextGUIThread.State getState()
Description copied from interface:AsynchronousTextGUIThreadReturns the current status of this GUI thread- Specified by:
getStatein interfaceAsynchronousTextGUIThread- Returns:
- Current status of the GUI thread
-
getThread
public java.lang.Thread getThread()
Description copied from interface:TextGUIThreadReturns the Java thread which is processing GUI events and updating the screen- Specified by:
getThreadin interfaceTextGUIThread- Returns:
- Thread which is processing events and updating the screen
-
invokeLater
public void invokeLater(java.lang.Runnable runnable) throws java.lang.IllegalStateExceptionDescription copied from interface:TextGUIThreadInvokes 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:
invokeLaterin interfaceTextGUIThread- Overrides:
invokeLaterin classAbstractTextGUIThread- Parameters:
runnable- Code to run asynchronously- Throws:
java.lang.IllegalStateException- If the GUI thread is not running
-
mainGUILoop
private void mainGUILoop()
-
-