- 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 class
SeparateTextGUIThread.Factory
Factory 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.State
state
private java.lang.Thread
textGUIThread
private java.util.concurrent.CountDownLatch
waitLatch
-
Fields inherited from class com.googlecode.lanterna.gui2.AbstractTextGUIThread
customTasks, exceptionHandler, textGUI
-
-
Constructor Summary
Constructors Modifier Constructor Description private
SeparateTextGUIThread(TextGUI textGUI)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description AsynchronousTextGUIThread.State
getState()
Returns the current status of this GUI threadjava.lang.Thread
getThread()
Returns the Java thread which is processing GUI events and updating the screenvoid
invokeLater(java.lang.Runnable runnable)
Invokes custom code on the GUI thread.private void
mainGUILoop()
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
waitForStop()
Blocks until the GUI loop has stoppedvoid
waitForStop(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: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
public void waitForStop() throws java.lang.InterruptedException
Description copied from interface:AsynchronousTextGUIThread
Blocks until the GUI loop has stopped- Specified by:
waitForStop
in 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.InterruptedException
Description copied from interface:AsynchronousTextGUIThread
Blocks until the GUI loop has stopped- Specified by:
waitForStop
in 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:AsynchronousTextGUIThread
Returns the current status of this GUI thread- Specified by:
getState
in interfaceAsynchronousTextGUIThread
- Returns:
- Current status of the GUI thread
-
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 interfaceTextGUIThread
- 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 interfaceTextGUIThread
- Overrides:
invokeLater
in classAbstractTextGUIThread
- Parameters:
runnable
- Code to run asynchronously- Throws:
java.lang.IllegalStateException
- If the GUI thread is not running
-
mainGUILoop
private void mainGUILoop()
-
-