Package totalcross.ui
Class MultiListBox
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ListBox
-
- totalcross.ui.MultiListBox
-
- All Implemented Interfaces:
Scrollable
public class MultiListBox extends ListBox
MultiListBox is a listbox that allows more than one item to be selected. The maximum number of selections can be defined using setMaxSelections.
To create a ComboBox with a MultiListBox, use:MultiListBox mlb; new ComboBox(mlb = new MultiListBox())
Be sure to save a reference to the MultiListBox so you can call the specific methods of this class. For instance, getSelectedIndex returns just the last selected index; to retrieve all indexes, use getSelectedIndexes.
In penless devices, there will be a cursor which will be used to highlight an item; to select or unselect it, you must press the left key.
MultiListBox requires the useFullWidthOnSelection on penless devices.- Since:
- TotalCross 1.0.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.ListBox
ListBox.CustomDrawingItem, ListBox.IconItem
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleanchangedInternal use only.IntVectorclearValuesFill this IntVector with the values that will be selected when the clear method is called.static java.lang.StringitemsTextGlobal suffix used to display the number of items in a ComboBox.java.lang.StringlocalItemsTextLocal suffix to display the number of items in a ComboBox.protected intmaxSelectionsprotected static intNO_OLD_SELECTIONprotected intoldSelectionprotected IntVectororderprotected IntHashtableselectedIndexesbooleanshowOrderInTipSet to false to don't show the number of selected elements as they are clicked.inttipDelayThe amount of time used to show how many itens.booleanunselectFirstWhenMaxIsReachedSet to true if you want to unselect the first element once max is reached.-
Fields inherited from class totalcross.ui.ListBox
back0, back1, btnX, btnX0, customCursorColor, dataCol, DEFAULT_ITEM_HEIGHT_FACTOR, drawBorder, EXTRA_HEIGHT_FACTOR, extraHorizScrollButtonHeight, flick, iconGap, ihFactor, ihtBackColors, ihtForeColors, itemCount, itemHeightFactor, items, offset, sbar, selectedIndex, simpleBorder, tempSelectedIndex, useFullWidthOnSelection, visibleItems, visibleLines, xOffset
-
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, lastH, lastScreenWidth, lastW, lastX, lastY, 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, effect, enableUpdateScreen, esce, eventsEnabled, FILL, fillColor, FIT, fm, fmH, focusHandler, focusLess, focusOnPenDown, focusTraversable, font, FONTSIZE, foreColor, height, ignoreInsets, isHighlighting, isTablet, KEEP, keepDisabled, keepEnabled, LEFT, nextTabControl, offscreen, offscreen0, onEventFirst, parent, PARENTSIZE, PARENTSIZEMAX, PARENTSIZEMIN, PREFERRED, RANGE, repositionAllowed, RIGHT, RIGHT_OF, SAME, SCREENSIZE, SCREENSIZEMAX, SCREENSIZEMIN, setFont, setH, setRel, setW, setX, setY, tempW, textShadowColor, TOP, translucentShape, transparentBackground, uiAdjustmentsBasedOnFontHeightIsSupported, uiAndroid, UICONST, uiFlat, uiHolo, uiMaterial, uiVista, visible, width, WILL_RESIZE, x, y
-
-
Constructor Summary
Constructors Constructor Description MultiListBox()Constructs an empty MultiListBox.MultiListBox(java.lang.Object[] items)Constructs a MultiListBox with the given items.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description protected voidcbddOnPopup()Called by ComboBoxDropDown when its being popped.protected voidcbddOnUnpop()Called by ComboBoxDropDown when its being unpopped.voidclear()Clears this control, selecting index clearValueInt.protected voiddrawItems(Graphics g, int dx, int dy, int greatestVisibleItemIndex)protected voiddrawSelectedItem(Graphics g, int from, int to)Draw all selected indexesprotected voidendSelection()protected intgetCursorColor(int index)java.lang.ObjectgetLastSelectedItem()Returns the last selected item if you had set order is important, otherwise returns null.intgetSelectedIndex()Returns the selected index.IntVectorgetSelectedIndexes()Return a vector with the indexes which have been selected.java.lang.StringgetText()Returns the String with the selected item (if single) or a string with the number of selected items.protected voidhandleClick(int index)ControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.protected voidhandleSelection(int newSelection)booleanisOrderImportant()Returns true if you requested that the order is important.booleanisSelected(int index)Returns if given index is selected.protected voidleftReached()protected voidonColorsChanged(boolean colorsChanged)Called after a setEnabled, setForeColor and setBackColor and when a control has been added to a Container.voidonEvent(Event e)Handles the events for this control.voidpostPressedEvent()Posts a ControlEvent.PRESSED event with this control as target.voidremoveAll()Empties this ListBox, setting all elements of the array tonullso they can be garbage collected.voidsetMaxSelections(int max)Defines the maximum number of items that can be selected.voidsetOrderIsImportant(boolean set)Call this method if you want to keep track of the order in which the items were selected.voidsetSelectedIndex(int index)In this MultiListBox, inverts the status of the given index, or clears all if i is -1.voidsetSelectedIndex(int index, boolean set)Sets or clear an index.-
Methods inherited from class totalcross.ui.ListBox
add, add, add, add, addWrapping, canScrollContent, drawCursor, drawItem, drawSelectedItem, enableHorizontalScroll, find, flickEnded, flickStarted, getEffectH, getEffectW, getEffectX, getEffectY, getFlick, getFocusableControls, getItemAt, getItemHeight, getItems, getItemsArray, getItemWidth, getPreferredHeight, getPreferredWidth, getScrollPosition, getSelectedItem, hideScrollBarIfNotNeeded, indexOf, insert, onBoundsChanged, onPaint, qsort, qsort, remove, remove, remove, scrollContent, selectLast, selectLast, setCursorColor, setEnabled, setItemAt, setSelectedItem, setSelectedItemStartingWith, setSimpleBorder, setTextAreaClip, size, wasScrolled
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, applyTransitionEffect, broadcastEvent, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resize, resizeHeight, resizeWidth, setBorderStyle, setFocusTraversable, setHighlighting, setInsets, setNextTransitionEffect, setPressColor, setPressed, swapToTopmostWindow
-
Methods inherited from class totalcross.ui.Control
_onEvent, addEnabledStateListener, addFocusListener, addGridListener, addHighlightListener, addKeyListener, addListContainerListener, addMouseListener, addMultiTouchListener, addPenListener, addPressListener, addPushNotificationListener, addTimer, addTimer, addTimerListener, addWindowListener, bringToFront, changeHighlighted, contains, drawTranslucentBackground, getAbsoluteRect, getBackColor, getEventListeners, getFont, getForeColor, getGap, getGraphics, getHeight, getNext, getParent, getParentWindow, getPos, getPressedEvent, getPrev, getRect, getSize, getTextShadowColor, getWidth, getX, getX2, getY, getY2, hadParentScrolled, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onFontChanged, onWindowPaintFinished, post, postEvent, releaseScreenShot, removeEnabledStateListener, removeFocusListener, removeGridListener, removeHighlightListener, removeKeyListener, removeListContainerListener, removeMouseListener, removeMultiTouchListener, removePenListener, removePressListener, removePushNotificationListener, removeTimer, removeTimerListener, removeWindowListener, repaint, repaintNow, reposition, reposition, repositionChildren, requestFocus, resetSetPositions, safeRepaintNow, safeUpdateScreen, sendToBack, setBackColor, setBackForeColors, setFocusLess, setFont, setForeColor, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
NO_OLD_SELECTION
protected static final int NO_OLD_SELECTION
- See Also:
- Constant Field Values
-
maxSelections
protected int maxSelections
-
oldSelection
protected int oldSelection
-
selectedIndexes
protected IntHashtable selectedIndexes
-
order
protected IntVector order
-
changed
public boolean changed
Internal use only.
-
clearValues
public IntVector clearValues
Fill this IntVector with the values that will be selected when the clear method is called.
-
showOrderInTip
public boolean showOrderInTip
Set to false to don't show the number of selected elements as they are clicked.- Since:
- TotalCross 1.3
-
unselectFirstWhenMaxIsReached
public boolean unselectFirstWhenMaxIsReached
Set to true if you want to unselect the first element once max is reached. Note that this implies that setOrderIsImportant(true) and also setMaxSelections were both called, otherwise it has no effects.
-
itemsText
public static java.lang.String itemsText
Global suffix used to display the number of items in a ComboBox. Defaults to " items".
-
localItemsText
public java.lang.String localItemsText
Local suffix to display the number of items in a ComboBox. Defaults to " items".
-
tipDelay
public int tipDelay
The amount of time used to show how many itens.
-
-
Method Detail
-
setOrderIsImportant
public void setOrderIsImportant(boolean set)
Call this method if you want to keep track of the order in which the items were selected. Note that this makes the listbox slower. Calling this method clears all selected items.
-
isOrderImportant
public boolean isOrderImportant()
Returns true if you requested that the order is important.
-
getSelectedIndex
public int getSelectedIndex()
Returns the selected index. If more than one item is selected, returns the last one.- Overrides:
getSelectedIndexin classListBox
-
getLastSelectedItem
public java.lang.Object getLastSelectedItem()
Returns the last selected item if you had set order is important, otherwise returns null.
-
setMaxSelections
public void setMaxSelections(int max)
Defines the maximum number of items that can be selected. If currently there are more selected than the allowed, all selections are cleared.
-
getSelectedIndexes
public IntVector getSelectedIndexes()
Return a vector with the indexes which have been selected. The elements of the Vector are the indexes in the Vector of the items. So if this Vector is holding [3, 12, 5] it means that the items 3, 5 and 12 have been selected. If order is important, then the order intvector is returned (caution: do not change the returned array!). Note that the indexes are not in order; to order them, callqsort.
-
isSelected
public boolean isSelected(int index)
Returns if given index is selected.
-
removeAll
public void removeAll()
Description copied from class:ListBoxEmpties this ListBox, setting all elements of the array tonullso they can be garbage collected. Attention! If you used the same object array to initialize two ListBoxes (or ComboBoxes), this method will null both ListBoxes (because they use the same array reference), and you'll get a null pointer exception!
-
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 classListBox
-
drawSelectedItem
protected void drawSelectedItem(Graphics g, int from, int to)
Draw all selected indexes- Overrides:
drawSelectedItemin classListBox
-
drawItems
protected void drawItems(Graphics g, int dx, int dy, int greatestVisibleItemIndex)
-
getCursorColor
protected int getCursorColor(int index)
- Overrides:
getCursorColorin classListBox
-
setSelectedIndex
public void setSelectedIndex(int index)
In this MultiListBox, inverts the status of the given index, or clears all if i is -1.- Overrides:
setSelectedIndexin classListBox- See Also:
setSelectedIndex(int, boolean)
-
leftReached
protected void leftReached()
- Overrides:
leftReachedin classListBox
-
setSelectedIndex
public void setSelectedIndex(int index, boolean set)Sets or clear an index. Can also be used to set or clear all indexes, passing -1 as the index. Both operations are limited by the defined max selections.- Overrides:
setSelectedIndexin classListBox
-
handleSelection
protected void handleSelection(int newSelection)
- Overrides:
handleSelectionin classListBox
-
cbddOnPopup
protected void cbddOnPopup()
Called by ComboBoxDropDown when its being popped.
-
cbddOnUnpop
protected void cbddOnUnpop()
Called by ComboBoxDropDown when its being unpopped. Sends a PRESSED event if a change was made in the selected indexes.
-
postPressedEvent
public void postPressedEvent()
Description copied from class:ControlPosts a ControlEvent.PRESSED event with this control as target.- Overrides:
postPressedEventin classControl
-
endSelection
protected void endSelection()
- Overrides:
endSelectionin classListBox
-
handleClick
protected void handleClick(int index)
-
getText
public java.lang.String getText()
Returns the String with the selected item (if single) or a string with the number of selected items. You can change the suffix itemsText or localItemsText to another one. If order is important, returns the last selected item.
-
onEvent
public void onEvent(Event e)
Description copied from class:ListBoxHandles the events for this control.
-
handleGeographicalFocusChangeKeys
public Control handleGeographicalFocusChangeKeys(KeyEvent ke)
Description copied from class:ControlUsed by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.- Overrides:
handleGeographicalFocusChangeKeysin classListBox- Parameters:
ke- The KeyEvent to be processed- Returns:
- The control that should get focus as a result of this KeyEvent. Null if this control did not handle the KeyEvent.
- See Also:
Settings.geographicalFocus
-
-