-
- All Superinterfaces:
TextGUIElement
- All Known Subinterfaces:
Border
,Container
,Interactable
- All Known Implementing Classes:
AbstractBasePane.ContentHolder
,AbstractBasePane.EmptyMenuBar
,AbstractBorder
,AbstractComponent
,AbstractComposite
,AbstractInteractableComponent
,AbstractListBox
,ActionListBox
,AnimatedLabel
,Borders.DoubleLine
,Borders.SingleLine
,Borders.StandardBorder
,Button
,CheckBox
,CheckBoxList
,ComboBox
,EmptySpace
,FileDialog.FileSystemLocationLabel
,GUIBackdrop
,ImageComponent
,Label
,Menu
,MenuBar
,MenuItem
,Panel
,ProgressBar
,RadioBoxList
,ScrollBar
,Separator
,SplitPanel
,Table
,TextBox
public interface Component extends TextGUIElement
This is the main interface defining a component in Lanterna, although you will probably not implement this directly but rather extend theAbstractComponent
or another one of the sub-classes instead to avoid implementing most of the methods in this interface.
-
-
Method Summary
All Methods Instance Methods Abstract Methods Modifier and Type Method Description Component
addTo(Panel panel)
Same as callingpanel.addComponent(thisComponent)
BasePane
getBasePane()
Returns the BasePane that this container belongs to.TerminalPosition
getGlobalPosition()
Returns the top-left corner of this component in global coordinates space usingTerminalPosition.TOP_LEFT_CORNER
withtoGlobal(TerminalPosition)
LayoutData
getLayoutData()
Returns the layout data associated with this component.Container
getParent()
Returns the container which is holding this container, ornull
if it's not assigned to anything.TerminalPosition
getPosition()
Returns the top-left corner of this component, measured from its parent.TerminalSize
getPreferredSize()
Returns the ideal size this component would like to have, in order to draw itself properly.ComponentRenderer<? extends Component>
getRenderer()
Returns the renderer used to draw this component and measure its preferred size.TerminalSize
getSize()
Returns how large this component is.TextGUI
getTextGUI()
Returns the TextGUI that this component is currently part of.Theme
getTheme()
Returns theTheme
this component should be rendered using.ThemeDefinition
getThemeDefinition()
Returns theThemeDefinition
defined in the currentTheme
for this component class.boolean
hasParent(Container parent)
Returnstrue
if the supplied Container is either the direct or indirect Parent of this component.void
invalidate()
Marks the component as invalid and requiring to be re-drawn at next opportunity.boolean
isInside(Container container)
Returns true if this component is inside of the specified Container.boolean
isVisible()
Returns the component's own state as to if it should be visible or not.void
onAdded(Container container)
Called by the GUI system when you add a component to a container; DO NOT CALL THIS YOURSELF!void
onRemoved(Container container)
Called by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!Component
setLayoutData(LayoutData data)
Sets optional layout data associated with this component.Component
setPosition(TerminalPosition position)
This method will be called by the layout manager when it has decided where the component is to be located.Component
setPreferredSize(TerminalSize explicitPreferredSize)
Overrides the components preferred size calculation and makes thegetPreferredSize()
always return the value passed in here.Component
setSize(TerminalSize size)
This method will be called by the layout manager when it has decided how large the component will be.Component
setTheme(Theme theme)
Overrides theTheme
this component will use so rather than deriving the theme from either the window or the GUI system, it will always return this theme.Component
setVisible(boolean visible)
Sets the component's own state as to if it should be visible or not.TerminalPosition
toBasePane(TerminalPosition position)
Translates a position local to the container to the base pane's coordinate space.TerminalPosition
toGlobal(TerminalPosition position)
Translates a position local to the container to global coordinate space.Border
withBorder(Border border)
Takes a border object and moves this component inside it and then returns it again.-
Methods inherited from interface com.googlecode.lanterna.gui2.TextGUIElement
draw, isInvalid
-
-
-
-
Method Detail
-
getPosition
TerminalPosition getPosition()
Returns the top-left corner of this component, measured from its parent.- Returns:
- Position of this component
-
getGlobalPosition
TerminalPosition getGlobalPosition()
Returns the top-left corner of this component in global coordinates space usingTerminalPosition.TOP_LEFT_CORNER
withtoGlobal(TerminalPosition)
- Returns:
- global position of this component
-
setPosition
Component setPosition(TerminalPosition position)
This method will be called by the layout manager when it has decided where the component is to be located. If you call this method yourself, prepare for unexpected results.- Parameters:
position
- Top-left position of the component, relative to its parent- Returns:
- Itself
-
getSize
TerminalSize getSize()
Returns how large this component is. If the layout manager has not yet laid this component out, it will return an empty size (0x0)- Returns:
- How large this component is
-
setSize
Component setSize(TerminalSize size)
This method will be called by the layout manager when it has decided how large the component will be. If you call this method yourself, prepare for unexpected results.- Parameters:
size
- Current size of the component- Returns:
- Itself
-
getPreferredSize
TerminalSize getPreferredSize()
Returns the ideal size this component would like to have, in order to draw itself properly. There are no guarantees the GUI system will decide to give it this size though.- Returns:
- Size we would like to be
-
setPreferredSize
Component setPreferredSize(TerminalSize explicitPreferredSize)
Overrides the components preferred size calculation and makes thegetPreferredSize()
always return the value passed in here. If you call this willnull
, it will re-enable the preferred size calculation again. Please note that using this method on components that are not designed to work with arbitrary sizes make have unexpected behaviour.- Parameters:
explicitPreferredSize
- Preferred size we want to use for this component- Returns:
- Itself
-
setLayoutData
Component setLayoutData(LayoutData data)
Sets optional layout data associated with this component. This meaning of this data is up to the layout manager to figure out, see each layout manager for examples of how to use it.- Parameters:
data
- Layout data associated with this component- Returns:
- Itself
-
getLayoutData
LayoutData getLayoutData()
Returns the layout data associated with this component. This data will optionally be used by the layout manager, see the documentation for each layout manager for more details on valid values and their meaning.- Returns:
- This component's layout data
-
isVisible
boolean isVisible()
Returns the component's own state as to if it should be visible or not. The exact behavior of an invisible component will depend on the layout manager; some will just ignore invisible components where others leave an empty space in their place. Invisible components cannot get input focus. The visibility value of the component has no effect if the component is not added to a container.- Returns:
- The component's internal visibility state
-
setVisible
Component setVisible(boolean visible)
Sets the component's own state as to if it should be visible or not. The exact behavior of an invisible component will depend on the layout manager; some will just ignore invisible components where others leave an empty space in their place. Invisible components cannot get input focus. The visibility value of the component has no effect if the component is not added to a container.- Parameters:
visible
-true
if the component should be visible,false
otherwise- Returns:
- Itself
-
getParent
Container getParent()
Returns the container which is holding this container, ornull
if it's not assigned to anything.- Returns:
- Parent container or null
-
hasParent
boolean hasParent(Container parent)
Returnstrue
if the supplied Container is either the direct or indirect Parent of this component.- Parameters:
parent
- Container to test if it's the parent or grand-parent of this component- Returns:
true
if the container is either the direct or indirect parent of this component, otherwisefalse
-
getTextGUI
TextGUI getTextGUI()
Returns the TextGUI that this component is currently part of. If the component hasn't been added to any container or in any other way placed into a GUI system, this method will return null.- Returns:
- The TextGUI that this component belongs to, or null if none
-
getTheme
Theme getTheme()
Returns theTheme
this component should be rendered using. The default implementation throughAbstractComponent
will retrieve this from theWindow
the component belongs to, or return the default theme if the component has not been added to a window yet. You can override the theme this component is assigned to by callingsetTheme(Theme)
.- Returns:
- The currently active
Theme
for this component
-
getThemeDefinition
ThemeDefinition getThemeDefinition()
Returns theThemeDefinition
defined in the currentTheme
for this component class. The is the same as calling:component.getTheme().getThemeDefinition(ComponentClassType.class); // i.e button.getTheme().getThemeDefinition(Button.class);
- Returns:
ThemeDefinition
defined in the currentTheme
for this component class
-
setTheme
Component setTheme(Theme theme)
Overrides theTheme
this component will use so rather than deriving the theme from either the window or the GUI system, it will always return this theme. If you call this withnull
, it remove the override and the next call togetTheme()
will again try to derive the theme by looking at the window or the GUI system.- Parameters:
theme
-Theme
to assign to this component, ornull
to use whatever the window uses- Returns:
- Itself
-
isInside
boolean isInside(Container container)
Returns true if this component is inside of the specified Container. It might be a direct child or not, this method makes no difference. IfgetParent()
is not the same instance ascontainer
, but if this method returns true, you can be sure that this component is not a direct child.- Parameters:
container
- Container to test if this component is inside- Returns:
- True if this component is contained in some way within the
container
-
getRenderer
ComponentRenderer<? extends Component> getRenderer()
Returns the renderer used to draw this component and measure its preferred size. You probably won't need to call this method unless you know exactly which ComponentRenderer implementation is used and you need to customize it.- Returns:
- Renderer this component is using
-
invalidate
void invalidate()
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.
-
withBorder
Border withBorder(Border border)
Takes a border object and moves this component inside it and then returns it again. This makes it easy to quickly wrap a component on creation, like this:container.addComponent(new Button("Test").withBorder(Borders.singleLine()));
- Parameters:
border
- Border to wrap the component with- Returns:
- The border with this component wrapped
-
toBasePane
TerminalPosition toBasePane(TerminalPosition position)
Translates a position local to the container to the base pane's coordinate space. For a window-based GUI, this be a coordinate in the window's coordinate space. If the component belongs to no base pane, it will returnnull
.- Parameters:
position
- Position to translate (relative to the container's top-left corner)- Returns:
- Position in base pane space, or
null
if the component is an orphan
-
toGlobal
TerminalPosition toGlobal(TerminalPosition position)
Translates a position local to the container to global coordinate space. This should be the absolute coordinate in the terminal screen, taking no windows or containers into account. If the component belongs to no base pane, it will returnnull
.- Parameters:
position
- Position to translate (relative to the container's top-left corner)- Returns:
- Position in global (or absolute) coordinates, or
null
if the component is an orphan
-
getBasePane
BasePane getBasePane()
Returns the BasePane that this container belongs to. In a window-based GUI system, this will be a Window.- Returns:
- The base pane this component is placed on, or
null
if none
-
addTo
Component addTo(Panel panel)
Same as callingpanel.addComponent(thisComponent)
- Parameters:
panel
- Panel to add this component to- Returns:
- Itself
-
onAdded
void onAdded(Container container)
Called by the GUI system when you add a component to a container; DO NOT CALL THIS YOURSELF!- Parameters:
container
- Container that this component was just added to
-
onRemoved
void onRemoved(Container container)
Called by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!- Parameters:
container
- Container that this component was just removed from
-
-