- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractTextGUI
-
- com.googlecode.lanterna.gui2.MultiWindowTextGUI
-
- All Implemented Interfaces:
TextGUI,WindowBasedTextGUI
public class MultiWindowTextGUI extends AbstractTextGUI implements 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
Screenobject with aVirtualScreento ensure that the UI always fits. As of 3.1.0, we don't do this anymore so when you create theMultiWindowTextGUIyou 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
Fields Modifier and Type Field Description private BasePanebackgroundPaneprivate TerminalPositiondragStartprivate booleaneofWhenNoWindowsprivate TerminalPositionoriginWindowPositionprivate WindowPostRendererpostRendererprivate WindowtitleBarDragWindowprivate WindowListwindowListprivate WindowManagerwindowManagerprivate java.util.IdentityHashMap<Window,TextImage>windowRenderBufferCache
-
Constructor Summary
Constructors Constructor Description MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen)Creates a newMultiWindowTextGUIthat uses the specifiedScreenas the backend for all drawing operations.MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager)Creates a newMultiWindowTextGUIthat uses the specifiedScreenas the backend for all drawing operations.MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager, WindowPostRenderer postRenderer, Component background)Creates a newMultiWindowTextGUIthat uses the specifiedScreenas the backend for all drawing operations.MultiWindowTextGUI(Screen screen)Creates a newMultiWindowTextGUIthat uses the specifiedScreenas the backend for all drawing operations.MultiWindowTextGUI(Screen screen, WindowManager windowManager, Component background)Creates a newMultiWindowTextGUIthat uses the specifiedScreenas the backend for all drawing operations.MultiWindowTextGUI(Screen screen, WindowManager windowManager, WindowPostRenderer postRenderer, Component background)Creates a newMultiWindowTextGUIthat uses the specifiedScreenas 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
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description WindowBasedTextGUIaddWindow(Window window)Adds a window to the TextGUI system, depending on the window manager this window may or may not be immediately visible.WindowBasedTextGUIaddWindowAndWait(Window window)Adds a window to the TextGUI system, depending on the window manager this window may or may not be immediately visible.protected voidchangeWindowHintsForDragged(Window window)In order for window to be draggable, it would no longer be CENTERED.WindowBasedTextGUIcycleActiveWindow(boolean reverse)Switches the active window by cyclically shuffling the window list.private voiddrawBackgroundPane(TextGUIGraphics graphics)protected voiddrawGUI(TextGUIGraphics graphics)Draws the entire GUI using aTextGUIGraphicsobjectWindowgetActiveWindow()Returns the window which the TextGUI considers the active one at the time of the method call.BasePanegetBackgroundPane()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.TerminalPositiongetCursorPosition()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.InteractablegetFocusedInteractable()Returns the interactable component currently in focusWindowManagergetWindowManager()Returns the window manager that is currently controlling this TextGUI.WindowPostRenderergetWindowPostRenderer()Returns theWindowPostRendererfor thisWindowBasedTextGUIjava.util.Collection<Window>getWindows()Returns a list of all windows currently in the TextGUI.booleanhandleInput(KeyStroke keyStroke)This method should take the user input and feed it to the focused component for handling.protected voidifMouseDownPossiblyChangeActiveWindow(KeyStroke keyStroke)protected voidifMouseDownPossiblyStartTitleDrag(KeyStroke keyStroke)protected voidifMouseDragPossiblyMoveWindow(KeyStroke keyStroke)booleanisEOFWhenNoWindows()Returns whether the TextGUI should return EOF when you try to read input while there are no windows in the window manager.booleanisPendingUpdate()This method can be used to determine if any component has requested a redraw.WindowBasedTextGUImoveToBottom(Window window)WindowBasedTextGUImoveToTop(Window window)Windows are internally stored as a stack and newer windows are added at the top of the stack.protected KeyStrokereadKeyStroke()Reads one key from the input queue, blocking or non-blocking depending on if blocking I/O has been enabled.WindowBasedTextGUIremoveWindow(Window window)Removes a window from the TextGUI.MultiWindowTextGUIsetActiveWindow(Window activeWindow)Selects a particular window to be considered 'active' and receive all input eventsvoidsetEOFWhenNoWindows(boolean eofWhenNoWindows)Sets whether the TextGUI should return EOF when you try to read input while there are no windows in the window manager.voidsetVirtualScreenEnabled(boolean virtualScreenEnabled)Deprecated.This method don't do anything anymore (as of 3.1.0)voidupdateScreen()Updates the screen, to make any changes visible to the user.voidwaitForWindowToClose(Window window)Waits for the specified window to be closed-
Methods 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 Detail
-
windowManager
private final WindowManager windowManager
-
backgroundPane
private final BasePane backgroundPane
-
windowList
private final WindowList windowList
-
windowRenderBufferCache
private final java.util.IdentityHashMap<Window,TextImage> windowRenderBufferCache
-
postRenderer
private final WindowPostRenderer postRenderer
-
eofWhenNoWindows
private boolean eofWhenNoWindows
-
titleBarDragWindow
private Window titleBarDragWindow
-
originWindowPosition
private TerminalPosition originWindowPosition
-
dragStart
private TerminalPosition dragStart
-
-
Constructor Detail
-
MultiWindowTextGUI
public MultiWindowTextGUI(Screen screen)
Creates a newMultiWindowTextGUIthat uses the specifiedScreenas 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
public MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen)
Creates a newMultiWindowTextGUIthat uses the specifiedScreenas 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 theTextGUIThreadscreen- Screen to use as the backend for drawing operations
-
MultiWindowTextGUI
public MultiWindowTextGUI(TextGUIThreadFactory guiThreadFactory, Screen screen, WindowManager windowManager)
Creates a newMultiWindowTextGUIthat uses the specifiedScreenas 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 theTextGUIThreadscreen- Screen to use as the backend for drawing operationswindowManager- Custom window manager to use
-
MultiWindowTextGUI
@Deprecated public 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. Using this constructor won't work well with theming.Creates a newMultiWindowTextGUIthat uses the specifiedScreenas the backend for all drawing operations. The background area of the GUI is a solid color as decided by thebackgroundColorparameter.- Parameters:
screen- Screen to use as the backend for drawing operationsbackgroundColor- Color to use for the GUI background
-
MultiWindowTextGUI
public MultiWindowTextGUI(Screen screen, WindowManager windowManager, Component background)
Creates a newMultiWindowTextGUIthat uses the specifiedScreenas 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 customWindowManagerinstead 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 newMultiWindowTextGUIthat uses the specifiedScreenas 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 customWindowManagerinstead ofDefaultWindowManageras well as a customWindowPostRendererthat 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-WindowPostRendererobject 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 newMultiWindowTextGUIthat uses the specifiedScreenas 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 customWindowManagerinstead ofDefaultWindowManageras well as a customWindowPostRendererthat 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 theTextGUIThreadscreen- Screen to use as the backend for drawing operationswindowManager- Window manager implementation to usepostRenderer-WindowPostRendererobject to invoke after each window has been drawnbackground- Component to use as the background of the GUI, behind all the windows
-
-
Method Detail
-
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- Overrides:
isPendingUpdatein classAbstractTextGUI- Returns:
trueif this TextGUI has a change and is waiting for someone to callupdateScreen()
-
updateScreen
public void updateScreen() throws java.io.IOExceptionDescription copied from interface:TextGUIUpdates the screen, to make any changes visible to the user.- Specified by:
updateScreenin interfaceTextGUI- Overrides:
updateScreenin classAbstractTextGUI- Throws:
java.io.IOException- In case there was an underlying I/O error
-
readKeyStroke
protected KeyStroke readKeyStroke() throws java.io.IOException
Description copied from class:AbstractTextGUIReads 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:
readKeyStrokein classAbstractTextGUI- Returns:
- One piece of user input as a
KeyStrokeornullif blocking I/O is disabled and there was no input waiting - Throws:
java.io.IOException- In case of an I/O error while reading input
-
drawGUI
protected void drawGUI(TextGUIGraphics graphics)
Description copied from class:AbstractTextGUIDraws the entire GUI using aTextGUIGraphicsobject- Specified by:
drawGUIin classAbstractTextGUI- Parameters:
graphics- Graphics object to draw using
-
drawBackgroundPane
private void drawBackgroundPane(TextGUIGraphics graphics)
-
getCursorPosition
public TerminalPosition getCursorPosition()
Description copied from class:AbstractTextGUITop-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:
getCursorPositionin classAbstractTextGUI- Returns:
- Where to place the text cursor, or
nullif 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 public void setVirtualScreenEnabled(boolean virtualScreenEnabled)
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:
setVirtualScreenEnabledin interfaceTextGUI- Parameters:
virtualScreenEnabled- Not used anymore
-
getFocusedInteractable
public Interactable getFocusedInteractable()
Description copied from interface:TextGUIReturns the interactable component currently in focus- Specified by:
getFocusedInteractablein interfaceTextGUI- Returns:
- Component that is currently in input focus
-
handleInput
public boolean handleInput(KeyStroke keyStroke)
Description copied from class:AbstractTextGUIThis method should take the user input and feed it to the focused component for handling.- Specified by:
handleInputin classAbstractTextGUI- Parameters:
keyStroke-KeyStrokerepresenting the user input- Returns:
trueif the input was recognized and handled by the GUI, indicating that the GUI should be redrawn
-
ifMouseDownPossiblyChangeActiveWindow
protected void ifMouseDownPossiblyChangeActiveWindow(KeyStroke keyStroke)
-
ifMouseDownPossiblyStartTitleDrag
protected void ifMouseDownPossiblyStartTitleDrag(KeyStroke keyStroke)
-
ifMouseDragPossiblyMoveWindow
protected void ifMouseDragPossiblyMoveWindow(KeyStroke keyStroke)
-
changeWindowHintsForDragged
protected void changeWindowHintsForDragged(Window window)
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
public WindowManager getWindowManager()
Description copied from interface:WindowBasedTextGUIReturns 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:
getWindowManagerin interfaceWindowBasedTextGUI- Returns:
- Window manager that is currently controlling the windows in the terminal
-
addWindow
public WindowBasedTextGUI addWindow(Window window)
Description copied from interface:WindowBasedTextGUIAdds 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:
addWindowin interfaceWindowBasedTextGUI- Parameters:
window- Window to add to the GUI- Returns:
- The WindowBasedTextGUI Itself
-
addWindowAndWait
public WindowBasedTextGUI addWindowAndWait(Window window)
Description copied from interface:WindowBasedTextGUIAdds 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:
addWindowAndWaitin interfaceWindowBasedTextGUI- Parameters:
window- Window to add to the GUI- Returns:
- The WindowBasedTextGUI Itself
-
removeWindow
public WindowBasedTextGUI removeWindow(Window window)
Description copied from interface:WindowBasedTextGUIRemoves 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:
removeWindowin interfaceWindowBasedTextGUI- Parameters:
window- Window to close- Returns:
- The WindowBasedTextGUI itself
-
waitForWindowToClose
public void waitForWindowToClose(Window window)
Description copied from interface:WindowBasedTextGUIWaits for the specified window to be closed- Specified by:
waitForWindowToClosein interfaceWindowBasedTextGUI- Parameters:
window- Window to wait for
-
getWindows
public java.util.Collection<Window> getWindows()
Description copied from interface:WindowBasedTextGUIReturns 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:
getWindowsin interfaceWindowBasedTextGUI- Returns:
- Unmodifiable list of all windows in the TextGUI at the time of the call
-
setActiveWindow
public MultiWindowTextGUI setActiveWindow(Window activeWindow)
Description copied from interface:WindowBasedTextGUISelects a particular window to be considered 'active' and receive all input events- Specified by:
setActiveWindowin interfaceWindowBasedTextGUI- Parameters:
activeWindow- Window to become active and receive input events- Returns:
- The WindowBasedTextGUI itself
-
getActiveWindow
public Window getActiveWindow()
Description copied from interface:WindowBasedTextGUIReturns 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:
getActiveWindowin interfaceWindowBasedTextGUI- Returns:
- Active window in the TextGUI or
null
-
getBackgroundPane
public BasePane getBackgroundPane()
Description copied from interface:WindowBasedTextGUIReturns 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:
getBackgroundPanein interfaceWindowBasedTextGUI- Returns:
- The
BasePaneused by thisWindowBasedTextGUI
-
getWindowPostRenderer
public WindowPostRenderer getWindowPostRenderer()
Description copied from interface:WindowBasedTextGUIReturns theWindowPostRendererfor thisWindowBasedTextGUI- Specified by:
getWindowPostRendererin interfaceWindowBasedTextGUI- Returns:
- the
WindowPostRendererfor thisWindowBasedTextGUI
-
moveToTop
public WindowBasedTextGUI moveToTop(Window window)
Description copied from interface:WindowBasedTextGUIWindows 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:
moveToTopin interfaceWindowBasedTextGUI- Parameters:
window- Window in the stack to move to the top position- Returns:
- The WindowBasedTextGUI Itself
-
moveToBottom
public WindowBasedTextGUI moveToBottom(Window window)
-
cycleActiveWindow
public WindowBasedTextGUI cycleActiveWindow(boolean reverse)
Switches the active window by cyclically shuffling the window list. Ifreverseparameter isfalsethen the current top window is placed at the bottom of the stack and the window immediately behind it is the new top. Ifreverseis set totruethen 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:
cycleActiveWindowin interfaceWindowBasedTextGUI- Parameters:
reverse- Direction to cycle through the windows- Returns:
- Itself
-
-