- All Known Implementing Classes:
AbstractWindow
,ActionListDialog
,BasicWindow
,ComboBox.PopupWindow
,DialogWindow
,DirectoryDialog
,FileDialog
,ListSelectDialog
,MenuPopupWindow
,MessageDialog
,TextInputDialog
,WaitingDialog
Window is a base unit in the TextGUI system, it represents a collection of components grouped together, usually
surrounded by a border and a title. Modern computer system GUIs are normally based around the metaphor of windows,
so I don't think you should have any problems understanding what this means.
-
Nested Class Summary
Nested ClassesModifier and TypeInterfaceDescriptionstatic class
Window hints are meta-data stored along with the window that can be used to give the GUI system some ideas of how this window wants to be treated. -
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 window.fromGlobal
(TerminalPosition position) Deprecated.fromGlobalToContentRelative
(TerminalPosition position) Returns a position expressed in global coordinates, i.e.Returns a position expressed in global coordinates, i.e.default TerminalRectangle
Return the last known size of the window including window decoration and the window position as a TerminalRectangle.Returns the component which is the top-level in the component hierarchy inside this window.Returns the position of where to put the terminal cursor according to this window.Returns the last known size of the window including window decorations put on by the window manager.Returns the component in the window that currently has input focus.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.Returns theMenuBar
assigned to this window, if any, otherwise returns {code null}.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 begetSize()
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's window manager when it has decided that this window should receive the keyboard input.void
Invalidates the whole window (including all of its child components) which will cause it to be recalculated and redrawn.boolean
This method is used to determine if the window requires re-drawing.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
.void
setComponent
(Component component) Sets the top-level component in the window, this will be the only component unless it's a container of some kind that you add child-components to.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
setFocusedInteractable
(Interactable interactable) Sets the component currently in focus within this window, or sets no component in focus ifnull
is passed in.void
setHints
(Collection<Window.Hint> hints) Updates the set of active hints for this window.void
setMenuBar
(MenuBar menubar) Sets the activeMenuBar
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.This method is deprecated now as it probably doesn't do what you think.void
setTextGUI
(WindowBasedTextGUI textGUI) DON'T CALL THIS METHOD YOURSELF, it is called automatically by the TextGUI system when you add a window.void
setVisible
(boolean visible) This values is optionally used by the window manager to decide if the windows should be drawn or not.toGlobal
(TerminalPosition localPosition) Deprecated.This is deprecated in favor of calling either of:toGlobalFromContentRelative()
ortoGlobalFromDecoratedRelative()
.toGlobalFromContentRelative
(TerminalPosition localPosition) Returns a position in the window content's local coordinate space to global coordinatestoGlobalFromDecoratedRelative
(TerminalPosition decoratedPosition) Returns a position in the decorated window local coordinate space to global coordinatesvoid
Waits for the window to close.Methods inherited from interface com.googlecode.lanterna.gui2.BasePane
getTheme, setEnableDirectionBasedMovements, setStrictFocusChange, setTheme
-
Method Details
-
getTextGUI
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
- Returns:
- The TextGUI this BasePane belongs to
-
setTextGUI
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.- Parameters:
textGUI
- TextGUI this window belongs to from now on
-
getTitle
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
- Returns:
- title of the window
-
isVisible
boolean isVisible()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.- Returns:
- Whether the window wants to be visible or not
-
setVisible
void setVisible(boolean visible) 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.- Parameters:
visible
- whether the window should be visible or not
-
isInvalid
boolean isInvalid()This method is used to determine if the window requires re-drawing. The most common cause for this is the some of its components has changed and we need a re-draw to make these changes visible. -
invalidate
void invalidate()Invalidates the whole window (including all of its child components) which will cause it to be recalculated and redrawn.- Specified by:
invalidate
in interfaceBasePane
-
getBounds
Return the last known size of the window including window decoration and the window position as a TerminalRectangle.- Returns:
- the decorated size and position of the window
-
getPreferredSize
TerminalSize getPreferredSize()Returns the size this window would like to be- Returns:
- Desired size of this window
-
close
void close()Closes the window, which will remove it from the GUI -
setHints
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.- Parameters:
hints
- Set of hints to be active for this window
-
getHints
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.- Returns:
- Set of hints defined for this window
-
getPosition
TerminalPosition getPosition()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.- Returns:
- Position, relative to the top-left corner of the terminal, of the top-left corner of the window
-
setPosition
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.- Parameters:
topLeft
- Global coordinates of the top-left corner of the window
-
getSize
TerminalSize getSize()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.- Returns:
- Size of the window
-
setSize
Deprecated.This method is deprecated now as it probably doesn't do what you think. Please usesetFixedSize
orsetDecoratedSize
instead, depending on what you are trying to do.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.- Parameters:
size
- New size of your fixed-size window
-
setFixedSize
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.- Parameters:
size
- New size of your fixed-size window
-
getDecoratedSize
TerminalSize getDecoratedSize()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(..)
.- Returns:
- Size of the window, including window decorations
-
setDecoratedSize
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.- Parameters:
decoratedSize
- Size of the window, including window decorations
-
setContentOffset
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.- Parameters:
offset
- Offset from the top-left corner of the window (including decorations) to the top-left corner of the content area.
-
waitUntilClosed
void waitUntilClosed()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. -
getPostRenderer
WindowPostRenderer getPostRenderer()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.- Returns:
WindowPostRenderer
to invoke after this window is drawn, ornull
fallback to the GUI system's default.
-
addWindowListener
Adds aWindowListener
to thisWindow
. If it has already been added, the call will do nothing.- Parameters:
windowListener
- Listener to attach to thisWindow
-
removeWindowListener
Removes aWindowListener
from thisWindow
. If the listener isn't in the list of listeners, this call does nothing.- Parameters:
windowListener
- Listener to remove from thisWindow
-
draw
Called by the GUI system (or something imitating the GUI system) to draw the window. The TextGUIGraphics object should be used to perform the drawing operations. -
handleInput
Called by the GUI system's window manager when it has decided that this window should receive the keyboard input. The window 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 window manager can take further decisions on what to do with it.- Specified by:
handleInput
in interfaceBasePane
- Parameters:
key
- Keyboard input- Returns:
true
If the window could handle the input, false otherwise
-
setComponent
Sets the top-level component in the window, this will be the only component unless it's a container of some kind that you add child-components to.- Specified by:
setComponent
in interfaceBasePane
- Specified by:
setComponent
in interfaceComposite
- Parameters:
component
- Component to use as the top-level object in the Window
-
getComponent
Component getComponent()Returns the component which is the top-level in the component hierarchy inside this window.- Specified by:
getComponent
in interfaceBasePane
- Specified by:
getComponent
in interfaceComposite
- Returns:
- Top-level component in the window
-
getFocusedInteractable
Interactable getFocusedInteractable()Returns the component in the window that currently has input focus. There can only be one component at a time being in focus.- Specified by:
getFocusedInteractable
in interfaceBasePane
- Returns:
- Interactable component that is currently in receiving input focus
-
setFocusedInteractable
Sets the component currently in focus within this window, or sets no component in focus ifnull
is passed in.- Specified by:
setFocusedInteractable
in interfaceBasePane
- Parameters:
interactable
- Interactable to focus, ornull
to clear focus
-
getCursorPosition
TerminalPosition getCursorPosition()Returns the position of where to put the terminal cursor according to this window. This is typically derived from which component has focus, ornull
if no component has focus or if the window doesn't want the cursor to be visible. Note that the coordinates are in local coordinate space, relative to the top-left corner of the window. You can use your TextGUI implementation to translate these to global coordinates.- Specified by:
getCursorPosition
in interfaceBasePane
- Returns:
- Local position of where to place the cursor, or
null
if the cursor shouldn't be visible
-
toGlobal
Deprecated.This is deprecated in favor of calling either of:toGlobalFromContentRelative()
ortoGlobalFromDecoratedRelative()
.Description copied from interface:BasePane
Returns a position in a root container's local coordinate space to global coordinates -
toGlobalFromContentRelative
Returns a position in the window content's local coordinate space to global coordinates- Parameters:
localPosition
- The local position to translate- Returns:
- The local position translated to global coordinates
-
toGlobalFromDecoratedRelative
Returns a position in the decorated window local coordinate space to global coordinates- Parameters:
decoratedPosition
- The local position to translate- Returns:
- The local position translated to global coordinates
-
fromGlobal
Deprecated.This is deprecated in favor of calling either of:fromGlobalToContentRelative()
orfromGlobalToDecoratedRelative()
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
- Parameters:
position
- Position expressed in global coordinates to translate to local coordinates of this BasePane- Returns:
- The global coordinates expressed as local coordinates
- See Also:
-
fromGlobalToContentRelative
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.- Parameters:
position
- Position expressed in global coordinates to translate to local coordinates of this Window's content.- Returns:
- The global coordinates expressed as local coordinates
-
fromGlobalToDecoratedRelative
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.- Parameters:
position
- 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
-
getMenuBar
MenuBar getMenuBar()Returns theMenuBar
assigned to this window, if any, otherwise returns {code null}.- Specified by:
getMenuBar
in interfaceBasePane
- Returns:
- The active menu bar or
null
-
fromGlobalToContentRelative()
orfromGlobalToDecoratedRelative()