Class AbstractWindow
- 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 AbstractBasePane
AbstractBasePane.ContentHolderNested classes/interfaces inherited from interface Window
Window.Hint -
Field Summary
FieldsModifier and TypeFieldDescriptionprivate booleanprivate TerminalPositionprivate Set<Window.Hint> private TerminalSizeprivate TerminalPositionprivate TerminalSizeprivate WindowBasedTextGUIprivate Stringprivate booleanprivate WindowPostRendererFields inherited from class 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 TypeMethodDescriptionvoidaddWindowListener(WindowListener windowListener) Adds aWindowListenerto thisWindow.voidclose()Closes the window, which will remove it from the GUIvoiddraw(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 TerminalSizeReturns 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 TerminalPositionReturns 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 TerminalSizegetSize()Returns the last known size of the window.Returns the TextGUI this BasePane belongs to ornullif 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 theWindowDecorationRendererused by theTextGUIbooleanhandleInput(KeyStroke key) Called by the GUI system to delegate a keyboard input event.booleanThis values is optionally used by the window manager to decide if the windows should be drawn or not.voidremoveWindowListener(WindowListener windowListener) Removes aWindowListenerfrom thisWindow.(package private) Windowself()voidsetCloseWindowWithEscape(boolean closeWindowWithEscape) Setting this property totruewill cause pressing the ESC key to close the window.voidsetContentOffset(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 voidsetDecoratedSize(TerminalSize decoratedSize) This method is called by the GUI system to update the window on how large it is, counting window decorations too.voidsetFixedSize(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.voidsetHints(Collection<Window.Hint> hints) Updates the set of active hints for this window.final voidsetPosition(TerminalPosition topLeft) This method is called by the GUI system to update the window on where the window manager placed it.voidsetSize(TerminalSize size) Deprecated.private voidsetSize(TerminalSize size, boolean invalidate) voidsetTextGUI(WindowBasedTextGUI textGUI) DON'T CALL THIS METHOD YOURSELF, it is called automatically by the TextGUI system when you add a window.voidAlters the title of the window to the supplied stringvoidsetVisible(boolean visible) This values is optionally used by the window manager to decide if the windows should be drawn or not.voidsetWindowPostRenderer(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.voidWaits for the window to close.Methods inherited from class AbstractBasePane
addBasePaneListener, getBasePaneListeners, getComponent, getCursorPosition, getFocusedInteractable, getMenuBar, getTheme, invalidate, isInvalid, removeBasePaneListener, setComponent, setEnableDirectionBasedMovements, setFocusedInteractable, setFocusedInteractable, setMenuBar, setStrictFocusChange, setThemeMethods inherited from class Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, waitMethods inherited from interface BasePane
getTheme, setEnableDirectionBasedMovements, setStrictFocusChange, setThemeMethods inherited from interface 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 totruewill 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:WindowDON'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:
setTextGUIin interfaceWindow- Parameters:
textGUI- TextGUI this window belongs to from now on
-
getTextGUI
Description copied from interface:BasePaneReturns the TextGUI this BasePane belongs to ornullif none. One example of when this method returnsnullis when calling it on a Window that hasn't been displayed yet.- Specified by:
getTextGUIin interfaceBasePane- Specified by:
getTextGUIin 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:WindowThis method returns the title of the window, which is normally drawn at the top-left corder of the window decoration, but depending on theWindowDecorationRendererused by theTextGUI -
isVisible
public boolean isVisible()Description copied from interface:WindowThis 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:WindowThis 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:
setVisiblein interfaceWindow- Parameters:
visible- whether the window should be visible or not
-
draw
Description copied from interface:BasePaneCalled 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:BasePaneCalled 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 returnfalseso that the GUI system can take further decisions on what to do with it.- Specified by:
handleInputin interfaceBasePane- Specified by:
handleInputin interfaceWindow- Overrides:
handleInputin classAbstractBasePane<Window>- Parameters:
key- Keyboard input- Returns:
trueIf the root container could handle the input, false otherwise
-
toGlobal
Deprecated.Description copied from interface:BasePaneReturns a position in a root container's local coordinate space to global coordinates -
toGlobalFromContentRelative
Description copied from interface:WindowReturns a position in the window content's local coordinate space to global coordinates- Specified by:
toGlobalFromContentRelativein interfaceWindow- Parameters:
contentLocalPosition- The local position to translate- Returns:
- The local position translated to global coordinates
-
toGlobalFromDecoratedRelative
Deprecated.Description copied from interface:WindowReturns a position in the decorated window local coordinate space to global coordinates- Specified by:
toGlobalFromDecoratedRelativein interfaceWindow- Parameters:
localPosition- The local position to translate- Returns:
- The local position translated to global coordinates
-
fromGlobal
Deprecated.Description copied from interface:BasePaneReturns 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:
fromGlobalin interfaceBasePane- Specified by:
fromGlobalin 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:WindowReturns 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:
fromGlobalToContentRelativein 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:WindowReturns 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:
fromGlobalToDecoratedRelativein 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:WindowReturns the size this window would like to be- Specified by:
getPreferredSizein interfaceWindow- Returns:
- Desired size of this window
-
setHints
Description copied from interface:WindowUpdates 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:WindowReturns 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:WindowReturns 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:
getPostRendererin interfaceWindow- Returns:
WindowPostRendererto invoke after this window is drawn, ornullfallback to the GUI system's default.
-
addWindowListener
Description copied from interface:WindowAdds aWindowListenerto thisWindow. If it has already been added, the call will do nothing.- Specified by:
addWindowListenerin interfaceWindow- Parameters:
windowListener- Listener to attach to thisWindow
-
removeWindowListener
Description copied from interface:WindowRemoves aWindowListenerfrom thisWindow. If the listener isn't in the list of listeners, this call does nothing.- Specified by:
removeWindowListenerin 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:WindowReturns 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:
getPositionin 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:WindowThis 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:
setPositionin interfaceWindow- Parameters:
topLeft- Global coordinates of the top-left corner of the window
-
getSize
Description copied from interface:WindowReturns 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:WindowThis 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 callsetDecoratedSizeinstead of this when decided the size of the window. -
setFixedSize
Description copied from interface:WindowCalling 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 theWindowManagerif this size and hint are going to be honored.- Specified by:
setFixedSizein interfaceWindow- Parameters:
size- New size of your fixed-size window
-
setSize
-
getDecoratedSize
Description copied from interface:WindowReturns 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:
getDecoratedSizein interfaceWindow- Returns:
- Size of the window, including window decorations
-
setDecoratedSize
Description copied from interface:WindowThis 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 ofsetSizewhen decided the size of the window.- Specified by:
setDecoratedSizein interfaceWindow- Parameters:
decoratedSize- Size of the window, including window decorations
-
setContentOffset
Description copied from interface:WindowThis 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:
setContentOffsetin interfaceWindow- Parameters:
offset- Offset from the top-left corner of the window (including decorations) to the top-left corner of the content area.
-
close
-
waitUntilClosed
public void waitUntilClosed()Description copied from interface:WindowWaits 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:
waitUntilClosedin interfaceWindow
-
self
Window self()- Specified by:
selfin classAbstractBasePane<Window>
-