TextGUI
MultiWindowTextGUI
public abstract class AbstractTextGUI extends Object implements TextGUI
TextGUI.Listener
Modifier | Constructor | Description |
---|---|---|
protected |
AbstractTextGUI(TextGUIThreadFactory textGUIThreadFactory,
Screen screen) |
Constructor for
AbstractTextGUI that requires a Screen and a factory for creating the GUI thread |
Modifier and Type | Method | Description |
---|---|---|
void |
addListener(TextGUI.Listener listener) |
Adds a listener to this TextGUI to fire events on.
|
protected abstract void |
drawGUI(TextGUIGraphics graphics) |
Draws the entire GUI using a
TextGUIGraphics object |
protected boolean |
fireUnhandledKeyStroke(KeyStroke keyStroke) |
This method should be called when there was user input that wasn't handled by the GUI.
|
protected abstract TerminalPosition |
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.
|
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 calling
processInput() and updateScreen() . |
Screen |
getScreen() |
Returns the
Screen for this WindowBasedTextGUI |
Theme |
getTheme() |
Returns the theme currently assigned to this
TextGUI |
protected abstract boolean |
handleInput(KeyStroke key) |
This method should take the user input and feed it to the focused component for handling.
|
protected void |
invalidate() |
Marks the whole text GUI as invalid and that it needs to be redrawn at next opportunity
|
boolean |
isBlockingIO() |
Checks if blocking I/O is enabled or not
|
boolean |
isPendingUpdate() |
This method can be used to determine if any component has requested a redraw.
|
protected KeyStroke |
pollInput() |
Polls the underlying input queue for user input, returning either a
KeyStroke or null |
boolean |
processInput() |
Drains the input queue and passes the key strokes to the GUI system for processing.
|
protected KeyStroke |
readKeyStroke() |
Reads one key from the input queue, blocking or non-blocking depending on if blocking I/O has been enabled.
|
void |
removeListener(TextGUI.Listener listener) |
Removes a listener from this TextGUI so that it will no longer receive events
|
void |
setBlockingIO(boolean blockingIO) |
Enables blocking I/O, causing calls to
readKeyStroke() to block until there is input available. |
void |
setTheme(Theme theme) |
Sets the global theme to be used by this TextGUI.
|
void |
updateScreen() |
Updates the screen, to make any changes visible to the user.
|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
getFocusedInteractable, setVirtualScreenEnabled
protected AbstractTextGUI(TextGUIThreadFactory textGUIThreadFactory, Screen screen)
AbstractTextGUI
that requires a Screen
and a factory for creating the GUI threadtextGUIThreadFactory
- Factory class to use for creating the TextGUIThread
classscreen
- What underlying Screen
to use for this text GUIprotected KeyStroke readKeyStroke() throws IOException
setBlockingIO(true)
.KeyStroke
or null
if blocking I/O is disabled and there was
no input waitingIOException
- In case of an I/O error while reading inputprotected KeyStroke pollInput() throws IOException
KeyStroke
or null
KeyStroke
representing the user input or null
if there was noneIOException
- In case of an I/O error while reading inputpublic boolean processInput() throws IOException
TextGUI
processInput
in interface TextGUI
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)IOException
- In case there was an underlying I/O errorEOFException
- In the input stream received an EOF markerpublic void setTheme(Theme theme)
TextGUI
public Theme getTheme()
TextGUI
TextGUI
public void updateScreen() throws IOException
TextGUI
updateScreen
in interface TextGUI
IOException
- In case there was an underlying I/O errorpublic Screen getScreen()
TextGUI
Screen
for this WindowBasedTextGUI
getScreen
in interface TextGUI
Screen
used by this WindowBasedTextGUI
public boolean isPendingUpdate()
TextGUI
true
, you may want to call updateScreen()
.isPendingUpdate
in interface TextGUI
true
if this TextGUI has a change and is waiting for someone to call updateScreen()
public TextGUIThread getGUIThread()
TextGUI
processInput()
and updateScreen()
. After the
initial call, it will return the same object as it was originally returning.getGUIThread
in interface TextGUI
TextGUIThread
implementation that can be used to asynchronously manage the GUIpublic void addListener(TextGUI.Listener listener)
TextGUI
addListener
in interface TextGUI
listener
- Listener to addpublic void removeListener(TextGUI.Listener listener)
TextGUI
removeListener
in interface TextGUI
listener
- Listener to removepublic void setBlockingIO(boolean blockingIO)
readKeyStroke()
to block until there is input available. Notice
that you can still poll for input using pollInput()
.blockingIO
- Set this to true
if blocking I/O should be enabled, otherwise false
public boolean isBlockingIO()
true
if blocking I/O is enabled, otherwise false
protected final boolean fireUnhandledKeyStroke(KeyStroke keyStroke)
onUnhandledKeyStroke(..)
method on any registered listener.keyStroke
- The KeyStroke
that wasn't handled by the GUItrue
if at least one of the listeners handled the key stroke, this will signal to the GUI that it
needs to be redrawn again.protected void invalidate()
protected abstract void drawGUI(TextGUIGraphics graphics)
TextGUIGraphics
objectgraphics
- Graphics object to draw usingprotected abstract TerminalPosition getCursorPosition()
null
if the cursor should be hiddenprotected abstract boolean handleInput(KeyStroke key)
key
- KeyStroke
representing the user inputtrue
if the input was recognized and handled by the GUI, indicating that the GUI should be redrawnCopyright © 2020. All rights reserved.