Package totalcross.ui
Class ListContainer
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ScrollContainer
-
- totalcross.ui.ListContainer
-
- All Implemented Interfaces:
UpdateListener,Scrollable
public class ListContainer extends ScrollContainer
ListContainer is a ListBox where each item is a Container.The correct way to create a ListContainer item is by subclassing a Container and adding the controls in the initUI method. Adding directly using
getContainer(i).addwill not work. Below is an example of how to use it, taken from the UIGadgets sample.class LCItem extends ScrollContainer { Label lDate,lPrice,lDesc; Check chPaid; public LCItem() { super(false); // VERY IMPORTANT (a RuntimeException will be thrown if this is not used). } public void initUI() { add(chPaid = new Check("Paid"),LEFT,TOP); add(lDate = new Label("99/99/9999"),RIGHT,TOP); add(new Label("US$"),LEFT,AFTER); add(lPrice = new Label("999.999.99"),AFTER,SAME); add(lDesc = new Label("",RIGHT),AFTER+10,SAME); lDesc.setText("description"); } } private void testListContainer() { ListContainer lc; add(lc = new ListContainer(),LEFT,TOP,FILL,FILL); for (int i =0; i < 10; i++) lc.addContainer(new LCItem()); }When an item is selected, a PRESSED event is dispatched. Check the ListContainerSample in the sdk for a bunch of ideas of what can be done with this component. The ListContainer supports navigation using the keys up/down, page-up/down, and enter. The left and right keys acts like clicking in the left or right buttons (if any).- Since:
- TotalCross 1.14
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static classListContainer.ItemAn item of the ListContainer.classListContainer.LayoutA set of fields and default fields that will be used to define the layout of a ListContainer's Item.-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleandrawHLineIf true (default), draws a horizontal line between each container.inthighlightColorColor used to highlight a container.protected ContainerlastSelprotected intlastSelBackprotected intlastSelIndex-
Fields inherited from class totalcross.ui.ScrollContainer
autoScroll, bag, bag0, disabledFlick, flick, hsIgnoreAutoScroll, lastH, lastV, sbH, sbV, shrink2size
-
Fields inherited from class totalcross.ui.Container
alwaysEraseBackground, BACKGROUND_CYLINDRIC_SHADED, BACKGROUND_SHADED, BACKGROUND_SHADED_INV, BACKGROUND_SOLID, backgroundStyle, BORDER_LOWERED, BORDER_NONE, BORDER_RAISED, BORDER_ROUNDED, BORDER_SIMPLE, BORDER_TOP, borderColor, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastScreenWidth, lastW, lastX, lastY, npback, numChildren, started, tabOrder, tail, TRANSITION_CLOSE, TRANSITION_FADE, TRANSITION_NONE, TRANSITION_OPEN, TRANSITION_TIME, transitionEffect
-
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 ListContainer()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddContainer(Container c)Adds a new Container to this list.voidaddContainers(Container[] all)Adds an array of Containers to this list.ContainergetContainer(int idx)Returns the given container number or null if its invalid.ListContainer.LayoutgetLayout(int itemCount, int itemsPerLine)Creates a Layout object with the given parameters.intgetSelectedIndex()Returns the selected index, or -1 if none is selected.ContainergetSelectedItem()Returns the selected container, or null if none is selected.voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event e)Called to process key, pen, control and other posted events.voidremoveAllContainers()Removes all containers of this ListContainer.voidresize()This method resizes the control to the needed bounds, based on added childs.voidscrollToControl(Control c)Positions the given Container (that should be a control added to this ListContainer) at the top of the list.voidsetBackColor(Container c, int back)Changes the color of all controls inside the given container that matches the background color of this ListContainer.voidsetSelectedIndex(int idx)Sets the selected container based on its index.voidsetSelectedItem(Container c)Sets the selected container.intsize()Returns the number of items of this list-
Methods inherited from class totalcross.ui.ScrollContainer
add, addScrollEventHandler, bagSetRect, canScrollContent, canShowScrollBars, disableFlick, enableFlick, flickEnded, flickStarted, getBagChildren, getBagInitialHeight, getBagInitialWidth, getClientRect, getFlick, getPreferredHeight, getPreferredWidth, getRealClientRect, getScrollDistance, getScrollPosition, moveFocusToNextControl, onBoundsChanged, onFontChanged, onPaint, remove, removeAll, removeScrollEventHandler, reposition, resize, scrollContent, scrollPage, scrollToOrigin, scrollToPage, setBorderStyle, setHandlersVisibility, setHandlersVisibility, setHValue, setScrollBars, setVValue, updateListenerTriggered, wasScrolled
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, applyTransitionEffect, broadcastEvent, clear, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getFirstChild, getFocusableControls, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resizeHeight, resizeWidth, setEnabled, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
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, 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, onWindowPaintFinished, post, postEvent, postPressedEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHandler, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, 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
-
lastSel
protected Container lastSel
-
lastSelBack
protected int lastSelBack
-
lastSelIndex
protected int lastSelIndex
-
highlightColor
public int highlightColor
Color used to highlight a container. Based on the background color.
-
drawHLine
public boolean drawHLine
If true (default), draws a horizontal line between each container.
-
-
Method Detail
-
getLayout
public ListContainer.Layout getLayout(int itemCount, int itemsPerLine)
Creates a Layout object with the given parameters.
-
onColorsChanged
public 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 classScrollContainer
-
size
public int size()
Returns the number of items of this list
-
addContainer
public void addContainer(Container c)
Adds a new Container to this list.- See Also:
addContainers(totalcross.ui.Container[])
-
addContainers
public void addContainers(Container[] all)
Adds an array of Containers to this list. Adding hundreds of containers is hundred times faster using this method instead of adding one at a time. Consider also to increase the value of Flick.defaultLongestFlick BEFORE creating the ListContainer, otherwise the user may take forever to flick. You can set it to 3 * all.length, if all.length is above 1000.- See Also:
Flick.defaultLongestFlick
-
removeAllContainers
public void removeAllContainers()
Removes all containers of this ListContainer. Note that onRemove is not called in the containers.
-
onEvent
public void onEvent(Event e)
Description copied from class:ControlCalled to process key, pen, control and other posted events.- Overrides:
onEventin classScrollContainer- Parameters:
e- the event to process- See Also:
Event,KeyEvent,PenEvent
-
getSelectedItem
public Container getSelectedItem()
Returns the selected container, or null if none is selected.
-
getSelectedIndex
public int getSelectedIndex()
Returns the selected index, or -1 if none is selected.
-
setSelectedIndex
public void setSelectedIndex(int idx)
Sets the selected container based on its index.- Parameters:
idx- The index or -1 to unselect all containers.
-
setSelectedItem
public void setSelectedItem(Container c)
Sets the selected container.
-
getContainer
public Container getContainer(int idx)
Returns the given container number or null if its invalid.
-
setBackColor
public void setBackColor(Container c, int back)
Changes the color of all controls inside the given container that matches the background color of this ListContainer.
-
resize
public void resize()
Description copied from class:ScrollContainerThis method resizes the control to the needed bounds, based on added childs. Must be called if you're controlling reposition by your own, after you repositioned the controls inside of it.- Overrides:
resizein classScrollContainer- See Also:
Container.resizeWidth(),Container.resizeHeight()
-
scrollToControl
public void scrollToControl(Control c)
Positions the given Container (that should be a control added to this ListContainer) at the top of the list.- Overrides:
scrollToControlin classScrollContainer
-
-