Interface TextGUI
- 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 interfaceListener interface for TextGUI, firing on events related to the overall GUI -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(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 theScreenfor thisWindowBasedTextGUIgetTheme()Returns the theme currently assigned to thisTextGUIbooleanThis method can be used to determine if any component has requested a redraw.booleanDrains the input queue and passes the key strokes to the GUI system for processing.voidremoveListener(TextGUI.Listener listener) Removes a listener from this TextGUI so that it will no longer receive eventsvoidSets the global theme to be used by this TextGUI.voidsetVirtualScreenEnabled(boolean virtualScreenEnabled) This method controls whether or not the virtual screen should be used.voidUpdates the screen, to make any changes visible to the user.
-
Method Details
-
getTheme
-
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:
trueif at least one key stroke was read and processed,falseif 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 theScreenfor thisWindowBasedTextGUI- Returns:
- the
Screenused 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:
trueif 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 istrueby 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
TextGUIThreadimplementation 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
-