Class 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.
    • Constructor Detail

      • DefaultWindowManager

        public DefaultWindowManager()
        Default constructor, will create a window manager that uses DefaultWindowDecorationRenderer for 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 new DefaultWindowManager using a DefaultWindowDecorationRenderer for 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 the initialScreenSize parameter (if null then 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 new DefaultWindowManager using a specified windowDecorationRendererOverride for 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 the initialScreenSize parameter
        Parameters:
        windowDecorationRenderer - Window decoration renderer to use when drawing windows
        initialScreenSize - 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: WindowManager
        Will be polled by the the WindowBasedTextGUI to 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 return true here. Please note that returning false will 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:
        isInvalid in interface WindowManager
        Returns:
        true if the window manager believes the GUI needs to be update, false otherwise
      • onAdded

        public void onAdded​(WindowBasedTextGUI textGUI,
                            Window window,
                            java.util.List<Window> allWindows)
        Description copied from interface: WindowManager
        Called whenever a window is added to the WindowBasedTextGUI. This gives the window manager an opportunity to setup internal state, if required, or decide on an initial position of the window
        Specified by:
        onAdded in interface WindowManager
        Parameters:
        textGUI - GUI that the window was added too
        window - Window that was added
        allWindows - 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: WindowManager
        Called whenever a window is removed from a WindowBasedTextGUI. This gives the window manager an opportunity to clear internal state if needed.
        Specified by:
        onRemoved in interface WindowManager
        Parameters:
        textGUI - GUI that the window was removed from
        window - Window that was removed
        allWindows - 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: WindowManager
        Called 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 using Window.setPosition(..) and Window.setDecoratedSize(..). Be sure to inspect the window hints assigned to the window, in case you want to try to honour them. Use the WindowManager.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:
        prepareWindows in interface WindowManager
        Parameters:
        textGUI - Text GUI that is about to draw the windows
        allWindows - All windows that are going to be drawn, in the order they will be drawn
        screenSize - Size of the terminal that is available to draw on
      • prepareWindow

        protected void prepareWindow​(TerminalSize screenSize,
                                     Window window)
        Called by DefaultWindowManager when iterating through all windows to decide their size and position. If you override DefaultWindowManager to 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 on
        window - Window to prepare decorated size and position for