- java.lang.Object
-
- com.googlecode.lanterna.gui2.AbstractComponent<Panel>
-
- com.googlecode.lanterna.gui2.Panel
-
- All Implemented Interfaces:
Component
,Container
,TextGUIElement
- Direct Known Subclasses:
SplitPanel
public class Panel extends AbstractComponent<Panel> implements Container
This class is the basic building block for creating user interfaces, being the standard implementation ofContainer
that supports multiple children. APanel
is a component that can contain one or more other components, including nested panels. The panel itself doesn't have any particular appearance and isn't interactable by itself, although you can set a border for the panel and interactable components inside the panel will receive input focus as expected.
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description class
Panel.DefaultPanelRenderer
-
Field Summary
Fields Modifier and Type Field Description private TerminalSize
cachedPreferredSize
private java.util.List<Component>
components
private TextColor
fillColorOverride
private LayoutManager
layoutManager
-
Constructor Summary
Constructors Constructor Description Panel()
Default constructor, creates a new panel with no child components and by default set to a verticalLinearLayout
layout manager.Panel(LayoutManager layoutManager)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description Panel
addComponent(int index, Component component)
Adds a new child component to the panel.Panel
addComponent(Component component)
Adds a new child component to the panel.Panel
addComponent(Component component, LayoutData layoutData)
This method is a shortcut for calling:TerminalSize
calculatePreferredSize()
Invokes the component renderer's size calculation logic and returns the result.boolean
containsComponent(Component component)
Returnstrue
if this container contains the supplied component either directly or indirectly through intermediate containers.protected ComponentRenderer<Panel>
createDefaultRenderer()
When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable).int
getChildCount()
Returns the number of children this container currently hasjava.util.Collection<Component>
getChildren()
Returns collection that is to be considered a copy of the list of children contained inside of this object.java.util.List<Component>
getChildrenList()
Returns list that is to be considered a copy of the list of children inside of this container.TextColor
getFillColorOverride()
Returns the color used to override the default background color from the theme, if set.LayoutManager
getLayoutManager()
Returns the layout manager assigned to this panelboolean
handleInput(KeyStroke key)
If an interactable component inside this container received a keyboard event that wasn't handled, the GUI system will recursively send the event to each parent container to give each of them a chance to consume the event.void
invalidate()
Marks the component as invalid and requiring to be re-drawn at next opportunity.boolean
isInvalid()
Checks if this element (or any of its child components, if any) has signaled that what it's currently displaying is out of date and needs re-drawing.private void
layout(TerminalSize size)
Interactable
nextFocus(Interactable fromThis)
Given an interactable, find the next one in line to receive focus.Interactable
previousFocus(Interactable fromThis)
Given an interactable, find the previous one in line to receive focus.Panel
removeAllComponents()
Removes all child components from this panelboolean
removeComponent(Component component)
Removes the component from the container.void
setFillColorOverride(TextColor fillColor)
Sets an override color to be used instead of the theme's color for Panels when drawing unused space.Panel
setLayoutManager(LayoutManager layoutManager)
Assigns a new layout manager to this panel, replacing the previous layout manager assigned.void
updateLookupMap(InteractableLookupMap interactableLookupMap)
Takes a lookup map and updates it with information about where all the interactables inside of this container are located.-
Methods inherited from class com.googlecode.lanterna.gui2.AbstractComponent
addTo, draw, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, isInside, isVisible, onAdded, onAfterDrawing, onBeforeDrawing, onRemoved, runOnGUIThreadIfExistsOtherwiseRunDirect, self, setLayoutData, setPosition, setPreferredSize, setRenderer, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
-
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.Component
addTo, getBasePane, getGlobalPosition, getLayoutData, getParent, getPosition, getPreferredSize, getRenderer, getSize, getTextGUI, getTheme, getThemeDefinition, hasParent, isInside, isVisible, onAdded, onRemoved, setLayoutData, setPosition, setPreferredSize, setSize, setTheme, setVisible, toBasePane, toGlobal, withBorder
-
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUIElement
draw
-
-
-
-
Field Detail
-
components
private final java.util.List<Component> components
-
layoutManager
private LayoutManager layoutManager
-
cachedPreferredSize
private TerminalSize cachedPreferredSize
-
fillColorOverride
private TextColor fillColorOverride
-
-
Constructor Detail
-
Panel
public Panel()
Default constructor, creates a new panel with no child components and by default set to a verticalLinearLayout
layout manager.
-
Panel
public Panel(LayoutManager layoutManager)
-
-
Method Detail
-
addComponent
public Panel addComponent(Component component)
Adds a new child component to the panel. Where within the panel the child will be displayed is up to the layout manager assigned to this panel. If the component has already been added to another panel, it will first be removed from that panel before added to this one.- Parameters:
component
- Child component to add to this panel- Returns:
- Itself
-
addComponent
public Panel addComponent(int index, Component component)
Adds a new child component to the panel. Where within the panel the child will be displayed is up to the layout manager assigned to this panel. If the component has already been added to another panel, it will first be removed from that panel before added to this one.- Parameters:
component
- Child component to add to this panelindex
- At what index to add the component among the existing components- Returns:
- Itself
-
addComponent
public Panel addComponent(Component component, LayoutData layoutData)
This method is a shortcut for calling:component.setLayoutData(layoutData); panel.addComponent(component);
- Parameters:
component
- Component to add to the panellayoutData
- Layout data to assign to the component- Returns:
- Itself
-
containsComponent
public boolean containsComponent(Component component)
Description copied from interface:Container
Returnstrue
if this container contains the supplied component either directly or indirectly through intermediate containers.- Specified by:
containsComponent
in interfaceContainer
- Parameters:
component
- Component to check if it's part of this container- Returns:
true
if the component is inside this Container, otherwisefalse
-
removeComponent
public boolean removeComponent(Component component)
Description copied from interface:Container
Removes the component from the container. This should remove the component from the Container's internal data structure as well as call the onRemoved(..) method on the component itself if it was found inside the container.- Specified by:
removeComponent
in interfaceContainer
- Parameters:
component
- Component to remove from the Container- Returns:
true
if the component existed inside the container and was removed,false
otherwise
-
removeAllComponents
public Panel removeAllComponents()
Removes all child components from this panel- Returns:
- Itself
-
setLayoutManager
public Panel setLayoutManager(LayoutManager layoutManager)
Assigns a new layout manager to this panel, replacing the previous layout manager assigned. Please note that if the panel is not empty at the time you assign a new layout manager, the existing components might not show up where you expect them and their layout data property might need to be re-assigned.- Parameters:
layoutManager
- New layout manager this panel should be using- Returns:
- Itself
-
getFillColorOverride
public TextColor getFillColorOverride()
Returns the color used to override the default background color from the theme, if set. Otherwisenull
is returned and whatever theme is assigned will be used to derive the fill color.- Returns:
- The color, if any, used to fill the panel's unused space instead of the theme's color
-
setFillColorOverride
public void setFillColorOverride(TextColor fillColor)
Sets an override color to be used instead of the theme's color for Panels when drawing unused space. If called withnull
, it will reset back to the theme's color.- Parameters:
fillColor
- Color to draw the unused space with instead of what the theme definition says, nonull
to go back to the theme definition
-
getLayoutManager
public LayoutManager getLayoutManager()
Returns the layout manager assigned to this panel- Returns:
- Layout manager assigned to this panel
-
getChildCount
public int getChildCount()
Description copied from interface:Container
Returns the number of children this container currently has- Specified by:
getChildCount
in interfaceContainer
- Returns:
- Number of children currently in this container
-
getChildren
public java.util.Collection<Component> getChildren()
Description copied from interface:Container
Returns collection that is to be considered a copy of the list of children contained inside of this object. Modifying this collection will not affect any internal state.This method isn't deprecated but it should have originally been defined as returning a List instead of a Collection. See
getChildrenList
for a method with this signature.- Specified by:
getChildren
in interfaceContainer
- Returns:
- Child-components inside of this Container
- See Also:
Container.getChildrenList()
-
getChildrenList
public java.util.List<Component> getChildrenList()
Description copied from interface:Container
Returns list that is to be considered a copy of the list of children inside of this container. Modifying this list will not affect any internal state. This method is essentially the same as getChildren but the returned collection is a list.- Specified by:
getChildrenList
in interfaceContainer
- Returns:
- Child-components inside of this Container
- See Also:
Container.getChildren()
-
createDefaultRenderer
protected ComponentRenderer<Panel> createDefaultRenderer()
Description copied from class:AbstractComponent
When you create a custom component, you need to implement this method and return a Renderer which is responsible for taking care of sizing the component, rendering it and choosing where to place the cursor (if Interactable). This value is intended to be overridden by custom themes.- Specified by:
createDefaultRenderer
in classAbstractComponent<Panel>
- Returns:
- Renderer to use when sizing and drawing this component
-
calculatePreferredSize
public TerminalSize calculatePreferredSize()
Description copied from class:AbstractComponent
Invokes the component renderer's size calculation logic and returns the result. This value represents the preferred size and isn't necessarily what it will eventually be assigned later on.- Overrides:
calculatePreferredSize
in classAbstractComponent<Panel>
- Returns:
- Size that the component renderer believes the component should be
-
isInvalid
public boolean isInvalid()
Description copied from interface:TextGUIElement
Checks if this element (or any of its child components, if any) has signaled that what it's currently displaying is out of date and needs re-drawing.- Specified by:
isInvalid
in interfaceTextGUIElement
- Overrides:
isInvalid
in classAbstractComponent<Panel>
- Returns:
true
if the component is invalid and needs redrawing,false
otherwise
-
nextFocus
public Interactable nextFocus(Interactable fromThis)
Description copied from interface:Container
Given an interactable, find the next one in line to receive focus. If the interactable isn't inside this container, this method should returnnull
.
-
previousFocus
public Interactable previousFocus(Interactable fromThis)
Description copied from interface:Container
Given an interactable, find the previous one in line to receive focus. If the interactable isn't inside this container, this method should returnnull
.- Specified by:
previousFocus
in interfaceContainer
- Parameters:
fromThis
- Component from which to get the previous interactable, or if null, pick the last interactable in the list- Returns:
- The previous interactable component, or null if there are no more interactables in the list
-
handleInput
public boolean handleInput(KeyStroke key)
Description copied from interface:Container
If an interactable component inside this container received a keyboard event that wasn't handled, the GUI system will recursively send the event to each parent container to give each of them a chance to consume the event. Returnfalse
if the implementer doesn't care about this particular keystroke and it will be automatically sent up the hierarchy the to next container. If you returntrue
, the event will stop here and won't be reported as unhandled.- Specified by:
handleInput
in interfaceContainer
- Parameters:
key
- Keystroke that was ignored by the interactable inside this container- Returns:
true
if this event was handled by this container and shouldn't be processed anymore,false
if the container didn't take any action on the event and want to pass it on
-
updateLookupMap
public void updateLookupMap(InteractableLookupMap interactableLookupMap)
Description copied from interface:Container
Takes a lookup map and updates it with information about where all the interactables inside of this container are located.- Specified by:
updateLookupMap
in interfaceContainer
- Parameters:
interactableLookupMap
- Interactable map to update
-
invalidate
public void invalidate()
Description copied from interface:Component
Marks the component as invalid and requiring to be re-drawn at next opportunity. Container components should take this as a hint to layout the child components again.- Specified by:
invalidate
in interfaceComponent
- Overrides:
invalidate
in classAbstractComponent<Panel>
-
layout
private void layout(TerminalSize size)
-
-