com.sun.lwuit
Class Container

java.lang.Object
  extended by com.sun.lwuit.Component
      extended by com.sun.lwuit.Container
Direct Known Subclasses:
Calendar, ErrorContentTextField, Form, FormItem, GroupHeader, HeaderBar, HTMLComponent, HyperLink, MenuBar, NotificationBar, PickerContainer, PickerItemContainer, PopupChoiceGroup, ProgressBar, RefreshLoadBar, SearchBar, SwitchComponent, Table, Tabs, Tree

public class Container
extends Component

A composite pattern with Component, allows nesting and arranging multiple components using a pluggable layout manager architecture. Containers can be nested one within the other to form elaborate UI's.

Author:
Chen Fishbein
See Also:
com.sun.lwuit.layouts, Component

Field Summary
 
Fields inherited from class com.sun.lwuit.Component
BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, LEFT, RIGHT, TOP
 
Constructor Summary
Container()
          Constructs a new Container, with a FlowLayout.
Container(Layout layout)
          Constructs a new Container with a new layout manager.
 
Method Summary
 void addComponent(Component cmp)
          Adds a Component to the Container
 void addComponent(int index, Component cmp)
          This method adds the Component at a specific index location in the Container Components array.
 void addComponent(int index, java.lang.Object constraints, Component cmp)
          Adds a Component to the Container
 void addComponent(java.lang.Object constraints, Component cmp)
          Adds a Component to the Container
 void animateLayout(int duration)
          Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
 void animateLayoutAndWait(int duration)
          Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation.
 void applyRTL(boolean rtl)
          Invokes apply/setRTL recursively on all the children components of this container
 boolean contains(Component cmp)
          Returns true if the given component is within the hierarchy of this container
 void drop(Component dragged, int x, int y)
          Performs a drop operation of the component at the given X/Y location in coordinate space, this method should be overriden by subclasses to perform all of the logic related to moving a component, by default this method does nothing and so dragging a component and dropping it has no effect
 Component findFirstFocusable()
          Finds the first focusable Component on this Container
 void flushReplace()
          Flushes ongoing replace operations to prevent two concurrent replace operations from colliding.
 int getBottomGap()
          Returns the gap to be left for the bottom scrollbar on the X axis.
 Component getComponentAt(int index)
          Returns the Component at a given index
 Component getComponentAt(int x, int y)
          Returns a Component that exists in the given x, y coordinates by traversing component objects and invoking contains
 int getComponentCount()
          Returns the number of components
 int getComponentIndex(Component cmp)
          Returns the Component index in the Container
 Layout getLayout()
          Returns the layout manager responsible for arranging this container
 int getLayoutHeight()
          Returns the height for layout manager purposes, this takes scrolling into consideration unlike the getWidth method.
 int getLayoutWidth()
          Returns the width for layout manager purposes, this takes scrolling into consideration unlike the getWidth method.
 Component getLeadComponent()
          Returns the lead component for this hierarchy if such a component is defined
 Container getLeadParent()
          Returns the lead container thats handling the leading, this is useful for a container hierachy where the parent container might not be the leader
 int getScrollIncrement()
          Gets the Container scroll increment
 int getSideGap()
          Returns the gap to be left for the side scrollbar on the Y axis.
 void invalidate()
          Same as setShouldCalcPreferredSize(true) but made accessible for layout managers
 boolean isEnabled()
          Indicates whether component is enabled or disabled thus allowing us to prevent a component from receiving input events and indicate so visually
 boolean isScrollableX()
          Indicates whether the component should/could scroll on the X axis
 boolean isScrollableY()
          Indicates whether the component should/could scroll on the Y axis
 void keyPressed(int k)
          If this Component is focused, the key pressed event will call this method
 void keyReleased(int k)
          If this Component is focused, the key released event will call this method
 void layoutContainer()
          Performs the layout of the container if a layout is necessary
 void paint(Graphics g)
          This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.
 void paintBackground(Graphics g)
          Paints the background of the component, invoked with the clipping region and appropriate scroll translation.
 void pointerHover(int[] x, int[] y)
          Invoked for devices where the pointer can hover without actually clicking the display.
 void pointerPressed(int x, int y)
          If this Component is focused, the pointer pressed event will call this method
 void refreshTheme()
          Makes sure the component is up to date with the current style object
 void removeAll()
          remove all Components from container, notice that removed component might still have a pending repaint in the queue that won't be removed.
 void removeComponent(Component cmp)
          removes a Component from the Container, notice that removed component might still have a pending repaint in the queue that won't be removed.
 void replace(Component current, Component next, Transition t)
          This method replaces the current Component with the next Component.
 void replace(Component current, Component next, Transition t, java.lang.Runnable onFinish, int growSpeed)
          This method replaces the current Component with the next Component
 void replaceAndWait(Component current, Component next, Transition t)
          This method replaces the current Component with the next Component.
 void replaceAndWait(Component current, Component next, Transition t, boolean dropEvents)
          This method replaces the current Component with the next Component.
 void replaceAndWait(Component current, Component next, Transition t, int layoutAnimationSpeed)
          This method replaces the current Component with the next Component.
 void revalidate()
          Re-layout the container, this is useful when we modify the container hierarchy and need to redo the layout
 void setCellRenderer(boolean cellRenderer)
          Used as an optimization to mark that this component is currently being used as a cell renderer
 void setEnabled(boolean enabled)
          This method will recursively set all the Container chidrens to be enabled/disabled.
 void setLayout(Layout layout)
          Sets the layout manager responsible for arranging this container
 void setLeadComponent(Component lead)
          Sets the lead component for this container, a lead component takes over the entire component hierarchy and receives all the events for the container hierarchy.
 void setScrollable(boolean scrollable)
          The equivalent of calling both setScrollableY and setScrollableX
 void setScrollableX(boolean scrollableX)
          Sets whether the component should/could scroll on the X axis
 void setScrollableY(boolean scrollableY)
          Sets whether the component should/could scroll on the Y axis
 void setScrollIncrement(int scrollIncrement)
          Determines the scroll increment size of this Container.
 void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)
          Indicates the values within the component have changed and preferred size should be recalculated
 
Methods inherited from class com.sun.lwuit.Component
addFocusListener, animate, contains, getAbsoluteX, getAbsoluteY, getBaseline, getBaselineResizeBehavior, getClientProperty, getComponentForm, getDirtyRegion, getDisabledStyle, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypes, getPropertyValue, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTensileLength, getUIID, getUnselectedStyle, getWidth, getX, getY, growShrink, handlesInput, hasFocus, isAlwaysTensile, isDraggable, isDropTarget, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isRTL, isScrollVisible, isSmoothScrolling, isSnapToGrid, isTactileTouch, isTensileDragEnabled, isVisible, keyRepeated, paintBackgrounds, paintComponent, paintComponent, paintLock, paintLockRelease, pointerDragged, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, removeFocusListener, repaint, repaint, requestFocus, scrollRectToVisible, setAlwaysTensile, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setPropertyValue, setRTL, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, styleChanged, toString
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait
 

Constructor Detail

Container

public Container(Layout layout)
Constructs a new Container with a new layout manager.

Parameters:
layout - the specified layout manager

Container

public Container()
Constructs a new Container, with a FlowLayout.

Method Detail

setLeadComponent

public void setLeadComponent(Component lead)
Sets the lead component for this container, a lead component takes over the entire component hierarchy and receives all the events for the container hierarchy.

Parameters:
lead - component that takes over the hierarchy

getLeadComponent

public Component getLeadComponent()
Returns the lead component for this hierarchy if such a component is defined

Returns:
the lead component

getLeadParent

public Container getLeadParent()
Returns the lead container thats handling the leading, this is useful for a container hierachy where the parent container might not be the leader

Returns:
the lead component

keyPressed

public void keyPressed(int k)
Description copied from class: Component
If this Component is focused, the key pressed event will call this method

Overrides:
keyPressed in class Component
Parameters:
k - the key code value to indicate a physical key.

keyReleased

public void keyReleased(int k)
Description copied from class: Component
If this Component is focused, the key released event will call this method

Overrides:
keyReleased in class Component
Parameters:
k - the key code value to indicate a physical key.

getLayout

public Layout getLayout()
Returns the layout manager responsible for arranging this container

Returns:
the container layout manager

setLayout

public void setLayout(Layout layout)
Sets the layout manager responsible for arranging this container

Parameters:
layout - the specified layout manager

invalidate

public void invalidate()
Same as setShouldCalcPreferredSize(true) but made accessible for layout managers


setShouldCalcPreferredSize

public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)
Description copied from class: Component
Indicates the values within the component have changed and preferred size should be recalculated

Overrides:
setShouldCalcPreferredSize in class Component
Parameters:
shouldCalcPreferredSize - indicate whether this component need to recalculate his preferred size

getLayoutWidth

public int getLayoutWidth()
Returns the width for layout manager purposes, this takes scrolling into consideration unlike the getWidth method.

Returns:
the layout width

getLayoutHeight

public int getLayoutHeight()
Returns the height for layout manager purposes, this takes scrolling into consideration unlike the getWidth method.

Returns:
the layout height

applyRTL

public void applyRTL(boolean rtl)
Invokes apply/setRTL recursively on all the children components of this container

Parameters:
rtl - right to left bidi indication
See Also:
Component.setRTL(boolean)

addComponent

public void addComponent(Component cmp)
Adds a Component to the Container

Parameters:
cmp - the component to be added

addComponent

public void addComponent(java.lang.Object constraints,
                         Component cmp)
Adds a Component to the Container

Parameters:
constraints - this method is useful when the Layout requires a constraint such as the BorderLayout. In this case you need to specify an additional data when you add a Component, such as "CENTER", "NORTH"...
cmp - component to add

addComponent

public void addComponent(int index,
                         java.lang.Object constraints,
                         Component cmp)
Adds a Component to the Container

Parameters:
index - location to insert the Component
constraints - this method is useful when the Layout requires a constraint such as the BorderLayout. In this case you need to specify an additional data when you add a Component, such as "CENTER", "NORTH"...
cmp - component to add

addComponent

public void addComponent(int index,
                         Component cmp)
This method adds the Component at a specific index location in the Container Components array.

Parameters:
index - location to insert the Component
cmp - the Component to add
Throws:
java.lang.ArrayIndexOutOfBoundsException - if index is out of bounds
java.lang.IllegalArgumentException - if Component is already contained or the cmp is a Form Component

replaceAndWait

public void replaceAndWait(Component current,
                           Component next,
                           Transition t)
This method replaces the current Component with the next Component. Current Component must be contained in this Container. This method returns when transition has finished.

Parameters:
current - a Component to remove from the Container
next - a Component that replaces the current Component
t - a Transition between the add and removal of the Components a Transition can be null

replaceAndWait

public void replaceAndWait(Component current,
                           Component next,
                           Transition t,
                           int layoutAnimationSpeed)
This method replaces the current Component with the next Component. Current Component must be contained in this Container. This method returns when transition has finished.

Parameters:
current - a Component to remove from the Container
next - a Component that replaces the current Component
t - a Transition between the add and removal of the Components a Transition can be null
layoutAnimationSpeed - the speed of the layout animation after replace is completed

replace

public void replace(Component current,
                    Component next,
                    Transition t,
                    java.lang.Runnable onFinish,
                    int growSpeed)
This method replaces the current Component with the next Component

Parameters:
current - a Component to remove from the Container
next - a Component that replaces the current Component
t - a Transition between the add and removal of the Components a Transition can be null
onFinish - invoked when the replace operation is completed, may be null
growSpeed - after replace is completed the component can gradually grow/shrink to fill up available room, set this to 0 for immediate growth or any larger number for gradual animation. -1 indicates a special case where no validation occurs

replaceAndWait

public void replaceAndWait(Component current,
                           Component next,
                           Transition t,
                           boolean dropEvents)
This method replaces the current Component with the next Component. Current Component must be contained in this Container. This method returns when transition has finished.

Parameters:
current - a Component to remove from the Container
next - a Component that replaces the current Component
t - a Transition between the add and removal of the Components a Transition can be null
dropEvents - indicates if the display should drop all events while this Component replacing is happening

replace

public void replace(Component current,
                    Component next,
                    Transition t)
This method replaces the current Component with the next Component. Current Component must be contained in this Container. This method return immediately.

Parameters:
current - a Component to remove from the Container
next - a Component that replaces the current Component
t - a Transition between the add and removal of the Components a Transition can be null

isEnabled

public boolean isEnabled()
Description copied from class: Component
Indicates whether component is enabled or disabled thus allowing us to prevent a component from receiving input events and indicate so visually

Overrides:
isEnabled in class Component
Returns:
true if enabled

removeComponent

public void removeComponent(Component cmp)
removes a Component from the Container, notice that removed component might still have a pending repaint in the queue that won't be removed. Calling form.repaint() will workaround such an issue.

Parameters:
cmp - the removed component

flushReplace

public void flushReplace()
Flushes ongoing replace operations to prevent two concurrent replace operations from colliding. If there is no ongoing replace nothing will occur


removeAll

public void removeAll()
remove all Components from container, notice that removed component might still have a pending repaint in the queue that won't be removed. Calling form.repaint() will workaround such an issue.


revalidate

public void revalidate()
Re-layout the container, this is useful when we modify the container hierarchy and need to redo the layout


paint

public void paint(Graphics g)
Description copied from class: Component
This method paints the Component on the screen, it should be overriden by subclasses to perform custom drawing or invoke the UI API's to let the PLAF perform the rendering.

Overrides:
paint in class Component
Parameters:
g - the component graphics

layoutContainer

public void layoutContainer()
Performs the layout of the container if a layout is necessary


getComponentCount

public int getComponentCount()
Returns the number of components

Returns:
the Component count

getComponentAt

public Component getComponentAt(int index)
Returns the Component at a given index

Parameters:
index - of the Component you wish to get
Returns:
a Component
Throws:
java.lang.ArrayIndexOutOfBoundsException - if an invalid index was given.

getComponentIndex

public int getComponentIndex(Component cmp)
Returns the Component index in the Container

Parameters:
cmp - the component to search for
Returns:
the Component index in the Container or -1 if not found

contains

public boolean contains(Component cmp)
Returns true if the given component is within the hierarchy of this container

Parameters:
cmp - a Component to check
Returns:
true if this Component contains in this Container

getComponentAt

public Component getComponentAt(int x,
                                int y)
Returns a Component that exists in the given x, y coordinates by traversing component objects and invoking contains

Parameters:
x - absolute screen location
y - absolute screen location
Returns:
a Component if found, null otherwise
See Also:
Component.contains(int, int)

pointerHover

public void pointerHover(int[] x,
                         int[] y)
Description copied from class: Component
Invoked for devices where the pointer can hover without actually clicking the display. This is true for PC mouse pointer as well as some devices such as the BB storm.

Overrides:
pointerHover in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

pointerPressed

public void pointerPressed(int x,
                           int y)
Description copied from class: Component
If this Component is focused, the pointer pressed event will call this method

Overrides:
pointerPressed in class Component
Parameters:
x - the pointer x coordinate
y - the pointer y coordinate

refreshTheme

public void refreshTheme()
Description copied from class: Component
Makes sure the component is up to date with the current style object

Overrides:
refreshTheme in class Component

isScrollableX

public boolean isScrollableX()
Description copied from class: Component
Indicates whether the component should/could scroll on the X axis

Overrides:
isScrollableX in class Component
Returns:
whether the component is scrollable on the X axis

isScrollableY

public boolean isScrollableY()
Description copied from class: Component
Indicates whether the component should/could scroll on the Y axis

Overrides:
isScrollableY in class Component
Returns:
whether the component is scrollable on the X axis

getSideGap

public int getSideGap()
Description copied from class: Component
Returns the gap to be left for the side scrollbar on the Y axis. This method is used by layout managers to determine the room they should leave for the scrollbar. (note: side scrollbar rather than left scrollbar is used for a future version that would support bidi).

Overrides:
getSideGap in class Component
Returns:
the gap to be left for the side scrollbar on the Y axis

getBottomGap

public int getBottomGap()
Description copied from class: Component
Returns the gap to be left for the bottom scrollbar on the X axis. This method is used by layout managers to determine the room they should leave for the scrollbar

Overrides:
getBottomGap in class Component
Returns:
the gap to be left for the bottom scrollbar on the X axis

setScrollableX

public void setScrollableX(boolean scrollableX)
Sets whether the component should/could scroll on the X axis

Parameters:
scrollableX - whether the component should/could scroll on the X axis

setScrollableY

public void setScrollableY(boolean scrollableY)
Sets whether the component should/could scroll on the Y axis

Parameters:
scrollableY - whether the component should/could scroll on the Y axis

setScrollable

public void setScrollable(boolean scrollable)
The equivalent of calling both setScrollableY and setScrollableX

Parameters:
scrollable - whether the component should/could scroll on the X and Y axis

setCellRenderer

public void setCellRenderer(boolean cellRenderer)
Description copied from class: Component
Used as an optimization to mark that this component is currently being used as a cell renderer

Overrides:
setCellRenderer in class Component
Parameters:
cellRenderer - indicate whether this component is currently being used as a cell renderer

setScrollIncrement

public void setScrollIncrement(int scrollIncrement)
Determines the scroll increment size of this Container. This value is in use when the current foucs element within this Container is larger than this Container size.

Parameters:
scrollIncrement - the size in pixels.

getScrollIncrement

public int getScrollIncrement()
Gets the Container scroll increment

Returns:
the scroll increment in pixels.

findFirstFocusable

public Component findFirstFocusable()
Finds the first focusable Component on this Container

Returns:
a focusable Component or null if not exists;

setEnabled

public void setEnabled(boolean enabled)
This method will recursively set all the Container chidrens to be enabled/disabled. If the Container is disabled and a child Component changed it's state to be enabled, the child Component will be treated as an enabled Component.

Overrides:
setEnabled in class Component
Parameters:
enabled -

paintBackground

public void paintBackground(Graphics g)
Description copied from class: Component
Paints the background of the component, invoked with the clipping region and appropriate scroll translation.

Parameters:
g - the component graphics

animateLayoutAndWait

public void animateLayoutAndWait(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation. This method waits until the operation is completed before returning

Parameters:
duration - the duration in milliseconds for the animation

animateLayout

public void animateLayout(int duration)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation

Parameters:
duration - the duration in milliseconds for the animation

drop

public void drop(Component dragged,
                 int x,
                 int y)
Description copied from class: Component
Performs a drop operation of the component at the given X/Y location in coordinate space, this method should be overriden by subclasses to perform all of the logic related to moving a component, by default this method does nothing and so dragging a component and dropping it has no effect

Overrides:
drop in class Component
Parameters:
dragged - the component being dropped
x - the x coordinate of the drop
y - the y coordinate of the drop