Class SeparateTextGUIThread
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 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:
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic classFactory class for creating SeparateTextGUIThread objectsNested classes/interfaces inherited from interface AsynchronousTextGUIThread
AsynchronousTextGUIThread.StateNested classes/interfaces inherited from interface TextGUIThread
TextGUIThread.ExceptionHandler -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate AsynchronousTextGUIThread.Stateprivate final Threadprivate final CountDownLatchFields inherited from class AbstractTextGUIThread
customTasks, exceptionHandler, textGUI -
Constructor Summary
Constructors -
Method Summary
Modifier and TypeMethodDescriptiongetState()Returns the current status of this GUI threadReturns the Java thread which is processing GUI events and updating the screenvoidinvokeLater(Runnable runnable) Invokes custom code on the GUI thread.private voidvoidstart()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 exitvoidBlocks until the GUI loop has stoppedvoidwaitForStop(long time, TimeUnit unit) Blocks until the GUI loop has stoppedMethods inherited from class AbstractTextGUIThread
invokeAndWait, processEventsAndUpdate, setExceptionHandlerMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TextGUIThread
invokeAndWait, processEventsAndUpdate, setExceptionHandler
-
Field Details
-
state
-
textGUIThread
-
waitLatch
-
-
Constructor Details
-
SeparateTextGUIThread
-
-
Method Details
-
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
Description copied from interface:AsynchronousTextGUIThreadBlocks until the GUI loop has stopped- Specified by:
waitForStopin interfaceAsynchronousTextGUIThread- Throws:
InterruptedException- In case this thread was interrupted while waiting for the GUI thread to exit
-
waitForStop
Description copied from interface:AsynchronousTextGUIThreadBlocks until the GUI loop has stopped- Specified by:
waitForStopin interfaceAsynchronousTextGUIThread- Throws:
InterruptedException- In case this thread was interrupted while waiting for the GUI thread to exit
-
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
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
Description 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:
IllegalStateException- If the GUI thread is not running
-
mainGUILoop
private void mainGUILoop()
-