java.lang.Object
com.googlecode.lanterna.gui2.AbstractTextGUI
com.googlecode.lanterna.gui2.MultiWindowTextGUI
- All Implemented Interfaces:
TextGUI
,WindowBasedTextGUI
This is the main Text GUI implementation built into Lanterna, supporting multiple tiled windows and a dynamic
background area that can be fully customized. If you want to create a text-based GUI with windows and controls,
it's very likely this is what you want to use.
Note: This class used to always wrap the Screen
object with a VirtualScreen
to ensure that the UI
always fits. As of 3.1.0, we don't do this anymore so when you create the MultiWindowTextGUI
you can wrap
the screen parameter yourself if you want to keep this behavior.
-
Nested Class Summary
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.TextGUI
TextGUI.Listener
-
Field Summary
FieldsModifier and TypeFieldDescriptionprivate final BasePane
private TerminalPosition
private boolean
private TerminalPosition
private final WindowPostRenderer
private Window
private final WindowList
private final WindowManager
private final IdentityHashMap
<Window, TextImage> -
Constructor Summary
ConstructorsConstructorDescriptionMultiWindowTextGUI
(TextGUIThreadFactory guiThreadFactory, Screen screen) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations.MultiWindowTextGUI
(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations.MultiWindowTextGUI
(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager, WindowPostRenderer postRenderer, Component background) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations.MultiWindowTextGUI
(Screen screen) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations.MultiWindowTextGUI
(Screen screen, WindowManager windowManager, Component background) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations.MultiWindowTextGUI
(Screen screen, WindowManager windowManager, WindowPostRenderer postRenderer, Component background) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations.MultiWindowTextGUI
(Screen screen, TextColor backgroundColor) Deprecated.It's preferred to use a custom background component if you want to customize the background color, or you should change the theme. -
Method Summary
Modifier and TypeMethodDescriptionAdds a window to the TextGUI system, depending on the window manager this window may or may not be immediately visible.addWindowAndWait
(Window window) Adds a window to the TextGUI system, depending on the window manager this window may or may not be immediately visible.protected void
changeWindowHintsForDragged
(Window window) In order for window to be draggable, it would no longer be CENTERED.cycleActiveWindow
(boolean reverse) Switches the active window by cyclically shuffling the window list.private void
drawBackgroundPane
(TextGUIGraphics graphics) protected void
drawGUI
(TextGUIGraphics graphics) Draws the entire GUI using aTextGUIGraphics
objectReturns the window which the TextGUI considers the active one at the time of the method call.Returns the container for the background, which works as a single large component that takes up the whole terminal area and is always behind all windows.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 the interactable component currently in focusReturns the window manager that is currently controlling this TextGUI.Returns theWindowPostRenderer
for thisWindowBasedTextGUI
Returns a list of all windows currently in the TextGUI.boolean
handleInput
(KeyStroke keyStroke) This method should take the user input and feed it to the focused component for handling.protected void
ifMouseDownPossiblyChangeActiveWindow
(KeyStroke keyStroke) protected void
ifMouseDownPossiblyStartTitleDrag
(KeyStroke keyStroke) protected void
ifMouseDragPossiblyMoveWindow
(KeyStroke keyStroke) boolean
Returns whether the TextGUI should return EOF when you try to read input while there are no windows in the window manager.boolean
This method can be used to determine if any component has requested a redraw.moveToBottom
(Window window) Windows are internally stored as a stack and newer windows are added at the top of the stack.protected KeyStroke
Reads one key from the input queue, blocking or non-blocking depending on if blocking I/O has been enabled.removeWindow
(Window window) Removes a window from the TextGUI.setActiveWindow
(Window activeWindow) Selects a particular window to be considered 'active' and receive all input eventsvoid
setEOFWhenNoWindows
(boolean eofWhenNoWindows) Sets whether the TextGUI should return EOF when you try to read input while there are no windows in the window manager.void
setVirtualScreenEnabled
(boolean virtualScreenEnabled) Deprecated.This method don't do anything anymore (as of 3.1.0)void
Updates the screen, to make any changes visible to the user.void
waitForWindowToClose
(Window window) Waits for the specified window to be closedMethods inherited from class com.googlecode.lanterna.gui2.AbstractTextGUI
addListener, fireUnhandledKeyStroke, getGUIThread, getScreen, getTheme, invalidate, isBlockingIO, pollInput, processInput, removeListener, setBlockingIO, setTheme
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUI
addListener, getGUIThread, getScreen, getTheme, processInput, removeListener, setTheme
-
Field Details
-
windowManager
-
backgroundPane
-
windowList
-
windowRenderBufferCache
-
postRenderer
-
eofWhenNoWindows
private boolean eofWhenNoWindows -
titleBarDragWindow
-
originWindowPosition
-
dragStart
-
-
Constructor Details
-
MultiWindowTextGUI
Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI will be a solid color, depending on theme (default is blue). The current thread will be used as the GUI thread for all Lanterna library operations.- Parameters:
screen
- Screen to use as the backend for drawing operations
-
MultiWindowTextGUI
Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI will be a solid color, depending on theme (default is blue). This constructor allows you control the threading model for the UI.- Parameters:
guiThreadFactory
- Factory implementation to use when creating theTextGUIThread
screen
- Screen to use as the backend for drawing operations
-
MultiWindowTextGUI
public MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI will be a solid color, depending on theme (default is blue). This constructor allows you control the threading model for the UI and set a customWindowManager
.- Parameters:
guiThreadFactory
- Factory implementation to use when creating theTextGUIThread
screen
- Screen to use as the backend for drawing operationswindowManager
- Custom window manager to use
-
MultiWindowTextGUI
Deprecated.It's preferred to use a custom background component if you want to customize the background color, or you should change the theme. Using this constructor won't work well with theming.Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI is a solid color as decided by thebackgroundColor
parameter.- Parameters:
screen
- Screen to use as the backend for drawing operationsbackgroundColor
- Color to use for the GUI background
-
MultiWindowTextGUI
Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI will be the component supplied instead of the usual backdrop. This constructor allows you to set a customWindowManager
instead ofDefaultWindowManager
.- Parameters:
screen
- Screen to use as the backend for drawing operationswindowManager
- Window manager implementation to usebackground
- Component to use as the background of the GUI, behind all the windows
-
MultiWindowTextGUI
public MultiWindowTextGUI(Screen screen, WindowManager windowManager, WindowPostRenderer postRenderer, Component background) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI will be the component supplied instead of the usual backdrop. This constructor allows you to set a customWindowManager
instead ofDefaultWindowManager
as well as a customWindowPostRenderer
that can be used to tweak the appearance of any window.- Parameters:
screen
- Screen to use as the backend for drawing operationswindowManager
- Window manager implementation to usepostRenderer
-WindowPostRenderer
object to invoke after each window has been drawnbackground
- Component to use as the background of the GUI, behind all the windows
-
MultiWindowTextGUI
public MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager, WindowPostRenderer postRenderer, Component background) Creates a newMultiWindowTextGUI
that uses the specifiedScreen
as the backend for all drawing operations. The background area of the GUI will be the component supplied instead of the usual backdrop. This constructor allows you to set a customWindowManager
instead ofDefaultWindowManager
as well as a customWindowPostRenderer
that can be used to tweak the appearance of any window. This constructor also allows you to control the threading model for the UI.- Parameters:
guiThreadFactory
- Factory implementation to use when creating theTextGUIThread
screen
- Screen to use as the backend for drawing operationswindowManager
- Window manager implementation to usepostRenderer
-WindowPostRenderer
object to invoke after each window has been drawnbackground
- Component to use as the background of the GUI, behind all the windows
-
-
Method Details
-
isPendingUpdate
public boolean isPendingUpdate()Description copied from interface:TextGUI
This method can be used to determine if any component has requested a redraw. If this method returnstrue
, you may want to callupdateScreen()
.- Specified by:
isPendingUpdate
in interfaceTextGUI
- Overrides:
isPendingUpdate
in classAbstractTextGUI
- Returns:
true
if this TextGUI has a change and is waiting for someone to callupdateScreen()
-
updateScreen
Description copied from interface:TextGUI
Updates the screen, to make any changes visible to the user.- Specified by:
updateScreen
in interfaceTextGUI
- Overrides:
updateScreen
in classAbstractTextGUI
- Throws:
IOException
- In case there was an underlying I/O error
-
readKeyStroke
Description copied from class:AbstractTextGUI
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)
.- Overrides:
readKeyStroke
in classAbstractTextGUI
- Returns:
- One piece of user input as a
KeyStroke
ornull
if blocking I/O is disabled and there was no input waiting - Throws:
IOException
- In case of an I/O error while reading input
-
drawGUI
Description copied from class:AbstractTextGUI
Draws the entire GUI using aTextGUIGraphics
object- Specified by:
drawGUI
in classAbstractTextGUI
- Parameters:
graphics
- Graphics object to draw using
-
drawBackgroundPane
-
getCursorPosition
Description copied from class:AbstractTextGUI
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.- Specified by:
getCursorPosition
in classAbstractTextGUI
- Returns:
- Where to place the text cursor, or
null
if the cursor should be hidden
-
setEOFWhenNoWindows
public void setEOFWhenNoWindows(boolean eofWhenNoWindows) Sets whether the TextGUI should return EOF when you try to read input while there are no windows in the window manager. Setting this to true (off by default) will make the GUI automatically exit when the last window has been closed.- Parameters:
eofWhenNoWindows
- Should the GUI return EOF when there are no windows left
-
isEOFWhenNoWindows
public boolean isEOFWhenNoWindows()Returns whether the TextGUI should return EOF when you try to read input while there are no windows in the window manager. When this is true (true by default) will make the GUI automatically exit when the last window has been closed.- Returns:
- Should the GUI return EOF when there are no windows left
-
setVirtualScreenEnabled
Deprecated.This method don't do anything anymore (as of 3.1.0)This method used to exist to control if the virtual screen should by bypassed or not. Since 3.1.0 calling this has no effect since we don't force a VirtualScreen anymore and you control it yourself when you create the GUI.- Specified by:
setVirtualScreenEnabled
in interfaceTextGUI
- Parameters:
virtualScreenEnabled
- Not used anymore
-
getFocusedInteractable
Description copied from interface:TextGUI
Returns the interactable component currently in focus- Specified by:
getFocusedInteractable
in interfaceTextGUI
- Returns:
- Component that is currently in input focus
-
handleInput
Description copied from class:AbstractTextGUI
This method should take the user input and feed it to the focused component for handling.- Specified by:
handleInput
in classAbstractTextGUI
- Parameters:
keyStroke
-KeyStroke
representing the user input- Returns:
true
if the input was recognized and handled by the GUI, indicating that the GUI should be redrawn
-
ifMouseDownPossiblyChangeActiveWindow
-
ifMouseDownPossiblyStartTitleDrag
-
ifMouseDragPossiblyMoveWindow
-
changeWindowHintsForDragged
In order for window to be draggable, it would no longer be CENTERED. Removes Hint.CENTERED, adds Hint.FIXED_POSITION to the window hints. -
getWindowManager
Description copied from interface:WindowBasedTextGUI
Returns the window manager that is currently controlling this TextGUI. The window manager is in charge of placing the windows on the surface and also deciding how they behave and move around.- Specified by:
getWindowManager
in interfaceWindowBasedTextGUI
- Returns:
- Window manager that is currently controlling the windows in the terminal
-
addWindow
Description copied from interface:WindowBasedTextGUI
Adds a window to the TextGUI system, depending on the window manager this window may or may not be immediately visible. By adding a window to the GUI, it will be associated with this GUI and can receive focus and events from it. This method call will return immediately, if you want the call to block until the window is closed, please useaddWindowAndWait(..)
. Windows are internally stored as a stack and newer windows are added at the top of the stack. The GUI system will render windows in a predictable order from bottom to top. You can modify the stack by usingmoveToTop(..)
to move a Window from its current position in the stack to the top.- Specified by:
addWindow
in interfaceWindowBasedTextGUI
- Parameters:
window
- Window to add to the GUI- Returns:
- The WindowBasedTextGUI Itself
-
addWindowAndWait
Description copied from interface:WindowBasedTextGUI
Adds a window to the TextGUI system, depending on the window manager this window may or may not be immediately visible. By adding a window to the GUI, it will be associated with this GUI and can receive focus and events from it. This method block until the added window is removed or closed, if you want the call to return immediately, please useaddWindow(..)
. This method call is useful for modal dialogs that requires a certain user input before the application can continue. Windows are internally stored as a stack and newer windows are added at the top of the stack. The GUI system will render windows in a predictable order from bottom to top. You can modify the stack by usingmoveToTop(..)
to move a Window from its current position in the stack to the top.- Specified by:
addWindowAndWait
in interfaceWindowBasedTextGUI
- Parameters:
window
- Window to add to the GUI- Returns:
- The WindowBasedTextGUI Itself
-
removeWindow
Description copied from interface:WindowBasedTextGUI
Removes a window from the TextGUI. This is effectively the same as closing the window. The window will be unassociated from this TextGUI and will no longer receive any events for it. Any threads waiting on the window to close will be resumed.- Specified by:
removeWindow
in interfaceWindowBasedTextGUI
- Parameters:
window
- Window to close- Returns:
- The WindowBasedTextGUI itself
-
waitForWindowToClose
Description copied from interface:WindowBasedTextGUI
Waits for the specified window to be closed- Specified by:
waitForWindowToClose
in interfaceWindowBasedTextGUI
- Parameters:
window
- Window to wait for
-
getWindows
Description copied from interface:WindowBasedTextGUI
Returns a list of all windows currently in the TextGUI. The list is unmodifiable and just a snapshot of what the state was when the method was invoked. If windows are added/removed after the method call, the list will not reflect this.- Specified by:
getWindows
in interfaceWindowBasedTextGUI
- Returns:
- Unmodifiable list of all windows in the TextGUI at the time of the call
-
setActiveWindow
Description copied from interface:WindowBasedTextGUI
Selects a particular window to be considered 'active' and receive all input events- Specified by:
setActiveWindow
in interfaceWindowBasedTextGUI
- Parameters:
activeWindow
- Window to become active and receive input events- Returns:
- The WindowBasedTextGUI itself
-
getActiveWindow
Description copied from interface:WindowBasedTextGUI
Returns the window which the TextGUI considers the active one at the time of the method call. The active window is generally the one which relieves all keyboard input.- Specified by:
getActiveWindow
in interfaceWindowBasedTextGUI
- Returns:
- Active window in the TextGUI or
null
-
getBackgroundPane
Description copied from interface:WindowBasedTextGUI
Returns the container for the background, which works as a single large component that takes up the whole terminal area and is always behind all windows.- Specified by:
getBackgroundPane
in interfaceWindowBasedTextGUI
- Returns:
- The
BasePane
used by thisWindowBasedTextGUI
-
getWindowPostRenderer
Description copied from interface:WindowBasedTextGUI
Returns theWindowPostRenderer
for thisWindowBasedTextGUI
- Specified by:
getWindowPostRenderer
in interfaceWindowBasedTextGUI
- Returns:
- the
WindowPostRenderer
for thisWindowBasedTextGUI
-
moveToTop
Description copied from interface:WindowBasedTextGUI
Windows are internally stored as a stack and newer windows are added at the top of the stack. The GUI system will render windows in a predictable order from bottom to top. This method allows you to move a Window from its current position in the stack to the top, meaning it will be rendered last. This mean it will overlap all other windows and because of this visually appear on top.- Specified by:
moveToTop
in interfaceWindowBasedTextGUI
- Parameters:
window
- Window in the stack to move to the top position- Returns:
- The WindowBasedTextGUI Itself
-
moveToBottom
-
cycleActiveWindow
Switches the active window by cyclically shuffling the window list. Ifreverse
parameter isfalse
then the current top window is placed at the bottom of the stack and the window immediately behind it is the new top. Ifreverse
is set totrue
then the window at the bottom of the stack is moved up to the front and the previous top window will be immediately below it- Specified by:
cycleActiveWindow
in interfaceWindowBasedTextGUI
- Parameters:
reverse
- Direction to cycle through the windows- Returns:
- Itself
-