- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractTextGUIThread
-
- All Implemented Interfaces:
TextGUIThread
- Direct Known Subclasses:
SameTextGUIThread,SeparateTextGUIThread
public abstract class AbstractTextGUIThread extends java.lang.Object implements TextGUIThread
Abstract implementation ofTextGUIThreadwith common logic for both available concrete implementations.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.TextGUIThread
TextGUIThread.ExceptionHandler
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.Queue<java.lang.Runnable>customTasksprotected TextGUIThread.ExceptionHandlerexceptionHandlerprotected TextGUItextGUI
-
Constructor Summary
Constructors Constructor Description AbstractTextGUIThread(TextGUI textGUI)Sets up thisAbstractTextGUIThreadfor operations on the suppliesTextGUI
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidinvokeAndWait(java.lang.Runnable runnable)Schedules custom code to be executed on the GUI thread and waits until the code has been executed before returning.voidinvokeLater(java.lang.Runnable runnable)Invokes custom code on the GUI thread.booleanprocessEventsAndUpdate()Main method to call when you are managing the event/input/update loop yourself.voidsetExceptionHandler(TextGUIThread.ExceptionHandler exceptionHandler)Updates the exception handler used by this TextGUIThread.-
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
getThread
-
-
-
-
Field Detail
-
textGUI
protected final TextGUI textGUI
-
customTasks
protected final java.util.Queue<java.lang.Runnable> customTasks
-
exceptionHandler
protected TextGUIThread.ExceptionHandler exceptionHandler
-
-
Constructor Detail
-
AbstractTextGUIThread
public AbstractTextGUIThread(TextGUI textGUI)
Sets up thisAbstractTextGUIThreadfor operations on the suppliesTextGUI- Parameters:
textGUI- Text GUI thisTextGUIThreadimplementations will be operating on
-
-
Method Detail
-
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- Parameters:
runnable- Code to run asynchronously- Throws:
java.lang.IllegalStateException- If the GUI thread is not running
-
setExceptionHandler
public void setExceptionHandler(TextGUIThread.ExceptionHandler exceptionHandler)
Description copied from interface:TextGUIThreadUpdates the exception handler used by this TextGUIThread. The exception handler will be invoked when an exception occurs in the main event loop. You can then decide how to log this exception and if you want to terminate the thread or not.- Specified by:
setExceptionHandlerin interfaceTextGUIThread- Parameters:
exceptionHandler- Handler to inspect exceptions
-
processEventsAndUpdate
public boolean processEventsAndUpdate() throws java.io.IOExceptionDescription copied from interface:TextGUIThreadMain method to call when you are managing the event/input/update loop yourself. This method will run one round through the GUI's event/input queue and update the visuals if required. If the operation did nothing (returningfalse) you could sleep for a millisecond and then try again. If you useSameTextGUIThreadyou must either call this method directly to make the GUI update or use one of the methods onWindowBasedTextGUIthat blocks until a particular window has closed.- Specified by:
processEventsAndUpdatein interfaceTextGUIThread- Returns:
trueif there was anything to process or the GUI was updated, otherwisefalse- Throws:
java.io.IOException- If there was an I/O error when processing and updating the GUI
-
invokeAndWait
public void invokeAndWait(java.lang.Runnable runnable) throws java.lang.IllegalStateException, java.lang.InterruptedExceptionDescription copied from interface:TextGUIThreadSchedules custom code to be executed on the GUI thread and waits until the code has been executed before returning. If this is run on the GUI thread, it will immediately run theRunnableand then return.- Specified by:
invokeAndWaitin interfaceTextGUIThread- Parameters:
runnable- Code to be run and waited for completion before this method returns- Throws:
java.lang.IllegalStateException- If the GUI thread is not runningjava.lang.InterruptedException- If the caller thread was interrupted while waiting for the task to be executed
-
-