public interface Component extends TextGUIElement
AbstractComponent
or another one of the sub-classes instead to avoid implementing most
of the methods in this interface.Modifier and Type | Method and Description |
---|---|
Component |
addTo(Panel panel)
Same as calling
panel.addComponent(thisComponent) |
BasePane |
getBasePane()
Returns the BasePane that this container belongs to.
|
LayoutData |
getLayoutData()
Returns the layout data associated with this component.
|
Container |
getParent()
Returns the container which is holding this container, or
null 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.
|
boolean |
hasParent(Container parent)
Returns
true 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.
|
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 the
getPreferredSize() 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.
|
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.
|
draw, isInvalid
TerminalPosition getPosition()
Component setPosition(TerminalPosition position)
position
- Top-left position of the component, relative to its parentTerminalSize getSize()
Component setSize(TerminalSize size)
size
- Current size of the componentTerminalSize getPreferredSize()
Component setPreferredSize(TerminalSize explicitPreferredSize)
getPreferredSize()
always return the
value passed in here. If you call this will null
, 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.explicitPreferredSize
- Preferred size we want to use for this componentComponent setLayoutData(LayoutData data)
data
- Layout data associated with this componentLayoutData getLayoutData()
Container getParent()
null
if it's not assigned to anything.boolean hasParent(Container parent)
true
if the supplied Container is either the direct or indirect Parent of this component.parent
- Container to test if it's the parent or grand-parent of this componenttrue
if the container is either the direct or indirect parent of this component, otherwise false
TextGUI getTextGUI()
boolean isInside(Container container)
getParent()
is not the same instance as container
, but if this
method returns true, you can be sure that this component is not a direct child.container
- Container to test if this component is insidecontainer
ComponentRenderer<? extends Component> getRenderer()
void invalidate()
Border withBorder(Border border)
container.addComponent(new Button("Test").withBorder(Borders.singleLine()));
border
- TerminalPosition toBasePane(TerminalPosition position)
null
.position
- Position to translate (relative to the container's top-left corner)null
if the component is an orphanTerminalPosition toGlobal(TerminalPosition position)
null
.position
- Position to translate (relative to the container's top-left corner)null
if the component is an orphanBasePane getBasePane()
null
if noneComponent addTo(Panel panel)
panel.addComponent(thisComponent)
panel
- Panel to add this component tovoid onAdded(Container container)
container
- Container that this component was just added tovoid onRemoved(Container container)
container
- Container that this component was just removed fromCopyright © 2016. All rights reserved.