2 * This file is part of lanterna (http://code.google.com/p/lanterna/).
4 * lanterna is free software: you can redistribute it and/or modify
5 * it under the terms of the GNU Lesser General Public License as published by
6 * the Free Software Foundation, either version 3 of the License, or
7 * (at your option) any later version.
9 * This program is distributed in the hope that it will be useful,
10 * but WITHOUT ANY WARRANTY; without even the implied warranty of
11 * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
12 * GNU Lesser General Public License for more details.
14 * You should have received a copy of the GNU Lesser General Public License
15 * along with this program. If not, see <http://www.gnu.org/licenses/>.
17 * Copyright (C) 2010-2015 Martin
19 package com
.googlecode
.lanterna
.gui2
;
21 import com
.googlecode
.lanterna
.TerminalPosition
;
22 import com
.googlecode
.lanterna
.TerminalSize
;
25 * This is the main interface defining a component in Lanterna, although you will probably not implement this directly
26 * but rather extend the {@code AbstractComponent} or another one of the sub-classes instead to avoid implementing most
27 * of the methods in this interface.
30 public interface Component
extends TextGUIElement
{
32 * Returns the top-left corner of this component, measured from its parent.
33 * @return Position of this component
35 TerminalPosition
getPosition();
38 * This method will be called by the layout manager when it has decided where the component is to be located. If you
39 * call this method yourself, prepare for unexpected results.
40 * @param position Top-left position of the component, relative to its parent
43 Component
setPosition(TerminalPosition position
);
46 * Returns how large this component is. If the layout manager has not yet laid this component out, it will return
48 * @return How large this component is
50 TerminalSize
getSize();
53 * This method will be called by the layout manager when it has decided how large the component will be. If you call
54 * this method yourself, prepare for unexpected results.
55 * @param size Current size of the component
58 Component
setSize(TerminalSize size
);
61 * Returns the ideal size this component would like to have, in order to draw itself properly. There are no
62 * guarantees the GUI system will decide to give it this size though.
63 * @return Size we would like to be
65 TerminalSize
getPreferredSize();
69 * Overrides the components preferred size calculation and makes the {@code getPreferredSize()} always return the
70 * value passed in here. If you call this will {@code null}, it will re-enable the preferred size calculation again.
71 * Please note that using this method on components that are not designed to work with arbitrary sizes make have
72 * unexpected behaviour.
73 * @param explicitPreferredSize Preferred size we want to use for this component
76 Component
setPreferredSize(TerminalSize explicitPreferredSize
);
79 * Sets optional layout data associated with this component. This meaning of this data is up to the layout manager
80 * to figure out, see each layout manager for examples of how to use it.
81 * @param data Layout data associated with this component
84 Component
setLayoutData(LayoutData data
);
87 * Returns the layout data associated with this component. This data will optionally be used by the layout manager,
88 * see the documentation for each layout manager for more details on valid values and their meaning.
89 * @return This component's layout data
91 LayoutData
getLayoutData();
94 * Returns the container which is holding this container, or {@code null} if it's not assigned to anything.
95 * @return Parent container or null
97 Container
getParent();
100 * Returns {@code true} if the supplied Container is either the direct or indirect Parent of this component.
101 * @param parent Container to test if it's the parent or grand-parent of this component
102 * @return {@code true} if the container is either the direct or indirect parent of this component, otherwise {@code false}
104 boolean hasParent(Container parent
);
107 * Returns the TextGUI that this component is currently part of. If the component hasn't been added to any container
108 * or in any other way placed into a GUI system, this method will return null.
109 * @return The TextGUI that this component belongs to, or null if none
111 TextGUI
getTextGUI();
114 * Returns true if this component is inside of the specified Container. It might be a direct child or not, this
115 * method makes no difference. If {@code getParent()} is not the same instance as {@code container}, but if this
116 * method returns true, you can be sure that this component is not a direct child.
117 * @param container Container to test if this component is inside
118 * @return True if this component is contained in some way within the {@code container}
120 boolean isInside(Container container
);
123 * Returns the renderer used to draw this component and measure its preferred size. You probably won't need to call
124 * this method unless you know exactly which ComponentRenderer implementation is used and you need to customize it.
125 * @return Renderer this component is using
127 ComponentRenderer
<?
extends Component
> getRenderer();
130 * Marks the component as invalid and requiring to be re-drawn at next opportunity. Container components should take
131 * this as a hint to layout the child components again.
136 * Takes a border object and moves this component inside it and then returns it again. This makes it easy to quickly
137 * wrap a component on creation, like this:
139 * container.addComponent(new Button("Test").withBorder(Borders.singleLine()));
144 Border
withBorder(Border border
);
147 * Translates a position local to the container to the base pane's coordinate space. For a window-based GUI, this
148 * be a coordinate in the window's coordinate space. If the component belongs to no base pane, it will return
150 * @param position Position to translate (relative to the container's top-left corner)
151 * @return Position in base pane space, or {@code null} if the component is an orphan
153 TerminalPosition
toBasePane(TerminalPosition position
);
156 * Translates a position local to the container to global coordinate space. This should be the absolute coordinate
157 * in the terminal screen, taking no windows or containers into account. If the component belongs to no base pane,
158 * it will return {@code null}.
159 * @param position Position to translate (relative to the container's top-left corner)
160 * @return Position in global (or absolute) coordinates, or {@code null} if the component is an orphan
162 TerminalPosition
toGlobal(TerminalPosition position
);
165 * Returns the BasePane that this container belongs to. In a window-based GUI system, this will be a Window.
166 * @return The base pane this component is placed on, or {@code null} if none
168 BasePane
getBasePane();
171 * Same as calling {@code panel.addComponent(thisComponent)}
172 * @param panel Panel to add this component to
175 Component
addTo(Panel panel
);
178 * Called by the GUI system when you add a component to a container; DO NOT CALL THIS YOURSELF!
179 * @param container Container that this component was just added to
181 void onAdded(Container container
);
184 * Called by the GUI system when you remove a component from a container; DO NOT CALL THIS YOURSELF!
185 * @param container Container that this component was just removed from
187 void onRemoved(Container container
);