- Direct Known Subclasses:
BasicWindow
,DialogWindow
,MenuPopupWindow
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.-
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
FieldsModifier and TypeFieldDescriptionprivate boolean
private TerminalPosition
private Set
<Window.Hint> private TerminalSize
private TerminalPosition
private TerminalSize
private WindowBasedTextGUI
private String
private boolean
private WindowPostRenderer
Fields inherited from class com.googlecode.lanterna.gui2.AbstractBasePane
contentHolder, interactableLookupMap
-
Constructor Summary
ConstructorsConstructorDescriptionDefault constructor, this creates a window with no titleAbstractWindow
(String title) Creates a window with a specific title that will (probably) be drawn in the window decorations -
Method Summary
Modifier and TypeMethodDescriptionvoid
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.fromGlobal
(TerminalPosition globalPosition) Deprecated.fromGlobalToContentRelative
(TerminalPosition globalPosition) Returns a position expressed in global coordinates, i.e.fromGlobalToDecoratedRelative
(TerminalPosition globalPosition) Returns a position expressed in global coordinates, i.e.final TerminalSize
Returns the last known size of the window including window decorations put on by the window manager.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.final TerminalPosition
Returns the position of the window, as last specified by the window manager.Returns a post-renderer the GUI system should invoke after the window has been drawn.Returns the size this window would like to befinal TerminalSize
getSize()
Returns the last known size of the window.Returns the TextGUI this BasePane belongs to ornull
if none.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
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.final 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
(Collection<Window.Hint> hints) Updates the set of active hints for this window.final 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
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.toGlobal
(TerminalPosition localPosition) Deprecated.toGlobalFromContentRelative
(TerminalPosition contentLocalPosition) Returns a position in the window content's local coordinate space to global coordinatestoGlobalFromDecoratedRelative
(TerminalPosition localPosition) Deprecated.void
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 Details
-
title
-
textGUI
-
visible
private boolean visible -
lastKnownSize
-
lastKnownDecoratedSize
-
lastKnownPosition
-
contentOffset
-
hints
-
windowPostRenderer
-
closeWindowWithEscape
private boolean closeWindowWithEscape
-
-
Constructor Details
-
AbstractWindow
public AbstractWindow()Default constructor, this creates a window with no title -
AbstractWindow
Creates a window with a specific title that will (probably) be drawn in the window decorations- Parameters:
title
- Title of this window
-
-
Method Details
-
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
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
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
Alters the title of the window to the supplied string- Parameters:
title
- New title of the window
-
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
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
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.Description copied from interface:BasePane
Returns a position in a root container's local coordinate space to global coordinates -
toGlobalFromContentRelative
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.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.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:
-
fromGlobalToContentRelative
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
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
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
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
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
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
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
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
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
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
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
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.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
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
-
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
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
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>
-