Class AbstractTextGUI
java.lang.Object
com.googlecode.lanterna.gui2.AbstractTextGUI
- All Implemented Interfaces:
TextGUI
- Direct Known Subclasses:
MultiWindowTextGUI
-
Nested Class Summary
Nested classes/interfaces inherited from interface TextGUI
TextGUI.Listener -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate booleanprivate Themeprivate final List<TextGUI.Listener> private final Screenprivate TextGUIThread -
Constructor Summary
ConstructorsModifierConstructorDescriptionprotectedAbstractTextGUI(TextGUIThreadFactory textGUIThreadFactory, Screen screen) Constructor forAbstractTextGUIthat requires aScreenand a factory for creating the GUI thread -
Method Summary
Modifier and TypeMethodDescriptionvoidaddListener(TextGUI.Listener listener) Adds a listener to this TextGUI to fire events on.protected abstract voiddrawGUI(TextGUIGraphics graphics) Draws the entire GUI using aTextGUIGraphicsobjectprotected final booleanfireUnhandledKeyStroke(KeyStroke keyStroke) This method should be called when there was user input that wasn't handled by the GUI.protected abstract TerminalPositionTop-level method for drilling in to the GUI and figuring out, in global coordinates, where to place the text cursor on the screen at this time.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().Returns theScreenfor thisWindowBasedTextGUIgetTheme()Returns the theme currently assigned to thisTextGUIprotected abstract booleanhandleInput(KeyStroke key) This method should take the user input and feed it to the focused component for handling.protected voidMarks the whole text GUI as invalid and that it needs to be redrawn at next opportunitybooleanChecks if blocking I/O is enabled or notbooleanThis method can be used to determine if any component has requested a redraw.protected KeyStrokePolls the underlying input queue for user input, returning either aKeyStrokeornullbooleanDrains the input queue and passes the key strokes to the GUI system for processing.protected KeyStrokeReads one key from the input queue, blocking or non-blocking depending on if blocking I/O has been enabled.voidremoveListener(TextGUI.Listener listener) Removes a listener from this TextGUI so that it will no longer receive eventsvoidsetBlockingIO(boolean blockingIO) Enables blocking I/O, causing calls toreadKeyStroke()to block until there is input available.voidSets the global theme to be used by this TextGUI.voidUpdates the screen, to make any changes visible to the user.Methods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface TextGUI
getFocusedInteractable, setVirtualScreenEnabled
-
Field Details
-
screen
-
listeners
-
blockingIO
private boolean blockingIO -
dirty
private boolean dirty -
textGUIThread
-
guiTheme
-
-
Constructor Details
-
AbstractTextGUI
Constructor forAbstractTextGUIthat requires aScreenand a factory for creating the GUI thread- Parameters:
textGUIThreadFactory- Factory class to use for creating theTextGUIThreadclassscreen- What underlyingScreento use for this text GUI
-
-
Method Details
-
readKeyStroke
Reads one key from the input queue, blocking or non-blocking depending on if blocking I/O has been enabled. To enable blocking I/O (disabled by default), usesetBlockingIO(true).- Returns:
- One piece of user input as a
KeyStrokeornullif blocking I/O is disabled and there was no input waiting - Throws:
IOException- In case of an I/O error while reading input
-
pollInput
Polls the underlying input queue for user input, returning either aKeyStrokeornull- Returns:
KeyStrokerepresenting the user input ornullif there was none- Throws:
IOException- In case of an I/O error while reading input
-
processInput
Description copied from interface:TextGUIDrains 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).- Specified by:
processInputin interfaceTextGUI- 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 error
-
setTheme
Description copied from interface:TextGUISets 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. -
getTheme
-
updateScreen
Description copied from interface:TextGUIUpdates the screen, to make any changes visible to the user.- Specified by:
updateScreenin interfaceTextGUI- Throws:
IOException- In case there was an underlying I/O error
-
getScreen
Description copied from interface:TextGUIReturns theScreenfor thisWindowBasedTextGUI- Specified by:
getScreenin interfaceTextGUI- Returns:
- the
Screenused by thisWindowBasedTextGUI
-
isPendingUpdate
public boolean isPendingUpdate()Description copied from interface:TextGUIThis method can be used to determine if any component has requested a redraw. If this method returnstrue, you may want to callupdateScreen().- Specified by:
isPendingUpdatein interfaceTextGUI- Returns:
trueif this TextGUI has a change and is waiting for someone to callupdateScreen()
-
getGUIThread
Description copied from interface:TextGUIThe 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.- Specified by:
getGUIThreadin interfaceTextGUI- Returns:
- A
TextGUIThreadimplementation that can be used to asynchronously manage the GUI
-
addListener
Description copied from interface:TextGUIAdds a listener to this TextGUI to fire events on.- Specified by:
addListenerin interfaceTextGUI- Parameters:
listener- Listener to add
-
removeListener
Description copied from interface:TextGUIRemoves a listener from this TextGUI so that it will no longer receive events- Specified by:
removeListenerin interfaceTextGUI- Parameters:
listener- Listener to remove
-
setBlockingIO
public void setBlockingIO(boolean blockingIO) Enables blocking I/O, causing calls toreadKeyStroke()to block until there is input available. Notice that you can still poll for input usingpollInput().- Parameters:
blockingIO- Set this totrueif blocking I/O should be enabled, otherwisefalse
-
isBlockingIO
public boolean isBlockingIO()Checks if blocking I/O is enabled or not- Returns:
trueif blocking I/O is enabled, otherwisefalse
-
fireUnhandledKeyStroke
This method should be called when there was user input that wasn't handled by the GUI. It will fire theonUnhandledKeyStroke(..)method on any registered listener.- Parameters:
keyStroke- TheKeyStrokethat wasn't handled by the GUI- Returns:
trueif at least one of the listeners handled the key stroke, this will signal to the GUI that it needs to be redrawn again.
-
invalidate
protected void invalidate()Marks the whole text GUI as invalid and that it needs to be redrawn at next opportunity -
drawGUI
Draws the entire GUI using aTextGUIGraphicsobject- Parameters:
graphics- Graphics object to draw using
-
getCursorPosition
Top-level method for drilling in to the GUI and figuring out, in global coordinates, where to place the text cursor on the screen at this time.- Returns:
- Where to place the text cursor, or
nullif the cursor should be hidden
-
handleInput
This method should take the user input and feed it to the focused component for handling.- Parameters:
key-KeyStrokerepresenting the user input- Returns:
trueif the input was recognized and handled by the GUI, indicating that the GUI should be redrawn
-