- All Known Subinterfaces:
WindowBasedTextGUI
- All Known Implementing Classes:
AbstractTextGUI
,MultiWindowTextGUI
public interface TextGUI
This is the base interface for advanced text GUIs supported in Lanterna. You may want to use this in combination with
a TextGUIThread, that can be created/retrieved by using
getGUIThread()
.-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic interface
Listener interface for TextGUI, firing on events related to the overall GUI -
Method Summary
Modifier and TypeMethodDescriptionvoid
addListener
(TextGUI.Listener listener) Adds a listener to this TextGUI to fire events on.Returns the interactable component currently in focusThe first time this method is called, it will create a new TextGUIThread object that you can use to automatically manage this TextGUI instead of manually callingprocessInput()
andupdateScreen()
.Returns theScreen
for thisWindowBasedTextGUI
getTheme()
Returns the theme currently assigned to thisTextGUI
boolean
This method can be used to determine if any component has requested a redraw.boolean
Drains the input queue and passes the key strokes to the GUI system for processing.void
removeListener
(TextGUI.Listener listener) Removes a listener from this TextGUI so that it will no longer receive eventsvoid
Sets the global theme to be used by this TextGUI.void
setVirtualScreenEnabled
(boolean virtualScreenEnabled) This method controls whether or not the virtual screen should be used.void
Updates the screen, to make any changes visible to the user.
-
Method Details
-
getTheme
Theme getTheme()Returns the theme currently assigned to thisTextGUI
- Returns:
- Currently active
Theme
-
setTheme
Sets the global theme to be used by this TextGUI. This value will be set on every TextGUIGraphics object created for drawing the GUI, but individual components can override this if they want. If you don't call this method you should assume that a default theme is assigned by the library.- Parameters:
theme
- Theme to use as the default theme for this TextGUI
-
processInput
Drains the input queue and passes the key strokes to the GUI system for processing. For window-based system, it will send each key stroke to the active window for processing. If the input read gives an EOF, it will throw EOFException and this is normally the signal to shut down the GUI (any command coming in before the EOF will be processed as usual before this).- Returns:
true
if at least one key stroke was read and processed,false
if there was nothing on the input queue (only for non-blocking IO)- Throws:
IOException
- In case there was an underlying I/O errorEOFException
- In the input stream received an EOF marker
-
getScreen
Screen getScreen()Returns theScreen
for thisWindowBasedTextGUI
- Returns:
- the
Screen
used by thisWindowBasedTextGUI
-
updateScreen
Updates the screen, to make any changes visible to the user.- Throws:
IOException
- In case there was an underlying I/O error
-
isPendingUpdate
boolean isPendingUpdate()This method can be used to determine if any component has requested a redraw. If this method returnstrue
, you may want to callupdateScreen()
.- Returns:
true
if this TextGUI has a change and is waiting for someone to callupdateScreen()
-
setVirtualScreenEnabled
void setVirtualScreenEnabled(boolean virtualScreenEnabled) This method controls whether or not the virtual screen should be used. This is what enabled you to make your UI larger than what fits the terminal, as it will expand the virtual area and put in scrollbars. If set tofalse
, the virtual screen will be bypassed and any content outside of the screen will be cropped. This property istrue
by default.- Parameters:
virtualScreenEnabled
- Iftrue
, then virtual screen will be used, otherwise it is bypassed
-
getGUIThread
TextGUIThread getGUIThread()The first time this method is called, it will create a new TextGUIThread object that you can use to automatically manage this TextGUI instead of manually callingprocessInput()
andupdateScreen()
. After the initial call, it will return the same object as it was originally returning.- Returns:
- A
TextGUIThread
implementation that can be used to asynchronously manage the GUI
-
getFocusedInteractable
Interactable getFocusedInteractable()Returns the interactable component currently in focus- Returns:
- Component that is currently in input focus
-
addListener
Adds a listener to this TextGUI to fire events on.- Parameters:
listener
- Listener to add
-
removeListener
Removes a listener from this TextGUI so that it will no longer receive events- Parameters:
listener
- Listener to remove
-