charva.awt

Class Container

Known Direct Subclasses:
Box, JMenuBar, JPanel, JScrollPane, JTabbedPane, JViewport, Window

public abstract class Container
extends Component

Container is the abstract superclass of Window and Panel.

Field Summary

protected Vector
_components
The list of components contained within this Container.
protected Component
_currentFocus
The component (which may itself be a Container) inside this Container that currently has the input focus (or, if the input focus is currently outside this Container, the component to which focus will return if and when this Container regains focus).
protected Insets
_insets
The insets define how much padding to insert inside the Container, to take into account the border frame (if any).
protected boolean
_isValid
A flag that is set to true when the container is laid out, and set to false when a component is added or removed from the container (indicating that it needs to be laid out again).
protected LayoutManager
_layoutMgr
The layout manager that will be used to lay out the components.
protected Dimension
_minimumSize
Used for caching the minimum size of this container, so that we don't have to keep recalculating it.
protected Dimension
_size
The container's size

Fields inherited from class charva.awt.Component

BOTTOM_ALIGNMENT, CENTER_ALIGNMENT, LEFT_ALIGNMENT, RIGHT_ALIGNMENT, TOP_ALIGNMENT, _alignmentX, _alignmentY, _background, _cursesColor, _enabled, _focusListeners, _foreground, _keyListeners, _origin, _parent, _visible

Constructor Summary

Container()

Method Summary

Component
add(Component component_)
The contained component will inherit the foreground and background colors of the container if they have not been set yet.
void
add(Component component_, Object constraint_)
Adds the specified component to the end of this container.
void
debug(int level_)
void
doLayout()
doLayout is intended to be used by subclasses of Container, such as Window, JPanel and JScrollPane.
void
draw()
Draw all the components in this container.
Component
getComponent(int n)
Returns the component at the specified index.
Component
getComponentAt(Point p)
Returns the component that contains the specified point, or null if no component contains the point.
Component
getComponentAt(int x, int y)
Returns the component that contains the specified point, or null if no component contains the point.
int
getComponentCount()
Returns the number of components in this Container.
Component[]
getComponents()
Returns an array of all the components in this container.
Component
getCurrentFocus()
Return a reference to the (non-container) component inside this Container that has the keyboard input focus (or would have it, if the focus was inside this container).
int
getHeight()
Insets
getInsets()
Dimension
getSize()
int
getWidth()
void
invalidate()
Marks the container and all parents above it as needing to be laid out again.
boolean
isFocusTraversable()
Return true if any of the components within this Container are focus-traversable (i.e. will accept keyboard input focus when TAB or SHIFT-TAB is pressed).
boolean
isValid()
Determines whether this component is valid.
Dimension
minimumSize()
void
nextFocus()
Set the _currentFocus to refer to the next focus-traversable component in the list of contained components, and put FocusEvents on the queue, one for the component that is losing the focus and one for the component gaining the focus.
void
previousFocus()
Set the _currentFocus to refer to the previous focus-traversable component in the list of contained components, and put FocusEvents on the queue, one for the component that is losing the focus and one for the component gaining the focus.
void
processKeyEvent(KeyEvent ke_)
void
remove(Component component_)
Removes the specified component from this container.
void
requestFocus()
void
setBackground(Color color_)
Sets the background color of this container and all its contained components that do not yet have their background color set.
void
setFocus(Component focus_)
Set this container's current keyboard focus.
void
setForeground(Color color_)
Sets the foreground color of this container and all its contained components that do not yet have their foreground color set.
void
setHeight(int height_)
void
setLayout(LayoutManager mgr_)
void
setSize(Dimension size_)
void
setSize(int width_, int height_)
void
setWidth(int width_)
void
validate()
Validates this container and all of its contained components.

Methods inherited from class charva.awt.Component

addFocusListener, addKeyListener, contains, contains, debug, draw, getAlignmentX, getAlignmentY, getAncestorWindow, getBackground, getBounds, getCursesColor, getForeground, getHeight, getLocation, getLocationOnScreen, getName, getParent, getSize, getWidth, hasFocus, hide, invalidate, isDisplayed, isEnabled, isFocusTraversable, isTotallyObscured, isValid, isVisible, minimumSize, processEvent, processFocusEvent, processKeyEvent, processMouseEvent, repaint, requestFocus, requestSync, setBackground, setBounds, setBounds, setBounds, setEnabled, setForeground, setLocation, setLocation, setName, setParent, setVisible, show, validate, validateCursesColor

Field Details

_components

protected Vector _components
The list of components contained within this Container.

_currentFocus

protected Component _currentFocus
The component (which may itself be a Container) inside this Container that currently has the input focus (or, if the input focus is currently outside this Container, the component to which focus will return if and when this Container regains focus).

_insets

protected Insets _insets
The insets define how much padding to insert inside the Container, to take into account the border frame (if any). For a Window they will be (1,1); for a Panel, they will be (0,0).

_isValid

protected boolean _isValid
A flag that is set to true when the container is laid out, and set to false when a component is added or removed from the container (indicating that it needs to be laid out again).

_layoutMgr

protected LayoutManager _layoutMgr
The layout manager that will be used to lay out the components.

_minimumSize

protected Dimension _minimumSize
Used for caching the minimum size of this container, so that we don't have to keep recalculating it. This dimension is valid only if _isValid is true.

_size

protected Dimension _size
The container's size

Constructor Details

Container

public Container()

Method Details

add

public Component add(Component component_)
The contained component will inherit the foreground and background colors of the container if they have not been set yet.

add

public void add(Component component_,
                Object constraint_)
Adds the specified component to the end of this container. Also notifies the layout manager to add this component to the layout using the specified constraint. If the layout manager does not implement the LayoutManager2 interface, i.e. does not know about layout constraints, we silently ignore the constraint (maybe fix this to throw an exception?).

debug

public void debug(int level_)
Overrides:
debug in interface Component

doLayout

public void doLayout()
doLayout is intended to be used by subclasses of Container, such as Window, JPanel and JScrollPane.

draw

public void draw()
Draw all the components in this container.
Overrides:
draw in interface Component

getComponent

public Component getComponent(int n)
Returns the component at the specified index.

getComponentAt

public Component getComponentAt(Point p)
Returns the component that contains the specified point, or null if no component contains the point. The x and y coordinates of the point are relative to the origin of this container.

getComponentAt

public Component getComponentAt(int x,
                                int y)
Returns the component that contains the specified point, or null if no component contains the point. The x and y coordinates of the point are relative to the origin of this container.

getComponentCount

public int getComponentCount()
Returns the number of components in this Container.

getComponents

public Component[] getComponents()
Returns an array of all the components in this container.

getCurrentFocus

public Component getCurrentFocus()
Return a reference to the (non-container) component inside this Container that has the keyboard input focus (or would have it, if the focus was inside this container). If no component inside the container has the focus, choose the first FocusTraversable component.
Returns:
the Component in this container that would have the focus; never null.

getHeight

public int getHeight()
Overrides:
getHeight in interface Component

getInsets

public Insets getInsets()

getSize

public Dimension getSize()
Overrides:
getSize in interface Component

getWidth

public int getWidth()
Overrides:
getWidth in interface Component

invalidate

public void invalidate()
Marks the container and all parents above it as needing to be laid out again.
Overrides:
invalidate in interface Component

isFocusTraversable

public boolean isFocusTraversable()
Return true if any of the components within this Container are focus-traversable (i.e. will accept keyboard input focus when TAB or SHIFT-TAB is pressed).
Overrides:
isFocusTraversable in interface Component

isValid

public boolean isValid()
Determines whether this component is valid. A container is valid when it is correctly sized and positioned within its parent container and all its children are also valid.
Overrides:
isValid in interface Component

minimumSize

public Dimension minimumSize()
Overrides:
minimumSize in interface Component

nextFocus

public void nextFocus()
Set the _currentFocus to refer to the next focus-traversable component in the list of contained components, and put FocusEvents on the queue, one for the component that is losing the focus and one for the component gaining the focus.

previousFocus

public void previousFocus()
Set the _currentFocus to refer to the previous focus-traversable component in the list of contained components, and put FocusEvents on the queue, one for the component that is losing the focus and one for the component gaining the focus.

processKeyEvent

public void processKeyEvent(KeyEvent ke_)
Overrides:
processKeyEvent in interface Component

remove

public void remove(Component component_)
Removes the specified component from this container.

requestFocus

public void requestFocus()
Overrides:
requestFocus in interface Component

setBackground

public void setBackground(Color color_)
Sets the background color of this container and all its contained components that do not yet have their background color set. Overrides the same method in the Component class.
Overrides:
setBackground in interface Component

setFocus

public void setFocus(Component focus_)
Set this container's current keyboard focus. Called by the requestFocus() method of the contained component.

setForeground

public void setForeground(Color color_)
Sets the foreground color of this container and all its contained components that do not yet have their foreground color set. Overrides the same method in the Component class.
Overrides:
setForeground in interface Component

setHeight

public void setHeight(int height_)

setLayout

public void setLayout(LayoutManager mgr_)

setSize

public void setSize(Dimension size_)

setSize

public void setSize(int width_,
                    int height_)

setWidth

public void setWidth(int width_)

validate

public void validate()
Validates this container and all of its contained components. The programmer must call validate() on a container to cause it to re-layout its contained components after components have been added, removed or resized.
Overrides:
validate in interface Component