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 class
Factory class for creating SeparateTextGUIThread objectsNested 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
FieldsModifier and TypeFieldDescriptionprivate AsynchronousTextGUIThread.State
private final Thread
private final CountDownLatch
Fields inherited from class com.googlecode.lanterna.gui2.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 screenvoid
invokeLater
(Runnable runnable) Invokes custom code on the GUI thread.private void
void
start()
Starts the AsynchronousTextGUIThread, typically meaning that the event processing loop will start.void
stop()
Requests that the AsynchronousTextGUIThread stops, typically meaning that the event processing loop will exitvoid
Blocks until the GUI loop has stoppedvoid
waitForStop
(long time, TimeUnit unit) Blocks until the GUI loop has stoppedMethods 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 Details
-
state
-
textGUIThread
-
waitLatch
-
-
Constructor Details
-
SeparateTextGUIThread
-
-
Method Details
-
start
public void start()Description copied from interface:AsynchronousTextGUIThread
Starts the AsynchronousTextGUIThread, typically meaning that the event processing loop will start.- Specified by:
start
in interfaceAsynchronousTextGUIThread
-
stop
public void stop()Description copied from interface:AsynchronousTextGUIThread
Requests that the AsynchronousTextGUIThread stops, typically meaning that the event processing loop will exit- Specified by:
stop
in interfaceAsynchronousTextGUIThread
-
waitForStop
Description copied from interface:AsynchronousTextGUIThread
Blocks until the GUI loop has stopped- Specified by:
waitForStop
in interfaceAsynchronousTextGUIThread
- Throws:
InterruptedException
- In case this thread was interrupted while waiting for the GUI thread to exit
-
waitForStop
Description copied from interface:AsynchronousTextGUIThread
Blocks until the GUI loop has stopped- Specified by:
waitForStop
in interfaceAsynchronousTextGUIThread
- Throws:
InterruptedException
- In case this thread was interrupted while waiting for the GUI thread to exit
-
getState
Description copied from interface:AsynchronousTextGUIThread
Returns the current status of this GUI thread- Specified by:
getState
in interfaceAsynchronousTextGUIThread
- Returns:
- Current status of the GUI thread
-
getThread
Description copied from interface:TextGUIThread
Returns the Java thread which is processing GUI events and updating the screen- Specified by:
getThread
in interfaceTextGUIThread
- Returns:
- Thread which is processing events and updating the screen
-
invokeLater
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 interfaceTextGUIThread
- Overrides:
invokeLater
in classAbstractTextGUIThread
- Parameters:
runnable
- Code to run asynchronously- Throws:
IllegalStateException
- If the GUI thread is not running
-
mainGUILoop
private void mainGUILoop()
-