- java.lang.Object
-
- com.googlecode.lanterna.gui2.DefaultWindowManager
-
- All Implemented Interfaces:
WindowManager
public class DefaultWindowManager extends java.lang.Object implements WindowManager
The default window manager implementation used by Lanterna. New windows will be generally added in a tiled manner, starting in the top-left corner and moving down-right as new windows are added. By using the various window hints that are available you have some control over how the window manager will place and size the windows.
-
-
Field Summary
Fields Modifier and Type Field Description private TerminalSizelastKnownScreenSizeprivate WindowDecorationRendererwindowDecorationRendererOverride
-
Constructor Summary
Constructors Constructor Description DefaultWindowManager()Default constructor, will create a window manager that usesDefaultWindowDecorationRendererfor drawing window decorations, unless the current theme has an override.DefaultWindowManager(WindowDecorationRenderer windowDecorationRenderer, TerminalSize initialScreenSize)Creates a newDefaultWindowManagerusing a specifiedwindowDecorationRendererOverridefor drawing window decorations.DefaultWindowManager(TerminalSize initialScreenSize)Creates a newDefaultWindowManagerusing aDefaultWindowDecorationRendererfor drawing window decorations, unless the current theme has an override.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description WindowDecorationRenderergetWindowDecorationRenderer(Window window)Returns theWindowDecorationRendererfor a particular windowbooleanisInvalid()Will be polled by the theWindowBasedTextGUIto see if the window manager believes an update is required.voidonAdded(WindowBasedTextGUI textGUI, Window window, java.util.List<Window> allWindows)Called whenever a window is added to theWindowBasedTextGUI.voidonRemoved(WindowBasedTextGUI textGUI, Window window, java.util.List<Window> allWindows)Called whenever a window is removed from aWindowBasedTextGUI.protected voidprepareWindow(TerminalSize screenSize, Window window)Called byDefaultWindowManagerwhen iterating through all windows to decide their size and position.voidprepareWindows(WindowBasedTextGUI textGUI, java.util.List<Window> allWindows, TerminalSize screenSize)Called by the GUI system before iterating through all windows during the drawing process.
-
-
-
Field Detail
-
windowDecorationRendererOverride
private final WindowDecorationRenderer windowDecorationRendererOverride
-
lastKnownScreenSize
private TerminalSize lastKnownScreenSize
-
-
Constructor Detail
-
DefaultWindowManager
public DefaultWindowManager()
Default constructor, will create a window manager that usesDefaultWindowDecorationRendererfor drawing window decorations, unless the current theme has an override. Any size calculations done before the text GUI has actually been started and displayed on the terminal will assume the terminal size is 80x24.
-
DefaultWindowManager
public DefaultWindowManager(TerminalSize initialScreenSize)
Creates a newDefaultWindowManagerusing aDefaultWindowDecorationRendererfor drawing window decorations, unless the current theme has an override. Any size calculations done before the text GUI has actually been started and displayed on the terminal will use the size passed in with theinitialScreenSizeparameter (ifnullthen size will be assumed to be 80x24)- Parameters:
initialScreenSize- Size to assume the terminal has until the text GUI is started and can be notified of the correct size
-
DefaultWindowManager
public DefaultWindowManager(WindowDecorationRenderer windowDecorationRenderer, TerminalSize initialScreenSize)
Creates a newDefaultWindowManagerusing a specifiedwindowDecorationRendererOverridefor drawing window decorations. Any size calculations done before the text GUI has actually been started and displayed on the terminal will use the size passed in with theinitialScreenSizeparameter- Parameters:
windowDecorationRenderer- Window decoration renderer to use when drawing windowsinitialScreenSize- Size to assume the terminal has until the text GUI is started and can be notified of the correct size
-
-
Method Detail
-
isInvalid
public boolean isInvalid()
Description copied from interface:WindowManagerWill be polled by the theWindowBasedTextGUIto see if the window manager believes an update is required. For example, it could be that there is no input, no events and none of the components are invalid, but the window manager decides for some other reason that the GUI needs to be updated, in that case you should returntruehere. Please note that returningfalsewill not prevent updates from happening, it's just stating that the window manager isn't aware of some internal state change that would require an update.- Specified by:
isInvalidin interfaceWindowManager- Returns:
trueif the window manager believes the GUI needs to be update,falseotherwise
-
getWindowDecorationRenderer
public WindowDecorationRenderer getWindowDecorationRenderer(Window window)
Description copied from interface:WindowManagerReturns theWindowDecorationRendererfor a particular window- Specified by:
getWindowDecorationRendererin interfaceWindowManager- Parameters:
window- Window to get the decoration renderer for- Returns:
WindowDecorationRendererfor the window
-
onAdded
public void onAdded(WindowBasedTextGUI textGUI, Window window, java.util.List<Window> allWindows)
Description copied from interface:WindowManagerCalled whenever a window is added to theWindowBasedTextGUI. This gives the window manager an opportunity to setup internal state, if required, or decide on an initial position of the window- Specified by:
onAddedin interfaceWindowManager- Parameters:
textGUI- GUI that the window was added toowindow- Window that was addedallWindows- All windows, including the new window, in the GUI
-
onRemoved
public void onRemoved(WindowBasedTextGUI textGUI, Window window, java.util.List<Window> allWindows)
Description copied from interface:WindowManagerCalled whenever a window is removed from aWindowBasedTextGUI. This gives the window manager an opportunity to clear internal state if needed.- Specified by:
onRemovedin interfaceWindowManager- Parameters:
textGUI- GUI that the window was removed fromwindow- Window that was removedallWindows- All windows, excluding the removed window, in the GUI
-
prepareWindows
public void prepareWindows(WindowBasedTextGUI textGUI, java.util.List<Window> allWindows, TerminalSize screenSize)
Description copied from interface:WindowManagerCalled by the GUI system before iterating through all windows during the drawing process. The window manager should ensure the position and decorated size of all windows at this point by usingWindow.setPosition(..)andWindow.setDecoratedSize(..). Be sure to inspect the window hints assigned to the window, in case you want to try to honour them. Use theWindowManager.getWindowDecorationRenderer(Window)method to get the currently assigned window decoration rendering class which can tell you the decorated size of a window given it's content size.- Specified by:
prepareWindowsin interfaceWindowManager- Parameters:
textGUI- Text GUI that is about to draw the windowsallWindows- All windows that are going to be drawn, in the order they will be drawnscreenSize- Size of the terminal that is available to draw on
-
prepareWindow
protected void prepareWindow(TerminalSize screenSize, Window window)
Called byDefaultWindowManagerwhen iterating through all windows to decide their size and position. If you overrideDefaultWindowManagerto add your own logic to how windows are placed on the screen, you can override this method and selectively choose which window to interfere with. Note that the two key properties that are read by the GUI system after preparing all windows are the position and decorated size. Your custom implementation should set these two fields directly on the window. You can infer the decorated size from the content size by using the window decoration renderer that is attached to the window manager.- Parameters:
screenSize- Size of the terminal that is available to draw onwindow- Window to prepare decorated size and position for
-
-