Class AbstractWindow

  • All Implemented Interfaces:
    BasePane, Composite, Window
    Direct Known Subclasses:
    BasicWindow, DialogWindow, MenuPopupWindow

    public abstract class AbstractWindow
    extends AbstractBasePane<Window>
    implements Window
    Abstract Window has most of the code requiring for a window to function, all concrete window implementations extends from this in one way or another. You can define your own window by extending from this, as an alternative to building up the GUI externally by constructing a BasicWindow and adding components to it.
    • Constructor Detail

      • AbstractWindow

        public AbstractWindow()
        Default constructor, this creates a window with no title
      • AbstractWindow

        public AbstractWindow​(java.lang.String title)
        Creates a window with a specific title that will (probably) be drawn in the window decorations
        Parameters:
        title - Title of this window
    • Method Detail

      • setCloseWindowWithEscape

        public void setCloseWindowWithEscape​(boolean closeWindowWithEscape)
        Setting this property to true will cause pressing the ESC key to close the window. This used to be the default behaviour of lanterna 3 during the development cycle but is not longer the case. You are encouraged to put proper buttons or other kind of components to clearly mark to the user how to close the window instead of magically taking ESC, but sometimes it can be useful (when doing testing, for example) to enable this mode.
        Parameters:
        closeWindowWithEscape - If true, this window will self-close if you press ESC key
      • setTextGUI

        public void setTextGUI​(WindowBasedTextGUI textGUI)
        Description copied from interface: Window
        DON'T CALL THIS METHOD YOURSELF, it is called automatically by the TextGUI system when you add a window. If you call it with the intention of adding the window to the specified TextGUI, you need to read the documentation on how to use windows.
        Specified by:
        setTextGUI in interface Window
        Parameters:
        textGUI - TextGUI this window belongs to from now on
      • getTextGUI

        public WindowBasedTextGUI getTextGUI()
        Description copied from interface: BasePane
        Returns the TextGUI this BasePane belongs to or null if none. One example of when this method returns null is when calling it on a Window that hasn't been displayed yet.
        Specified by:
        getTextGUI in interface BasePane
        Specified by:
        getTextGUI in interface Window
        Returns:
        The TextGUI this BasePane belongs to
      • setTitle

        public void setTitle​(java.lang.String title)
        Alters the title of the window to the supplied string
        Parameters:
        title - New title of the window
      • getTitle

        public java.lang.String getTitle()
        Description copied from interface: Window
        This method returns the title of the window, which is normally drawn at the top-left corder of the window decoration, but depending on the WindowDecorationRenderer used by the TextGUI
        Specified by:
        getTitle in interface Window
        Returns:
        title of the window
      • isVisible

        public boolean isVisible()
        Description copied from interface: Window
        This values is optionally used by the window manager to decide if the windows should be drawn or not. In an invisible state, the window is still considered active in the TextGUI but just not drawn and not receiving any input events. Please note that window managers may choose not to implement this.
        Specified by:
        isVisible in interface Window
        Returns:
        Whether the window wants to be visible or not
      • setVisible

        public void setVisible​(boolean visible)
        Description copied from interface: Window
        This values is optionally used by the window manager to decide if the windows should be drawn or not. In an invisible state, the window is still considered active in the TextGUI but just not drawn and not receiving any input events. Please note that window managers may choose not to implement this.
        Specified by:
        setVisible in interface Window
        Parameters:
        visible - whether the window should be visible or not
      • draw

        public void draw​(TextGUIGraphics graphics)
        Description copied from interface: BasePane
        Called by the GUI system (or something imitating the GUI system) to draw the root container. The TextGUIGraphics object should be used to perform the drawing operations.
        Specified by:
        draw in interface BasePane
        Specified by:
        draw in interface Window
        Overrides:
        draw in class AbstractBasePane<Window>
        Parameters:
        graphics - TextGraphics object to draw with
      • handleInput

        public boolean handleInput​(KeyStroke key)
        Description copied from interface: BasePane
        Called by the GUI system to delegate a keyboard input event. The root container will decide what to do with this input, usually sending it to one of its sub-components, but if it isn't able to find any handler for this input it should return false so that the GUI system can take further decisions on what to do with it.
        Specified by:
        handleInput in interface BasePane
        Specified by:
        handleInput in interface Window
        Overrides:
        handleInput in class AbstractBasePane<Window>
        Parameters:
        key - Keyboard input
        Returns:
        true If the root container could handle the input, false otherwise
      • toGlobalFromContentRelative

        public TerminalPosition toGlobalFromContentRelative​(TerminalPosition contentLocalPosition)
        Description copied from interface: Window
        Returns a position in the window content's local coordinate space to global coordinates
        Specified by:
        toGlobalFromContentRelative in interface Window
        Parameters:
        contentLocalPosition - The local position to translate
        Returns:
        The local position translated to global coordinates
      • toGlobalFromDecoratedRelative

        @Deprecated
        public TerminalPosition toGlobalFromDecoratedRelative​(TerminalPosition localPosition)
        Deprecated.
        Description copied from interface: Window
        Returns a position in the decorated window local coordinate space to global coordinates
        Specified by:
        toGlobalFromDecoratedRelative in interface Window
        Parameters:
        localPosition - The local position to translate
        Returns:
        The local position translated to global coordinates
      • fromGlobal

        @Deprecated
        public TerminalPosition fromGlobal​(TerminalPosition globalPosition)
        Deprecated.
        Description copied from interface: BasePane
        Returns a position expressed in global coordinates, i.e. row and column offset from the top-left corner of the terminal into a position relative to the top-left corner of the base pane. Calling fromGlobal(toGlobal(..)) should return the exact same position.
        Specified by:
        fromGlobal in interface BasePane
        Specified by:
        fromGlobal in interface Window
        Parameters:
        globalPosition - Position expressed in global coordinates to translate to local coordinates of this BasePane
        Returns:
        The global coordinates expressed as local coordinates
        See Also:
        Window.fromGlobalToContentRelative(TerminalPosition)
      • fromGlobalToContentRelative

        public TerminalPosition fromGlobalToContentRelative​(TerminalPosition globalPosition)
        Description copied from interface: Window
        Returns a position expressed in global coordinates, i.e. row and column offset from the top-left corner of the terminal into a position relative to the top-left corner of the window's content. Calling fromGlobalToContentRelative(toGlobalFromContentRelative(..)) should return the exact same position.
        Specified by:
        fromGlobalToContentRelative in interface Window
        Parameters:
        globalPosition - Position expressed in global coordinates to translate to local coordinates of this Window's content.
        Returns:
        The global coordinates expressed as local coordinates
      • fromGlobalToDecoratedRelative

        public TerminalPosition fromGlobalToDecoratedRelative​(TerminalPosition globalPosition)
        Description copied from interface: Window
        Returns a position expressed in global coordinates, i.e. row and column offset from the top-left corner of the terminal into a position relative to the top-left corner of the window including it's decoration. Calling fromGlobalToDecoratedRelative(toGlobalFromDecoratedRelative(..)) should return the exact same position.
        Specified by:
        fromGlobalToDecoratedRelative in interface Window
        Parameters:
        globalPosition - Position expressed in global coordinates to translate to local coordinates of this window including it's decoration.
        Returns:
        The global coordinates expressed as local coordinates
      • getPreferredSize

        public TerminalSize getPreferredSize()
        Description copied from interface: Window
        Returns the size this window would like to be
        Specified by:
        getPreferredSize in interface Window
        Returns:
        Desired size of this window
      • setHints

        public void setHints​(java.util.Collection<Window.Hint> hints)
        Description copied from interface: Window
        Updates the set of active hints for this window. Please note that it's up to the window manager if these hints will be honored or not.
        Specified by:
        setHints in interface Window
        Parameters:
        hints - Set of hints to be active for this window
      • getHints

        public java.util.Set<Window.Hint> getHints()
        Description copied from interface: Window
        Returns a set of window hints that can be used by the text gui system, the window manager or any other part that is interacting with windows.
        Specified by:
        getHints in interface Window
        Returns:
        Set of hints defined for this window
      • getPostRenderer

        public WindowPostRenderer getPostRenderer()
        Description copied from interface: Window
        Returns a post-renderer the GUI system should invoke after the window has been drawn. This can be used to creating effects like shadows, overlays, etc. If this returns null, the GUI system will fall back to it's own global override and after that to the current theme. If these are all null, no post-rendering is done.
        Specified by:
        getPostRenderer in interface Window
        Returns:
        WindowPostRenderer to invoke after this window is drawn, or null fallback to the GUI system's default.
      • removeWindowListener

        public void removeWindowListener​(WindowListener windowListener)
        Description copied from interface: Window
        Removes a WindowListener from this Window. If the listener isn't in the list of listeners, this call does nothing.
        Specified by:
        removeWindowListener in interface Window
        Parameters:
        windowListener - Listener to remove from this Window
      • setWindowPostRenderer

        public void setWindowPostRenderer​(WindowPostRenderer windowPostRenderer)
        Sets the post-renderer to use for this window. This will override the default from the GUI system (if there is one set, otherwise from the theme).
        Parameters:
        windowPostRenderer - Window post-renderer to assign to this window
      • getPosition

        public final TerminalPosition getPosition()
        Description copied from interface: Window
        Returns the position of the window, as last specified by the window manager. This position does not include window decorations but is the top-left position of the first usable space of the window.
        Specified by:
        getPosition in interface Window
        Returns:
        Position, relative to the top-left corner of the terminal, of the top-left corner of the window
      • setPosition

        public final void setPosition​(TerminalPosition topLeft)
        Description copied from interface: Window
        This method is called by the GUI system to update the window on where the window manager placed it. Calling this yourself will have no effect other than making the getPosition() call incorrect until the next redraw, unless you have specified through window hints that you don't want the window manager to automatically place the window. Notice that the position here is expressed in "global" coordinates, which means measured from the top-left corner of the terminal itself.
        Specified by:
        setPosition in interface Window
        Parameters:
        topLeft - Global coordinates of the top-left corner of the window
      • getSize

        public final TerminalSize getSize()
        Description copied from interface: Window
        Returns the last known size of the window. This is in general derived from the last drawing operation, how large area the window was allowed to draw on. This size does not include window decorations.
        Specified by:
        getSize in interface Window
        Returns:
        Size of the window
      • setSize

        @Deprecated
        public void setSize​(TerminalSize size)
        Deprecated.
        Description copied from interface: Window
        This method is called by the GUI system to update the window on how large it is, excluding window decorations. Calling this yourself will generally make no difference in the size of the window, since it will be reset on the next redraw based on how large area the TextGraphics given is covering. However, if you add the FIXED_SIZE window hint, the auto-size calculation will be turned off and you can use this method to set how large you want the window to be.

        Important: if you are writing your own WindowManager, you should call setDecoratedSize instead of this when decided the size of the window.

        Specified by:
        setSize in interface Window
        Parameters:
        size - New size of your fixed-size window
      • setFixedSize

        public void setFixedSize​(TerminalSize size)
        Description copied from interface: Window
        Calling this method will add the FIXED_SIZE window hint (if it wasn't present already) and attempt to force the window to always have the size specified. Notice that it's up to the WindowManager if this size and hint are going to be honored.
        Specified by:
        setFixedSize in interface Window
        Parameters:
        size - New size of your fixed-size window
      • setSize

        private void setSize​(TerminalSize size,
                             boolean invalidate)
      • getDecoratedSize

        public final TerminalSize getDecoratedSize()
        Description copied from interface: Window
        Returns the last known size of the window including window decorations put on by the window manager. The value returned here is passed in during drawing by the TextGUI through setDecoratedSize(..).
        Specified by:
        getDecoratedSize in interface Window
        Returns:
        Size of the window, including window decorations
      • setDecoratedSize

        public final void setDecoratedSize​(TerminalSize decoratedSize)
        Description copied from interface: Window
        This method is called by the GUI system to update the window on how large it is, counting window decorations too. Calling this yourself will have no effect other than making the getDecoratedSize() call incorrect until the next redraw.

        Important: if you are writing your own WindowManager, you should call this method instead of setSize when decided the size of the window.

        Specified by:
        setDecoratedSize in interface Window
        Parameters:
        decoratedSize - Size of the window, including window decorations
      • setContentOffset

        public void setContentOffset​(TerminalPosition offset)
        Description copied from interface: Window
        This method is called by the GUI system to update the window on, as of the last drawing operation, the distance from the top-left position of the window including decorations to the top-left position of the actual content area. If this window has no decorations, it will be always 0x0. Do not call this method yourself.
        Specified by:
        setContentOffset in interface Window
        Parameters:
        offset - Offset from the top-left corner of the window (including decorations) to the top-left corner of the content area.
      • close

        public void close()
        Description copied from interface: Window
        Closes the window, which will remove it from the GUI
        Specified by:
        close in interface Window
      • waitUntilClosed

        public void waitUntilClosed()
        Description copied from interface: Window
        Waits for the window to close. Please note that this can cause deadlocks if care is not taken. Also, this method will swallow any interrupts, if you need a wait method that throws InterruptedException, you'll have to implement this yourself.
        Specified by:
        waitUntilClosed in interface Window