portal.core.api
Class Container

java.lang.Object
  extended byportal.core.api.Component
      extended byportal.core.api.Container
All Implemented Interfaces:
Renderable, java.io.Serializable
Direct Known Subclasses:
Panel

public class Container
extends Component

This is the base class for all components that can contain a list of children. This class manages the link between these child components and their parent (this Container instance).

The rendering of this container is delegated to layout managers. Setting a layout manager for a container is done by calling the method Component.setLayout(LayoutManager).

Some layout managers require more information to render the children of the container. For these specific layout managers you can pass a value to the constraint paramater of the add(...) methods. The actual value is only interpreted by the layout manager. See the documentation of the layout manager used for possible values and their meaning.

Since:
0.9
Author:
bavodr
See Also:
Serialized Form

Constructor Summary
Container()
          Create a new Container instance.
Container(LayoutManager layout)
          Create a new Container instance with an initial layout manager.
Container(java.lang.String name, LayoutManager layout)
          Create a new Container instance with the give name and layout manager.
 
Method Summary
 void add(Component component)
          Add a new child component to this container with no constraint.
 void add(Component component, java.lang.Object constraint)
          Add a new child component to this container with the given constraint.
 void add(int index, Component component, java.lang.Object constraint)
          Add a new child component to this container with the given constraint and at the given index.
 Component getComponent(int index)
          Return the child component at the given index.
 Component getComponent(java.lang.Object constraint)
          Search for the first component in this container that uses the given constraint.
 java.util.Collection getComponents()
          Creates a copy of the current list of child components in this container.
 java.lang.Object getConstraint(int index)
          Return the constraint used by the child component at the given index.
 void remove(Component component)
          Remove the given child component from this container if present.
 void remove(int index)
          Removes the child at the given index.
 void remove(java.lang.Object constraint)
          Find the first child component that has a constraint equal to the given constraint and remove the child component.
 void removeAll()
          Remove all children with their constraints from this container instance.
 int size()
          Returns the size of this container.
 
Methods inherited from class portal.core.api.Component
afterRender, beforeRender, createDefaultModel, draw, getLayout, getModel, getParent, isEnabled, isVisible, render, setEnabled, setLayout, setModel, setParent, setVisible, toString
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Container

public Container()

Create a new Container instance.

Calling this constructor is is identical to calling Container(String,LayoutManager) with a name equal to null and a layout equal to null.

For this container to be rendered, you have to call the method Component.setLayout(LayoutManager) and set a layout manager.


Container

public Container(LayoutManager layout)

Create a new Container instance with an initial layout manager.

Calling this constructor is is identical to calling Container(String,LayoutManager) with a name equal to null.

Parameters:
layout - the initial layout manager for this container

Container

public Container(java.lang.String name,
                 LayoutManager layout)

Create a new Container instance with the give name and layout manager. The layout manager can be replaced by a later call to Component.setLayout(LayoutManager)

See also Component.Component(String).

Parameters:
name - the name of this container
layout - the initial layout manager for this container
Method Detail

add

public final void add(Component component)

Add a new child component to this container with no constraint. Calling this method is identical to calling add(Component,Object) with a constraint value of null.

Parameters:
component - The child component to add to this container.

add

public final void add(Component component,
                      java.lang.Object constraint)

Add a new child component to this container with the given constraint. The possible values of the constraint paramater depend on the layout manager used to render this container. Some layout managers even ignore this value.

The parent of the child component is updated to be this container. If the child belonged to another container, it will be removed from that container first.

Parameters:
component - The child component to add to this container.
constraint - The constraint used to add this child component to this container.

add

public final void add(int index,
                      Component component,
                      java.lang.Object constraint)

Add a new child component to this container with the given constraint and at the given index.

The actual orderering of the items within the container is only used by the layout manager and may be ignored.

See also add(Component,Object) for more information.

Parameters:
index - The index at which to add this child component.
component - The child component to add to this container.
constraint - The constraint used to add this child component to this container.

remove

public final void remove(Component component)

Remove the given child component from this container if present. If the child component is not present in this container, nothing will happen.

The parent of the child component will be set to null before the child is removed.

Parameters:
component - the child component that has to be removed.

remove

public final void remove(java.lang.Object constraint)

Find the first child component that has a constraint equal to the given constraint and remove the child component. If there is no such constraint used in this container, nothing happens.

The parent of the child component will be set to null before the child is removed.

Parameters:
constraint - the constraint for which the child has to be removed.

remove

public final void remove(int index)

Removes the child at the given index. The index has to be within the bounds set by the container (< size() and >= 0).

The parent of the child component will be set to null before the child is removed.

Parameters:
index - the index of the child componet that has to be removed.

removeAll

public final void removeAll()

Remove all children with their constraints from this container instance. The result is an empty container.

The parent of all child components will be set to null before the child is removed.


size

public final int size()

Returns the size of this container. The size is set to be equal to the number of components in this container.

Returns:
The number of components held within this container.

getConstraint

public final java.lang.Object getConstraint(int index)

Return the constraint used by the child component at the given index. The index has to be within the bounds set by the container (< size() and >= 0).

It is possible that the child component at the given index does not use a constraint. In that case null will be returned.

Parameters:
index - the index within the container to search at.
Returns:
the constrained used by the child component at the given index or null if no constraint was given.

getComponent

public final Component getComponent(int index)

Return the child component at the given index. The index has to be within the bounds set by the container (< size() and >= 0).

Parameters:
index - the index within the container to search at.
Returns:
the child component at the given index.

getComponents

public final java.util.Collection getComponents()

Creates a copy of the current list of child components in this container. The resulting collection can be manipulated without affecting the container.

Returns:
a copy of the list of child components in this container.

getComponent

public final Component getComponent(java.lang.Object constraint)

Search for the first component in this container that uses the given constraint. If no such component is found, null is returned.

Parameters:
constraint - the constraint to search for. Cannot be null.
Returns:
the first component found that uses this constraint.