- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractBasePane<Window>
-
- com.googlecode.lanterna.gui2.AbstractWindow
-
- 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 aBasicWindow
and adding components to it.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class com.googlecode.lanterna.gui2.AbstractBasePane
AbstractBasePane.ContentHolder
-
Nested classes/interfaces inherited from interface com.googlecode.lanterna.gui2.Window
Window.Hint
-
-
Field Summary
Fields Modifier and Type Field Description private boolean
closeWindowWithEscape
private TerminalPosition
contentOffset
private java.util.Set<Window.Hint>
hints
private TerminalSize
lastKnownDecoratedSize
private TerminalPosition
lastKnownPosition
private TerminalSize
lastKnownSize
private WindowBasedTextGUI
textGUI
private java.lang.String
title
private boolean
visible
private WindowPostRenderer
windowPostRenderer
-
Fields inherited from class com.googlecode.lanterna.gui2.AbstractBasePane
contentHolder, interactableLookupMap
-
-
Constructor Summary
Constructors Constructor Description AbstractWindow()
Default constructor, this creates a window with no titleAbstractWindow(java.lang.String title)
Creates a window with a specific title that will (probably) be drawn in the window decorations
-
Method Summary
All Methods Instance Methods Concrete Methods Deprecated Methods Modifier and Type Method Description void
addWindowListener(WindowListener windowListener)
Adds aWindowListener
to thisWindow
.void
close()
Closes the window, which will remove it from the GUIvoid
draw(TextGUIGraphics graphics)
Called by the GUI system (or something imitating the GUI system) to draw the root container.TerminalPosition
fromGlobal(TerminalPosition globalPosition)
Deprecated.TerminalPosition
fromGlobalToContentRelative(TerminalPosition globalPosition)
Returns a position expressed in global coordinates, i.e.TerminalPosition
fromGlobalToDecoratedRelative(TerminalPosition globalPosition)
Returns a position expressed in global coordinates, i.e.TerminalSize
getDecoratedSize()
Returns the last known size of the window including window decorations put on by the window manager.java.util.Set<Window.Hint>
getHints()
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.TerminalPosition
getPosition()
Returns the position of the window, as last specified by the window manager.WindowPostRenderer
getPostRenderer()
Returns a post-renderer the GUI system should invoke after the window has been drawn.TerminalSize
getPreferredSize()
Returns the size this window would like to beTerminalSize
getSize()
Returns the last known size of the window.WindowBasedTextGUI
getTextGUI()
Returns the TextGUI this BasePane belongs to ornull
if none.java.lang.String
getTitle()
This method returns the title of the window, which is normally drawn at the top-left corder of the window decoration, but depending on theWindowDecorationRenderer
used by theTextGUI
boolean
handleInput(KeyStroke key)
Called by the GUI system to delegate a keyboard input event.boolean
isVisible()
This values is optionally used by the window manager to decide if the windows should be drawn or not.void
removeWindowListener(WindowListener windowListener)
Removes aWindowListener
from thisWindow
.(package private) Window
self()
void
setCloseWindowWithEscape(boolean closeWindowWithEscape)
Setting this property totrue
will cause pressing the ESC key to close the window.void
setContentOffset(TerminalPosition offset)
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.void
setDecoratedSize(TerminalSize decoratedSize)
This method is called by the GUI system to update the window on how large it is, counting window decorations too.void
setFixedSize(TerminalSize size)
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.void
setHints(java.util.Collection<Window.Hint> hints)
Updates the set of active hints for this window.void
setPosition(TerminalPosition topLeft)
This method is called by the GUI system to update the window on where the window manager placed it.void
setSize(TerminalSize size)
Deprecated.private void
setSize(TerminalSize size, boolean invalidate)
void
setTextGUI(WindowBasedTextGUI textGUI)
DON'T CALL THIS METHOD YOURSELF, it is called automatically by the TextGUI system when you add a window.void
setTitle(java.lang.String title)
Alters the title of the window to the supplied stringvoid
setVisible(boolean visible)
This values is optionally used by the window manager to decide if the windows should be drawn or not.void
setWindowPostRenderer(WindowPostRenderer windowPostRenderer)
Sets the post-renderer to use for this window.TerminalPosition
toGlobal(TerminalPosition localPosition)
Deprecated.TerminalPosition
toGlobalFromContentRelative(TerminalPosition contentLocalPosition)
Returns a position in the window content's local coordinate space to global coordinatesTerminalPosition
toGlobalFromDecoratedRelative(TerminalPosition localPosition)
Deprecated.void
waitUntilClosed()
Waits for the window to close.-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractBasePane
addBasePaneListener, getBasePaneListeners, getComponent, getCursorPosition, getFocusedInteractable, getMenuBar, getTheme, invalidate, isInvalid, removeBasePaneListener, setComponent, setEnableDirectionBasedMovements, setFocusedInteractable, setFocusedInteractable, setMenuBar, setStrictFocusChange, 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.BasePane
getTheme, setEnableDirectionBasedMovements, setStrictFocusChange, setTheme
-
Methods inherited from interface com.googlecode.lanterna.gui2.Window
getBounds, getComponent, getCursorPosition, getFocusedInteractable, getMenuBar, invalidate, isInvalid, setComponent, setFocusedInteractable, setMenuBar
-
-
-
-
Field Detail
-
title
private java.lang.String title
-
textGUI
private WindowBasedTextGUI textGUI
-
visible
private boolean visible
-
lastKnownSize
private TerminalSize lastKnownSize
-
lastKnownDecoratedSize
private TerminalSize lastKnownDecoratedSize
-
lastKnownPosition
private TerminalPosition lastKnownPosition
-
contentOffset
private TerminalPosition contentOffset
-
hints
private java.util.Set<Window.Hint> hints
-
windowPostRenderer
private WindowPostRenderer windowPostRenderer
-
closeWindowWithEscape
private boolean closeWindowWithEscape
-
-
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 totrue
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
- Iftrue
, 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 interfaceWindow
- 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 ornull
if none. One example of when this method returnsnull
is when calling it on a Window that hasn't been displayed yet.- Specified by:
getTextGUI
in interfaceBasePane
- Specified by:
getTextGUI
in interfaceWindow
- 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 theWindowDecorationRenderer
used by theTextGUI
-
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.
-
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 interfaceWindow
- 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.
-
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 returnfalse
so that the GUI system can take further decisions on what to do with it.- Specified by:
handleInput
in interfaceBasePane
- Specified by:
handleInput
in interfaceWindow
- Overrides:
handleInput
in classAbstractBasePane<Window>
- Parameters:
key
- Keyboard input- Returns:
true
If the root container could handle the input, false otherwise
-
toGlobal
@Deprecated public TerminalPosition toGlobal(TerminalPosition localPosition)
Deprecated.Description copied from interface:BasePane
Returns a position in a root container's local coordinate space to global coordinates- Specified by:
toGlobal
in interfaceBasePane
- Specified by:
toGlobal
in interfaceWindow
- Parameters:
localPosition
- The local position to translate- Returns:
- The local position translated to global coordinates
- See Also:
Window.toGlobalFromContentRelative(TerminalPosition)
-
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 interfaceWindow
- 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 interfaceWindow
- 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. CallingfromGlobal(toGlobal(..))
should return the exact same position.- Specified by:
fromGlobal
in interfaceBasePane
- Specified by:
fromGlobal
in interfaceWindow
- 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. CallingfromGlobalToContentRelative(toGlobalFromContentRelative(..))
should return the exact same position.- Specified by:
fromGlobalToContentRelative
in interfaceWindow
- 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. CallingfromGlobalToDecoratedRelative(toGlobalFromDecoratedRelative(..))
should return the exact same position.- Specified by:
fromGlobalToDecoratedRelative
in interfaceWindow
- 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 interfaceWindow
- 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.
-
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.
-
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 returnsnull
, the GUI system will fall back to it's own global override and after that to the current theme. If these are allnull
, no post-rendering is done.- Specified by:
getPostRenderer
in interfaceWindow
- Returns:
WindowPostRenderer
to invoke after this window is drawn, ornull
fallback to the GUI system's default.
-
addWindowListener
public void addWindowListener(WindowListener windowListener)
Description copied from interface:Window
Adds aWindowListener
to thisWindow
. If it has already been added, the call will do nothing.- Specified by:
addWindowListener
in interfaceWindow
- Parameters:
windowListener
- Listener to attach to thisWindow
-
removeWindowListener
public void removeWindowListener(WindowListener windowListener)
Description copied from interface:Window
Removes aWindowListener
from thisWindow
. If the listener isn't in the list of listeners, this call does nothing.- Specified by:
removeWindowListener
in interfaceWindow
- Parameters:
windowListener
- Listener to remove from thisWindow
-
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 interfaceWindow
- 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 thegetPosition()
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 interfaceWindow
- 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.
-
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 callsetDecoratedSize
instead of this when decided the size of the 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 theWindowManager
if this size and hint are going to be honored.- Specified by:
setFixedSize
in interfaceWindow
- 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 throughsetDecoratedSize(..)
.- Specified by:
getDecoratedSize
in interfaceWindow
- 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 thegetDecoratedSize()
call incorrect until the next redraw.Important: if you are writing your own
WindowManager
, you should call this method instead ofsetSize
when decided the size of the window.- Specified by:
setDecoratedSize
in interfaceWindow
- 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 interfaceWindow
- 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
-
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 interfaceWindow
-
self
Window self()
- Specified by:
self
in classAbstractBasePane<Window>
-
-