Module com.googlecode.lanterna
Package com.googlecode.lanterna.gui2
Class AbstractBasePane<T extends BasePane>
- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractBasePane<T>
-
- Direct Known Subclasses:
AbstractWindow
public abstract class AbstractBasePane<T extends BasePane> extends java.lang.Object implements BasePane
This abstract implementation ofBasePane
has the common code shared by all different concrete implementations.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description protected class
AbstractBasePane.ContentHolder
private static class
AbstractBasePane.EmptyMenuBar
-
Field Summary
Fields Modifier and Type Field Description protected AbstractBasePane.ContentHolder
contentHolder
private boolean
enableDirectionBasedMovements
private Interactable
focusedInteractable
protected InteractableLookupMap
interactableLookupMap
private boolean
invalid
private java.util.concurrent.CopyOnWriteArrayList<BasePaneListener<T>>
listeners
private Interactable
mouseDownForDrag
private boolean
strictFocusChange
private Theme
theme
-
Constructor Summary
Constructors Modifier Constructor Description protected
AbstractBasePane()
-
Method Summary
All Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description protected void
addBasePaneListener(BasePaneListener<T> basePaneListener)
private boolean
doHandleInput(KeyStroke key)
void
draw(TextGUIGraphics graphics)
Called by the GUI system (or something imitating the GUI system) to draw the root container.protected java.util.List<BasePaneListener<T>>
getBasePaneListeners()
Component
getComponent()
Returns the component that is the content of the BasePane.TerminalPosition
getCursorPosition()
Returns the position of where to put the terminal cursor according to this root container.Interactable
getFocusedInteractable()
Returns the component in the root container that currently has input focus.MenuBar
getMenuBar()
Returns theMenuBar
assigned to this base pane/window, if any, otherwise returns {code null}.Theme
getTheme()
Returns the text GUITheme
associated with this base pane/window.boolean
handleInput(KeyStroke key)
Called by the GUI system to delegate a keyboard input event.private boolean
handleMouseInput(MouseAction mouseAction)
void
invalidate()
Invalidates the whole root container (including all of its child components) which will cause them all to be recalculated (for containers) and redrawn.boolean
isInvalid()
Checks if this root container (i.e.protected void
removeBasePaneListener(BasePaneListener<T> basePaneListener)
(package private) abstract T
self()
void
setComponent(Component component)
Sets the top-level component inside this BasePane.void
setEnableDirectionBasedMovements(boolean enableDirectionBasedMovements)
If set to false, using the keyboard arrows keys will have the same effect as using the tab and reverse tab.void
setFocusedInteractable(Interactable toFocus)
Sets the component currently in focus within this root container, or sets no component in focus ifnull
is passed in.protected void
setFocusedInteractable(Interactable toFocus, Interactable.FocusChangeDirection direction)
void
setMenuBar(MenuBar menuBar)
Sets the activeMenuBar
for this base pane/window.void
setStrictFocusChange(boolean strictFocusChange)
If set to true, up/down array keys will not translate to next/previous if there are no more components above/below.void
setTheme(Theme theme)
-
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
fromGlobal, getTextGUI, toGlobal
-
-
-
-
Field Detail
-
contentHolder
protected final AbstractBasePane.ContentHolder contentHolder
-
listeners
private final java.util.concurrent.CopyOnWriteArrayList<BasePaneListener<T extends BasePane>> listeners
-
interactableLookupMap
protected InteractableLookupMap interactableLookupMap
-
focusedInteractable
private Interactable focusedInteractable
-
invalid
private boolean invalid
-
strictFocusChange
private boolean strictFocusChange
-
enableDirectionBasedMovements
private boolean enableDirectionBasedMovements
-
theme
private Theme theme
-
mouseDownForDrag
private Interactable mouseDownForDrag
-
-
Method Detail
-
isInvalid
public boolean isInvalid()
Description copied from interface:BasePane
Checks if this root container (i.e. any of its child components) has signaled that what it's currently displaying is out of date and needs re-drawing.
-
invalidate
public void invalidate()
Description copied from interface:BasePane
Invalidates the whole root container (including all of its child components) which will cause them all to be recalculated (for containers) and redrawn.- Specified by:
invalidate
in interfaceBasePane
-
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
- Parameters:
key
- Keyboard input- Returns:
true
If the root container could handle the input, false otherwise
-
self
abstract T self()
-
doHandleInput
private boolean doHandleInput(KeyStroke key)
-
handleMouseInput
private boolean handleMouseInput(MouseAction mouseAction)
-
getComponent
public Component getComponent()
Description copied from interface:BasePane
Returns the component that is the content of the BasePane. This is probably the root of a hierarchy of nested Panels but it could also be a single component.- Specified by:
getComponent
in interfaceBasePane
- Specified by:
getComponent
in interfaceComposite
- Returns:
- Component which is the content of this BasePane
-
setComponent
public void setComponent(Component component)
Description copied from interface:BasePane
Sets the top-level component inside this BasePane. If you want it to contain only one component, you can set it directly, but for more complicated GUIs you probably want to create a hierarchy of panels and set the first one here.- Specified by:
setComponent
in interfaceBasePane
- Specified by:
setComponent
in interfaceComposite
- Parameters:
component
- Component which this BasePane is using as it's content
-
getFocusedInteractable
public Interactable getFocusedInteractable()
Description copied from interface:BasePane
Returns the component in the root container 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
-
getCursorPosition
public TerminalPosition getCursorPosition()
Description copied from interface:BasePane
Returns the position of where to put the terminal cursor according to this root container. This is typically derived from which component has focus, ornull
if no component has focus or if the root container 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 root container. 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
-
setFocusedInteractable
public void setFocusedInteractable(Interactable toFocus)
Description copied from interface:BasePane
Sets the component currently in focus within this root container, or sets no component in focus ifnull
is passed in.- Specified by:
setFocusedInteractable
in interfaceBasePane
- Parameters:
toFocus
- Interactable to focus, ornull
to clear focus
-
setFocusedInteractable
protected void setFocusedInteractable(Interactable toFocus, Interactable.FocusChangeDirection direction)
-
setStrictFocusChange
public void setStrictFocusChange(boolean strictFocusChange)
Description copied from interface:BasePane
If set to true, up/down array keys will not translate to next/previous if there are no more components above/below.- Specified by:
setStrictFocusChange
in interfaceBasePane
- Parameters:
strictFocusChange
- Will not allow relaxed navigation if set totrue
-
setEnableDirectionBasedMovements
public void setEnableDirectionBasedMovements(boolean enableDirectionBasedMovements)
Description copied from interface:BasePane
If set to false, using the keyboard arrows keys will have the same effect as using the tab and reverse tab. Lanterna will map arrow down and arrow right to tab, going to the next component, and array up and array left to reverse tab, going to the previous component. If set to true, Lanterna will search for the next component starting at the cursor position in the general direction of the arrow. By default this is enabled.In Lanterna 2, direction based movements were not available.
- Specified by:
setEnableDirectionBasedMovements
in interfaceBasePane
- Parameters:
enableDirectionBasedMovements
- Should direction based focus movements be enabled?
-
getTheme
public Theme getTheme()
Description copied from interface:BasePane
Returns the text GUITheme
associated with this base pane/window. This is either coming from theTextGUI
this object is associated with, the theme set as the override throughBasePane.setTheme(Theme)
ornull
if this base pane/window isn't added to anyTextGUI
and doesn't have any override.
-
getMenuBar
public MenuBar getMenuBar()
Description copied from interface:BasePane
Returns theMenuBar
assigned to this base pane/window, if any, otherwise returns {code null}.- Specified by:
getMenuBar
in interfaceBasePane
- Returns:
- The active menu bar or
null
-
setMenuBar
public void setMenuBar(MenuBar menuBar)
Description copied from interface:BasePane
Sets the activeMenuBar
for this base pane/window. The menu will be rendered at the top (inside the window decorations if set on a window), if set. If called withnull
, any previously set menu bar is removed.- Specified by:
setMenuBar
in interfaceBasePane
- Parameters:
menuBar
- TheMenuBar
to assign to this pane/window
-
addBasePaneListener
protected void addBasePaneListener(BasePaneListener<T> basePaneListener)
-
removeBasePaneListener
protected void removeBasePaneListener(BasePaneListener<T> basePaneListener)
-
getBasePaneListeners
protected java.util.List<BasePaneListener<T>> getBasePaneListeners()
-
-