Package totalcross.ui
Class Container
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- Direct Known Subclasses:
AccordionContainer.Caption,AlignedLabelsContainer,AlphabetKeyboard,Bar,BorderContainer,ChartData,ClippedContainer,ComboBox,ComponentWrarper,FlowContainer,GPSView,Grid,GridContainer,GridContainer.Cell,HtmlContainer,LinearBox,ListBox,ListContainer.Item,MultiEdit,NumericAndSymbolsKeyboard,ScrollBar,ScrollContainer,SideMenuContainer,SideMenuContainer.Sub.Caption,TopMenu.Item,Tree,Velocimeter,Window
public class Container extends Control
Container is a control that contains child controls.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleanalwaysEraseBackgroundSet to true to always erase the background when repainting this container.static intBACKGROUND_CYLINDRIC_SHADEDused in the backgroundStyle field.static intBACKGROUND_SHADEDused in the backgroundStyle fieldstatic intBACKGROUND_SHADED_INVused in the backgroundStyle fieldstatic intBACKGROUND_SOLIDused in the bckgroundStyle fieldintbackgroundStyleSets the type of background of this Container.static byteBORDER_LOWEREDused in the setBorderStyle methodstatic byteBORDER_NONEused in the setBorderStyle methodstatic byteBORDER_RAISEDused in the setBorderStyle methodstatic byteBORDER_ROUNDEDused in the setBorderStyle method.static byteBORDER_SIMPLEused in the setBorderStyle methodstatic byteBORDER_TOPused in the setBorderStyle methodintborderColorThe color used in the border.protected ControlchildrenThe children of the container.protected static booleancontrolFoundReturns true if the control was found in findChild, false otherwise.protected booleanfinishedStartprotected booleanignoreOnAddAgainSet to true to avoid calling the methods onRemove or onAddAgainprotected booleanignoreOnRemoveSet to true to avoid calling the methods onRemove or onAddAgainprotected InsetsinsetsThe insets of this container.protected intlastHprotected intlastScreenWidthprotected intlastWprotected intlastXprotected intlastYprotected Imagenpbackprotected intnumChildrenprotected booleanstartedVectortabOrderHolds the controls that will be used to transfer focus when the tab key is pressed.protected ControltailThe tail of the children list.static intTRANSITION_CLOSEUsed when animating the exhibition of a container.static intTRANSITION_FADEUsed when animating the exhibition of a container.static intTRANSITION_NONEUsed when animating the exhibition of a container.static intTRANSITION_OPENUsed when animating the exhibition of a container.static intTRANSITION_TIMEDefines the total transition time.inttransitionEffectSet the transition effect when this container appears on screen.-
Fields inherited from class totalcross.ui.Control
AFTER, alphaValue, appId, appObj, asContainer, asWindow, backColor, BEFORE, BOTTOM, BOTTOM_OF, BRIGHTER_BACKGROUND, callListenersOnAllTargets, CENTER, CENTER_OF, clearValueInt, clearValueStr, DARKER_BACKGROUND, DP, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, floating, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, next, nextTabControl, npParts, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, prev, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, SETX_NOT_SET, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description Container()Creates a container with the default colors.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(Control control)Adds a child control to this container.voidadd(Control control, int x, int y)Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the last control added Same ofvoidadd(Control control, int x, int y, int w, int h)Adds the control to this container, using the given bounds, relative to the last control added Same ofvoidadd(Control control, int x, int y, int w, int h, Control relative)Adds the control to this container, using the given bounds, relative to the given control.voidadd(Control control, int x, int y, Control relative)Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the given control Same ofstatic voidapplyTransitionEffect()voidbroadcastEvent(Event e)Posts an event to the children of this container and to all containers inside this containers; recursively.voidclear()Clears all children controls that arefocusTraversable, recursively.protected voidfillBackground(Graphics g, int b)ControlfindChild(int x, int y)Returns the child located at the given x and y coordinates.ControlfindNearestChild(int x, int y, int minDistance)ControlfindNextFocusControl(Control c, int direction)Finds the next control that should receive focus based on the direction with respect to c.bytegetBorderStyle()Returns the border style.Control[]getChildren()Return an array of Controls that are added to this Container.intgetChildrenCount()RectgetClientRect()Returns the client rect for this Container, in relative coords.protected voidgetClientRect(Rect r)Returns the client rect for this Container, in relative coords, excluding the insets.ControlgetFirstChild()voidgetFocusableControls(Vector v)Get a list of child controls of this container which are focus candidatesvoidgetInsets(Insets copyInto)Copy the current insets values into the given insets.voidincLastX(int n)Increments the lastX, used in relative positioning.voidincLastY(int n)Increments the lastY, used in relative positioning.voidinitUI()Called to initialize the User Interface of this container.booleanisPressed()ControlmoveFocusToNextControl(Control control, boolean forward)Moves the focus to the next control, which can be an Edit, a MultiEdit, or another control type.ControlmoveFocusToNextEditable(Control control, boolean forward)Moves the focus to the next Edit or MultiEdit control.protected voidonAddAgain()When the container is added for the first time, the method initUI is called, so the user interface can be initialized.protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonPaint(Graphics g)Draws the border (if any).protected voidonRemove()Called when this container is removed from the parent.voidonSwapFinished()Called when this container has been swapped into the Window and the swap is done.voidpaintChildren()Called by the system to draw the children of the container.voidremove(Control control)Removes a child control from the container.voidremoveAll()Removes all controls inside this container.voidresize()This method resizes the Container's width and height to the needed bounds, based on added childs.voidresizeHeight()This method resizes the Container's width to the needed bounds, based on added childs.voidresizeWidth()This method resizes the Container's width to the needed bounds, based on added childs.voidsetBorderStyle(byte border)Sets the border for this container.voidsetEnabled(boolean enabled)Sets if this container and all childrens can or not accept eventsvoidsetFocusTraversable(boolean b)Changes the focusTraversable property for this container and all controls, recursivelyvoidsetHighlighting()Called by the event dispatcher to set highlighting back to true.voidsetInsets(int left, int right, int top, int bottom)Sets the insets value to match the given ones.static voidsetNextTransitionEffect(int t)The transition effect to apply in the next screen update.voidsetPressColor(int color)voidsetPressed(boolean p)voidswapToTopmostWindow()Call this method to swap this Container to the topmost window.-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addFontChangeHandler, addGridListener, addHandler, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addSizeChangeHandler, addTimer, addTimer, addTimerListener, addValueChangeHandler, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getDoEffect, getEffectH, getEffectW, getEffectX, getEffectY, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPreferredHeight, getPreferredWidth, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, handleGeographicalFocusChangeKeys, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onBoundsChanged, onEvent, onFontChanged, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, resetStyle, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setDoEffect, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
children
protected Control children
The children of the container.
-
tail
protected Control tail
The tail of the children list.
-
npback
protected Image npback
-
backgroundStyle
public int backgroundStyle
Sets the type of background of this Container. To disable the background, set thetransparentBackgroundof the Control class to true. This field is used when transparentBackground is set to false (default). If the transparent background doesn't work, try settingalwaysEraseBackground = true.- Since:
- TotalCross 1.3
- See Also:
BACKGROUND_SHADED,BACKGROUND_SOLID,UIColors.shadeFactor
-
BORDER_NONE
public static final byte BORDER_NONE
used in the setBorderStyle method- See Also:
- Constant Field Values
-
BORDER_LOWERED
public static final byte BORDER_LOWERED
used in the setBorderStyle method- See Also:
- Constant Field Values
-
BORDER_RAISED
public static final byte BORDER_RAISED
used in the setBorderStyle method- See Also:
- Constant Field Values
-
BORDER_SIMPLE
public static final byte BORDER_SIMPLE
used in the setBorderStyle method- See Also:
- Constant Field Values
-
BORDER_TOP
public static final byte BORDER_TOP
used in the setBorderStyle method- See Also:
- Constant Field Values
-
BORDER_ROUNDED
public static final byte BORDER_ROUNDED
used in the setBorderStyle method.- Since:
- TotalCross 2.0
- See Also:
- Constant Field Values
-
BACKGROUND_SOLID
public static final int BACKGROUND_SOLID
used in the bckgroundStyle field- See Also:
- Constant Field Values
-
BACKGROUND_SHADED
public static final int BACKGROUND_SHADED
used in the backgroundStyle field- See Also:
- Constant Field Values
-
BACKGROUND_SHADED_INV
public static final int BACKGROUND_SHADED_INV
used in the backgroundStyle field- See Also:
- Constant Field Values
-
BACKGROUND_CYLINDRIC_SHADED
public static final int BACKGROUND_CYLINDRIC_SHADED
used in the backgroundStyle field. The bright color must be the fore color, and the darker color, the back color- Since:
- TotalCross 2.0
- See Also:
- Constant Field Values
-
TRANSITION_NONE
public static final int TRANSITION_NONE
Used when animating the exhibition of a container.- See Also:
- Constant Field Values
-
TRANSITION_OPEN
public static final int TRANSITION_OPEN
Used when animating the exhibition of a container.- See Also:
- Constant Field Values
-
TRANSITION_CLOSE
public static final int TRANSITION_CLOSE
Used when animating the exhibition of a container.- See Also:
- Constant Field Values
-
TRANSITION_FADE
public static final int TRANSITION_FADE
Used when animating the exhibition of a container.- See Also:
- Constant Field Values
-
borderColor
public int borderColor
The color used in the border.- Since:
- TotalCross 2.0
-
transitionEffect
public int transitionEffect
Set the transition effect when this container appears on screen. Defaults to Control.UPDATESCREEN_AT_ONCE, which means no transition effects. The transition is applied by the popup/unpop methods (if this container is a Window), or in the swap method (otherwise).
See the UIGadgets and the ContainerSwitch samples in the SDK.- Since:
- TotalCross 1.2
- See Also:
TRANSITION_NONE,TRANSITION_OPEN,TRANSITION_CLOSE,Window.swap(Container),Window.popup(),Window.unpop(),nextTransitionEffect
-
TRANSITION_TIME
public static int TRANSITION_TIME
Defines the total transition time. Defaults to 1000 (1 second).- Since:
- TotalCross 1.68
-
lastX
protected int lastX
-
lastY
protected int lastY
-
lastW
protected int lastW
-
lastH
protected int lastH
-
numChildren
protected int numChildren
-
started
protected boolean started
-
ignoreOnRemove
protected boolean ignoreOnRemove
Set to true to avoid calling the methods onRemove or onAddAgain
-
ignoreOnAddAgain
protected boolean ignoreOnAddAgain
Set to true to avoid calling the methods onRemove or onAddAgain
-
finishedStart
protected boolean finishedStart
-
tabOrder
public Vector tabOrder
Holds the controls that will be used to transfer focus when the tab key is pressed. You can add or remove controls from here, but be careful not to add repeated controls.- Since:
- SuperWaba 5.5
-
lastScreenWidth
protected int lastScreenWidth
-
insets
protected Insets insets
The insets of this container. Never change it directly, otherwise some controls may not work correctly; use setInsets instead.- See Also:
setInsets(int, int, int, int)
-
alwaysEraseBackground
public boolean alwaysEraseBackground
Set to true to always erase the background when repainting this container.- Since:
- TotalCross 1.0
-
controlFound
protected static boolean controlFound
Returns true if the control was found in findChild, false otherwise.- Since:
- TotalCross 1.2
-
-
Constructor Detail
-
Container
public Container()
Creates a container with the default colors. Important note: this container has no default size.
NEVER INITIALIZE THE USER INTERFACE IN THE CONSTRUCTOR
If you're extending the Container class and adding controls in its constructor, you may come into problems if you don't set the bounds as the first thing.
-
-
Method Detail
-
setPressColor
public void setPressColor(int color)
-
setPressed
public void setPressed(boolean p)
-
isPressed
public boolean isPressed()
-
setNextTransitionEffect
public static void setNextTransitionEffect(int t)
The transition effect to apply in the next screen update. After this effect is applied, the next effect is set to TRANSITION_NONE.- Since:
- TotalCross 1.2
- See Also:
transitionEffect,TRANSITION_NONE,TRANSITION_OPEN,TRANSITION_CLOSE,TRANSITION_FADE
-
applyTransitionEffect
public static void applyTransitionEffect()
-
setInsets
public void setInsets(int left, int right, int top, int bottom)Sets the insets value to match the given ones.- Since:
- TotalCross 1.01
-
getInsets
public void getInsets(Insets copyInto)
Copy the current insets values into the given insets. If you call this method often, create an Insets field and reuse it.- Parameters:
copyInto- The created object where the insets values will be copied into.- Since:
- TotalCross 1.01
-
add
public void add(Control control, int x, int y, int w, int h)
Adds the control to this container, using the given bounds, relative to the last control added Same ofadd(control); control.setRect(x,y,w,h, null,false);
-
add
public void add(Control control, int x, int y, int w, int h, Control relative)
Adds the control to this container, using the given bounds, relative to the given control. Same ofadd(control); control.setRect(x,y,w,h, relative,false);
-
add
public void add(Control control, int x, int y)
Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the last control added Same ofadd(control); control.setRect(x,y,PREFERRED,PREFERRED, null,false);
-
add
public void add(Control control, int x, int y, Control relative)
Add the control to this container and set its rect to be the given x,y and PREFERRED as width/height relative to the given control Same ofadd(control); control.setRect(x,y,PREFERRED,PREFERRED, relative,false);
-
add
public void add(Control control)
Adds a child control to this container. Important: If you're swapping containers from the MainWindow, be sure that you set the focus on the new container after calling this add method. Otherwise, a MenuBar will not work. Or, use the handy method Window.swap
-
remove
public void remove(Control control)
Removes a child control from the container.
-
findChild
public Control findChild(int x, int y)
Returns the child located at the given x and y coordinates. Usually, if a control is not found, the last visited container is returned. In this case, controlFound is set to false.- See Also:
controlFound
-
findNearestChild
public Control findNearestChild(int x, int y, int minDistance)
-
getChildren
public Control[] getChildren()
Return an array of Controls that are added to this Container.
-
getFirstChild
public Control getFirstChild()
-
getChildrenCount
public int getChildrenCount()
-
setEnabled
public void setEnabled(boolean enabled)
Sets if this container and all childrens can or not accept events- Overrides:
setEnabledin classControl
-
broadcastEvent
public void broadcastEvent(Event e)
Posts an event to the children of this container and to all containers inside this containers; recursively.- Since:
- SuperWaba 2.0 beta 4
-
paintChildren
public void paintChildren()
Called by the system to draw the children of the container.
-
setBorderStyle
public void setBorderStyle(byte border)
Sets the border for this container. The insets are changed after this method is called. The BORDER_ROUNDED sets the background to transparent.- See Also:
BORDER_NONE,BORDER_LOWERED,BORDER_RAISED,BORDER_SIMPLE,BORDER_TOP,BORDER_ROUNDED
-
getClientRect
public Rect getClientRect()
Returns the client rect for this Container, in relative coords. The client rectangle usually excludes the title (if applicable) and the border. If you call this method often, consider using the other version, where a cached Rect is used; it avoids the creation of a Rect.- See Also:
getClientRect(Rect)
-
getClientRect
protected void getClientRect(Rect r)
Returns the client rect for this Container, in relative coords, excluding the insets. In this version, you provide the instantiated Rect to be filled with the coords.
-
onColorsChanged
protected void onColorsChanged(boolean colorsChanged)
Description copied from class:ControlCalled after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container. If colorsChanged is true, it was called from setForeColor/setBackColor/Container.add; otherwise, it was called from setEnabled- Overrides:
onColorsChangedin classControl
-
fillBackground
protected void fillBackground(Graphics g, int b)
-
onPaint
public void onPaint(Graphics g)
Draws the border (if any). If you override this method, be sure to callsuper.onPaint(g);, or the border will not be drawn.
-
onAddAgain
protected void onAddAgain()
When the container is added for the first time, the method initUI is called, so the user interface can be initialized. From the second time and up that the container is added, the onAddAgain method is called instead.
If this container is a window, this method is not called when the window is popped.
If you don't want this method to be called, you must setignoreOnAddAgain = true;inside the method initUI or the class constructor. Doing so makes the user interface initialize faster.- Since:
- SuperWaba 4.1
-
onRemove
protected void onRemove()
Called when this container is removed from the parent. Note that, if this container is a window, this method is not called when the window is unpopped.
If you don't want this method to be called, you must setignoreOnRemove = true;inside the method initUI or the class constructor. Doing so makes the user interface initialize faster.- Since:
- SuperWaba 4.1
-
initUI
public void initUI()
Called to initialize the User Interface of this container. This differs from the onAddAgain method by that this method is called only once, at the first time the control is added to the parent. When the container is being setup, the initUI method is called; then, the onAddAgain is called every time the container is added again.- Since:
- SuperWaba 3.4
-
setHighlighting
public void setHighlighting()
Called by the event dispatcher to set highlighting back to true. A class may extend this to decide when its time to turn it on again or not.
-
swapToTopmostWindow
public void swapToTopmostWindow()
Call this method to swap this Container to the topmost window. Note that since we have no idea who is our future parent window, we just use the topmost window. The topmost window is the one that is currently visible.
This method is useful if you have containers that are SINGLETONS and wish to set them as the current container. E.G.:public class MainMenu extends Container // create a Singleton from MainMenu { private static instance; public static getInstance() { return instance != null ? instance : (instance=new MainMenu()); } private MainMenu() { } } // then at some other class, you can do: MainMenu.getInstance().swapToTopmostWindow();- Since:
- SuperWaba 5.7
-
clear
public void clear()
Clears all children controls that arefocusTraversable, recursively.
-
getFocusableControls
public void getFocusableControls(Vector v)
Get a list of child controls of this container which are focus candidates- Parameters:
v- A vector into which to add the focus candidates.
-
findNextFocusControl
public Control findNextFocusControl(Control c, int direction)
Finds the next control that should receive focus based on the direction with respect to c.- Parameters:
c- The reference control from which to find the next control.direction- The direction in which to look from c. One of: SpecialKeys.LEFT, SpecialKeys.RIGHT, SpecialKeys.UP, SpecialKeys.DOWN- Returns:
- The control which should receive focus next, or null.
- See Also:
Settings.geographicalFocus
-
getBorderStyle
public byte getBorderStyle()
Returns the border style.
-
removeAll
public void removeAll()
Removes all controls inside this container.- Since:
- TotalCross 1.0
-
incLastX
public void incLastX(int n)
Increments the lastX, used in relative positioning.
-
incLastY
public void incLastY(int n)
Increments the lastY, used in relative positioning.
-
resize
public void resize()
This method resizes the Container's width and height to the needed bounds, based on added childs. You can add spaces at right and bottom using the insets.right/bottom properties. Sample:// this sample will center two buttons of different sizes on screen Container c = new Container(); add(c, CENTER,BOTTOM,1000,1000); c.add(new Button("Ok"),LEFT,TOP); c.add(new Button("Cancel"),AFTER+5,SAME); c.resize();Note: differently of Window.resize, this method does not call setRect again, it only changes the width and height by direct assignment.- Since:
- TotalCross 1.14
- See Also:
resizeWidth(),resizeHeight()
-
resizeWidth
public void resizeWidth()
This method resizes the Container's width to the needed bounds, based on added childs. You can add spaces at right using the insets.right property. Sample:// this sample will center two buttons of different sizes on screen Container c = new Container(); add(c, CENTER,BOTTOM,1000,1000); c.add(new Button("Ok"),LEFT,TOP); c.add(new Button("Cancel"),AFTER+5,SAME); c.resize();Note: differently of Window.resize, this method does not call setRect again, it only changes the width by direct assignment.- Since:
- TotalCross 1.14
- See Also:
resize(),resizeHeight()
-
resizeHeight
public void resizeHeight()
This method resizes the Container's width to the needed bounds, based on added childs. You can add spaces at bottom using the insets.bottom property. Sample:// this sample will center two buttons of different sizes on screen Container c = new Container(); add(c, CENTER,BOTTOM,1000,1000); c.add(new Button("Ok"),LEFT,TOP); c.add(new Button("Cancel"),AFTER+5,SAME); c.resize();Note: differently of Window.resize, this method does not call setRect again, it only changes the height by direct assignment.- Since:
- TotalCross 1.14
- See Also:
resizeWidth(),resize()
-
moveFocusToNextEditable
public Control moveFocusToNextEditable(Control control, boolean forward)
Moves the focus to the next Edit or MultiEdit control.- Returns:
- The selected control or null if none was found.
- Since:
- TotalCross 1.25
-
moveFocusToNextControl
public Control moveFocusToNextControl(Control control, boolean forward)
Moves the focus to the next control, which can be an Edit, a MultiEdit, or another control type. It does not show the keyboard.- Returns:
- The selected control or null if none was found.
- Since:
- TotalCross 1.53
-
setFocusTraversable
public void setFocusTraversable(boolean b)
Changes the focusTraversable property for this container and all controls, recursively
-
onSwapFinished
public void onSwapFinished()
Called when this container has been swapped into the Window and the swap is done.- Since:
- TotalCross 2.0
-
-