-
- All Known Subinterfaces:
AsynchronousTextGUIThread
- All Known Implementing Classes:
AbstractTextGUIThread
,SameTextGUIThread
,SeparateTextGUIThread
public interface TextGUIThread
Class that represents the thread this is expected to run the event/input/update loop for theTextGUI
. There are mainly two implementations of this interface, one for having lanterna automatically spawn a new thread for doing all the processing and leaving the creator thread free to do other things, and one that assumes the creator thread will hand over control to lanterna for as long as the GUI is running.- See Also:
SameTextGUIThread
,SeparateTextGUIThread
-
-
Nested Class Summary
Nested Classes Modifier and Type Interface Description static interface
TextGUIThread.ExceptionHandler
This interface defines an exception handler, that is used for looking at exceptions that occurs during the main event loop of the TextGUIThread.
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description java.lang.Thread
getThread()
Returns the Java thread which is processing GUI events and updating the screenvoid
invokeAndWait(java.lang.Runnable runnable)
Schedules custom code to be executed on the GUI thread and waits until the code has been executed before returning.void
invokeLater(java.lang.Runnable runnable)
Invokes custom code on the GUI thread.boolean
processEventsAndUpdate()
Main method to call when you are managing the event/input/update loop yourself.void
setExceptionHandler(TextGUIThread.ExceptionHandler exceptionHandler)
Updates the exception handler used by this TextGUIThread.
-
-
-
Method Detail
-
invokeLater
void invokeLater(java.lang.Runnable runnable) throws java.lang.IllegalStateException
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.- Parameters:
runnable
- Code to run asynchronously- Throws:
java.lang.IllegalStateException
- If the GUI thread is not running
-
processEventsAndUpdate
boolean processEventsAndUpdate() throws java.io.IOException
Main 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 useSameTextGUIThread
you must either call this method directly to make the GUI update or use one of the methods onWindowBasedTextGUI
that blocks until a particular window has closed.- Returns:
true
if 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
void invokeAndWait(java.lang.Runnable runnable) throws java.lang.IllegalStateException, java.lang.InterruptedException
Schedules 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 theRunnable
and then return.- 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
-
setExceptionHandler
void setExceptionHandler(TextGUIThread.ExceptionHandler exceptionHandler)
Updates 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.- Parameters:
exceptionHandler
- Handler to inspect exceptions
-
getThread
java.lang.Thread getThread()
Returns the Java thread which is processing GUI events and updating the screen- Returns:
- Thread which is processing events and updating the screen
-
-