public class Container extends Component
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.com.codename1.ui.layouts
,
Component
BASELINE, BOTTOM, BRB_CENTER_OFFSET, BRB_CONSTANT_ASCENT, BRB_CONSTANT_DESCENT, BRB_OTHER, CENTER, DRAG_REGION_LIKELY_DRAG_X, DRAG_REGION_LIKELY_DRAG_XY, DRAG_REGION_LIKELY_DRAG_Y, DRAG_REGION_NOT_DRAGGABLE, DRAG_REGION_POSSIBLE_DRAG_X, DRAG_REGION_POSSIBLE_DRAG_XY, DRAG_REGION_POSSIBLE_DRAG_Y, LEFT, RIGHT, TOP
Constructor and Description |
---|
Container()
Constructs a new Container, with a
FlowLayout . |
Container(Layout layout)
Constructs a new Container with a new layout manager.
|
Modifier and Type | Method and Description |
---|---|
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,
Object constraints,
Component cmp)
Adds a Component to the Container
|
void |
addComponent(Object constraints,
Component cmp)
Adds a Component to the Container
|
void |
animateHierarchy(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation
|
void |
animateHierarchyAndWait(int duration)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation.
|
void |
animateHierarchyFade(int duration,
int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation
|
void |
animateHierarchyFadeAndWait(int duration,
int startingOpacity)
Animates a pending hierarchy of components into place, this effectively replaces revalidate with
a more visual form of animation.
|
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 |
animateLayoutFade(int duration,
int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation
|
void |
animateLayoutFadeAndWait(int duration,
int startingOpacity)
Animates a pending layout into place, this effectively replaces revalidate with a more visual form of animation.
|
void |
animateUnlayout(int duration,
int opacity,
Runnable callback)
This method is the exact reverse of animateLayout, when completed it leaves the container in
an invalid state.
|
void |
animateUnlayoutAndWait(int duration,
int opacity)
This method is the exact reverse of animateLayoutAndWait, when completed it leaves the container in
an invalid state.
|
void |
applyRTL(boolean rtl)
Invokes apply/setRTL recursively on all the children components of this container
|
protected Dimension |
calcPreferredSize()
Calculates the preferred size based on component content.
|
protected void |
cancelRepaints()
remove this component and it's children from the painting queue
|
void |
clearClientProperties()
Clears all client properties from this Component
|
boolean |
contains(Component cmp)
Returns true if the given component is within the hierarchy of this container
|
protected Motion |
createAnimateMotion(int start,
int destination,
int duration)
Creates a motion object for animation, allows subclasses to replace the motion type
used in animations (currently defaults to ease-in).
|
protected void |
dragInitiated()
Invoked on the focus component to let it know that drag has started on the parent container
for the case of a component that doesn't support scrolling
|
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
|
protected void |
fireClicked()
When working in 3 softbutton mode "fire" key (center softbutton) is sent to this method
in order to allow 3 button devices to work properly.
|
void |
flushReplace()
Flushes ongoing replace operations to prevent two concurrent replace operations from colliding.
|
void |
forceRevalidate()
A more powerful form of revalidate that recursively lays out the full hierarchy
|
int |
getBottomGap()
Returns the gap to be left for the bottom scrollbar on the X axis.
|
Component |
getClosestComponentTo(int x,
int y)
Very useful for touch events or drop events that need approximation more than accuracy
|
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
|
protected int |
getGridPosX()
This method should be implemented correctly by subclasses to make snap to grid functionality work
as expected.
|
protected int |
getGridPosY()
This method should be implemented correctly by subclasses to make snap to grid functionality work
as expected.
|
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 hierarchy 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.
|
UIManager |
getUIManager()
This method should be used by the Component to retrieve the correct UIManager to work with
|
protected void |
initLaf(UIManager uim)
This method initializes the Component defaults constants
|
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
|
protected boolean |
isSelectableInteraction()
This method allows a component to indicate that it is interested in an "implicit" select
command to appear in the "fire" button when 3 softbuttons are defined in a device.
|
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 |
morph(Component source,
Component destination,
int duration,
Runnable onCompletion)
Morph is similar to the replace functionality where a component might be replaced with
a component that isn't within the container.
|
void |
morphAndWait(Component source,
Component destination,
int duration)
Morph is similar to the replace functionality where a component might be replaced with
a component that isn't within the container.
|
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 |
paintComponentBackground(Graphics g)
Paints the background of the component, invoked with the clipping region
and appropriate scroll translation.
|
protected void |
paintGlass(Graphics g)
This method can be overriden by a component to draw on top of itself or its children
after the component or the children finished drawing in a similar way to the glass
pane but more refined per component
|
protected String |
paramString()
Returns a string representing the state of this component.
|
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(boolean merge)
Makes sure the component is up to date with the current theme, ONLY INVOKE THIS METHOD IF YOU CHANGED THE THEME!
|
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,
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 |
scrollComponentToVisible(Component c)
Makes sure the component is visible in the scroll if this container is
scrollable
|
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
|
protected void |
setShouldLayout(boolean layout)
Flags this container to preform layout
|
void |
setUIManager(UIManager uiManager)
Allows replacing the UIManager in a component hierarchy to update the look and feel
only to a specific hierarchy
|
addDragOverListener, addDropListener, addFocusListener, addPointerDraggedListener, addPointerPressedListener, addPointerReleasedListener, addPullToRefresh, addScrollListener, animate, bindProperty, calcScrollSize, contains, deinitialize, deinitializeCustomStyle, dragEnter, dragExit, draggingOver, drawDraggedImage, focusGained, focusLost, getAbsoluteX, getAbsoluteY, getBaseline, getBaselineResizeBehavior, getBindablePropertyNames, getBindablePropertyTypes, getBorder, getBoundPropertyValue, getBounds, getClientProperty, getCloudBoundProperty, getCloudDestinationProperty, getComponentForm, getComponentState, getDirtyRegion, getDisabledStyle, getDraggedx, getDraggedy, getDragImage, getDragRegionStatus, getDragSpeed, getHeight, getLabelForComponent, getName, getNextFocusDown, getNextFocusLeft, getNextFocusRight, getNextFocusUp, getParent, getPreferredH, getPreferredSize, getPreferredW, getPressedStyle, getPropertyNames, getPropertyTypeNames, getPropertyTypes, getPropertyValue, getSameHeight, getSameWidth, getScrollable, getScrollAnimationSpeed, getScrollDimension, getScrollOpacity, getScrollOpacityChangeSpeed, getScrollX, getScrollY, getSelectCommandText, getSelectedRect, getSelectedStyle, getStyle, getTensileLength, getUIID, getUnselectedStyle, getVisibleBounds, getWidth, getX, getY, growShrink, handlesInput, hasFocus, initComponent, initCustomStyle, installDefaultPainter, isAlwaysTensile, isCellRenderer, isDragActivated, isDragAndDropOperation, isDraggable, isDragRegion, isDropTarget, isFlatten, isFocusable, isGrabsPointerEvents, isHideInPortrait, isInClippingRegion, isInitialized, isRTL, isScrollable, isScrollVisible, isSmoothScrolling, isSnapToGrid, isStickyDrag, isTactileTouch, isTactileTouch, isTensileDragEnabled, isVisible, keyRepeated, laidOut, longKeyPress, longPointerPress, onScrollX, onScrollY, paintBackground, paintBackgrounds, paintBorder, paintComponent, paintComponent, paintLock, paintLockRelease, paintScrollbars, paintScrollbarX, paintScrollbarY, pinch, pointerDragged, pointerDragged, pointerHoverPressed, pointerHoverReleased, pointerPressed, pointerReleased, pointerReleased, putClientProperty, refreshTheme, refreshTheme, removeDragOverListener, removeDropListener, removeFocusListener, removePointerDraggedListener, removePointerPressedListener, removePointerReleasedListener, removeScrollListener, repaint, repaint, requestFocus, resetFocusable, scrollRectToVisible, scrollRectToVisible, setAlwaysTensile, setBoundPropertyValue, setCloudBoundProperty, setCloudDestinationProperty, setComponentState, setDirtyRegion, setDisabledStyle, setDraggable, setDropTarget, setFlatten, setFocus, setFocusable, setGrabsPointerEvents, setHandlesInput, setHeight, setHideInPortrait, setInitialized, setIsScrollVisible, setLabelForComponent, setName, setNextFocusDown, setNextFocusLeft, setNextFocusRight, setNextFocusUp, setPreferredH, setPreferredSize, setPreferredW, setPressedStyle, setPropertyValue, setRTL, setSameHeight, setSameWidth, setScrollAnimationSpeed, setScrollOpacityChangeSpeed, setScrollSize, setScrollVisible, setScrollX, setScrollY, setSelectCommandText, setSelectedStyle, setSize, setSmoothScrolling, setSnapToGrid, setTactileTouch, setTensileDragEnabled, setTensileLength, setUIID, setUnselectedStyle, setVisible, setWidth, setX, setY, shouldBlockSideSwipe, styleChanged, toString, unbindProperty
public Container(Layout layout)
layout
- the specified layout managerpublic Container()
FlowLayout
.protected void initLaf(UIManager uim)
Component
public UIManager getUIManager()
Component
getUIManager
in class Component
public void setUIManager(UIManager uiManager)
uiManager
- UIManager instancepublic void setLeadComponent(Component lead)
lead
- component that takes over the hierarchypublic Component getLeadComponent()
public Container getLeadParent()
public void keyPressed(int k)
Component
keyPressed
in class Component
k
- the key code value to indicate a physical key.public void keyReleased(int k)
Component
keyReleased
in class Component
k
- the key code value to indicate a physical key.public Layout getLayout()
public void setLayout(Layout layout)
layout
- the specified layout managerpublic void invalidate()
protected void setShouldLayout(boolean layout)
layout
- public void setShouldCalcPreferredSize(boolean shouldCalcPreferredSize)
Component
setShouldCalcPreferredSize
in class Component
shouldCalcPreferredSize
- indicate whether this component need to
recalculate his preferred sizepublic int getLayoutWidth()
public int getLayoutHeight()
public void applyRTL(boolean rtl)
rtl
- right to left bidi indicationComponent.setRTL(boolean)
public void addComponent(Component cmp)
cmp
- the component to be addedpublic void addComponent(Object constraints, Component cmp)
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 addpublic void addComponent(int index, Object constraints, Component cmp)
index
- location to insert the Componentconstraints
- 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 addpublic void addComponent(int index, Component cmp)
index
- location to insert the Componentcmp
- the Component to addArrayIndexOutOfBoundsException
- if index is out of boundsIllegalArgumentException
- if Component is already contained or
the cmp is a Form Componentpublic void replaceAndWait(Component current, Component next, Transition t)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullpublic void replaceAndWait(Component current, Component next, Transition t, int layoutAnimationSpeed)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nulllayoutAnimationSpeed
- the speed of the layout animation after replace is completedpublic void replace(Component current, Component next, Transition t, Runnable onFinish, int growSpeed)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullonFinish
- invoked when the replace operation is completed, may be nullgrowSpeed
- 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 occurspublic void replaceAndWait(Component current, Component next, Transition t, boolean dropEvents)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nulldropEvents
- indicates if the display should drop all events
while this Component replacing is happeningpublic void replace(Component current, Component next, Transition t)
current
- a Component to remove from the Containernext
- a Component that replaces the current Componentt
- a Transition between the add and removal of the Components
a Transition can be nullpublic boolean isEnabled()
Component
public void removeComponent(Component cmp)
cmp
- the removed componentprotected void cancelRepaints()
cancelRepaints
in class Component
public void flushReplace()
public void removeAll()
public void revalidate()
public void forceRevalidate()
public void clearClientProperties()
Component
clearClientProperties
in class Component
public void paint(Graphics g)
Component
protected void paintGlass(Graphics g)
g
- the graphics contextpublic void layoutContainer()
public int getComponentCount()
public Component getComponentAt(int index)
index
- of the Component you wish to getArrayIndexOutOfBoundsException
- if an invalid index was given.public int getComponentIndex(Component cmp)
cmp
- the component to search forpublic boolean contains(Component cmp)
cmp
- a Component to checkpublic void scrollComponentToVisible(Component c)
c
- the component that will be scrolling for visibilitypublic Component getClosestComponentTo(int x, int y)
x
- location in container relative coordinatesy
- location in container relative coordinatespublic Component getComponentAt(int x, int y)
x
- absolute screen locationy
- absolute screen locationComponent.contains(int, int)
public void pointerHover(int[] x, int[] y)
Component
pointerHover
in class Component
x
- the pointer x coordinatey
- the pointer y coordinatepublic void pointerPressed(int x, int y)
Component
pointerPressed
in class Component
x
- the pointer x coordinatey
- the pointer y coordinateprotected Dimension calcPreferredSize()
Component
calcPreferredSize
in class Component
protected String paramString()
Component
null
.paramString
in class Component
public void refreshTheme(boolean merge)
Component
refreshTheme
in class Component
merge
- indicates if the current styles should be merged with the new stylespublic boolean isScrollableX()
Component
isScrollableX
in class Component
public boolean isScrollableY()
Component
isScrollableY
in class Component
public int getSideGap()
Component
getSideGap
in class Component
public int getBottomGap()
Component
getBottomGap
in class Component
public void setScrollableX(boolean scrollableX)
scrollableX
- whether the component should/could scroll on the X axispublic void setScrollableY(boolean scrollableY)
scrollableY
- whether the component should/could scroll on the Y axispublic void setScrollable(boolean scrollable)
scrollable
- whether the component should/could scroll on the
X and Y axispublic void setCellRenderer(boolean cellRenderer)
Component
setCellRenderer
in class Component
cellRenderer
- indicate whether this component is currently being
used as a cell rendererpublic void setScrollIncrement(int scrollIncrement)
scrollIncrement
- the size in pixels.public int getScrollIncrement()
public Component findFirstFocusable()
protected void dragInitiated()
Component
dragInitiated
in class Component
protected void fireClicked()
Component
fireClicked
in class Component
protected boolean isSelectableInteraction()
Component
isSelectableInteraction
in class Component
public void setEnabled(boolean enabled)
setEnabled
in class Component
enabled
- protected int getGridPosY()
Component
getGridPosY
in class Component
public void paintComponentBackground(Graphics g)
Component
g
- the component graphicsprotected int getGridPosX()
Component
getGridPosX
in class Component
public void animateHierarchyAndWait(int duration)
duration
- the duration in milliseconds for the animationpublic void animateHierarchy(int duration)
duration
- the duration in milliseconds for the animationpublic void animateHierarchyFadeAndWait(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateHierarchyFade(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateLayoutFadeAndWait(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateLayoutFade(int duration, int startingOpacity)
duration
- the duration in milliseconds for the animationstartingOpacity
- the initial opacity to give to the animated componentspublic void animateLayoutAndWait(int duration)
duration
- the duration in milliseconds for the animationpublic void animateLayout(int duration)
duration
- the duration in milliseconds for the animationpublic void drop(Component dragged, int x, int y)
Component
protected Motion createAnimateMotion(int start, int destination, int duration)
start
- start valuedestination
- destination valueduration
- duration of animationpublic void morph(Component source, Component destination, int duration, Runnable onCompletion)
source
- source component assumed to be within this container or one of its childrendestination
- the destination componentduration
- the time the morph operation should takeonCompletion
- invoked when the morphing completespublic void morphAndWait(Component source, Component destination, int duration)
source
- source component assumed to be within this container or one of its childrendestination
- the destination componentduration
- the time the morph operation should takepublic void animateUnlayout(int duration, int opacity, Runnable callback)
duration
- the duration of the animationopacity
- the opacity to which the layout will reach, allows fading out the componentscallback
- if not null will be invoked when unlayouting is completepublic void animateUnlayoutAndWait(int duration, int opacity)
duration
- the duration of the animationopacity
- the opacity to which the layout will reach, allows fading out the components