Package totalcross.db.sqlite.ui
Class DBListBox
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.Container
-
- totalcross.ui.ListBox
-
- totalcross.db.sqlite.ui.DBListBox
-
- All Implemented Interfaces:
Scrollable
public class DBListBox extends ListBox
DBListBox is a simple implementation of a Listbox. You can use the up/down keys to scroll and enter the first letter of an item to select it.Note: the color used in the setBackground method will be used in the scrollbar only. The background color of the control will be a lighter version of the given color.
Note: this is a special version. It accepts a String matrix as the input, and does not allow add/remove/set of elements, since it reflects the database and must be filled again after some row is updated.
Here is an example showing how it can be used:
public class MyProgram extends totalcross.ui.MainWindow { DBListBox lb; public void initUI() { ResultSet rs = driver.executeQuery("select rowid,name from person where name > 20"); rs.first(); lb = new DBListBox(rs.getStrings(-1,true,false),1); // display column 1 add(lb,LEFT,TOP); } public void onEvent(totalcross.ui.event.Event event) { switch (event.type) { case totalcross.ui.event.ControlEvent.PRESSED: if (event.target == lb) String[] element = (String[])lb.getSelectedItem(); // in most cases, this is just a String and may be casted to such } } }The first item has index 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 protected java.lang.String[][]sitemsThe String items-
Fields inherited from class totalcross.ui.ListBox
autoResizeIcon, back0, back1, btnX, btnX0, customCursorColor, dataCol, DEFAULT_ITEM_HEIGHT_FACTOR, drawBorder, EXTRA_HEIGHT_FACTOR, extraHorizScrollButtonHeight, flick, iconGap, iconSize, ihFactor, ihtBackColors, ihtForeColors, itemCount, itemHeightFactor, items, offset, paddingBottom, paddingLeft, paddingRight, paddingTop, 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, borderRadius, children, controlFound, finishedStart, ignoreOnAddAgain, ignoreOnRemove, insets, lastH, lastScreenWidth, lastW, lastX, lastY, numChildren, started, tabOrder, tail, TRANSITION_TIME
-
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
-
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidadd(java.lang.Object item)REPLACES the current items with the given ones.voidadd(java.lang.Object[] items)REPLACES the current items with the given ones.voidadd(Control control)Does nothingprotected voiddrawItem(Graphics g, int index, int dx, int dy)You can extend ListBox and overide this method to draw the itemsprotected voidfind(char c)Does nothingintgetColumnCount()Returns the number of columns, if there are items.java.lang.ObjectgetItemAt(int i)Get the Object at the given Index.java.lang.Object[]getItems()Returns all items in this ListBox.protected java.lang.Object[]getItemsArray()Used internallyprotected intgetItemWidth(int index)Returns the width of the given item index with the current fontmetrics.intgetSelectedIndex()Returns the position of the selected item of the Listbox or -1 if the listbox has no selected index yet.java.lang.ObjectgetSelectedItem()Returns the selected item of the Listbox or null if none is selectedjava.lang.StringgetText()Returns the string of the selected item or "" if none is selected.intindexOf(java.lang.Object name, int col)Returns the index of the object at the given column.voidinsert(java.lang.Object item, int index)Does nothingvoidqsort()Sorts the elements of this ListBox.voidremove(int itemIndex)Does nothingvoidremove(java.lang.Object item)Does nothingvoidremove(Control control)Does nothingvoidremoveAll()Empties this ListBox, setting all elements of the array tonullso they can be garbage collected.voidsetDisplayCol(int displayCol)Sets the column of the String matrix that will be used to display the elements.voidsetItemAt(int i, java.lang.Object s)Does nothingvoidsetSelectedIndex(int i)Select an item and scroll to it if necessary.intsize()Returns the number of items-
Methods inherited from class totalcross.ui.ListBox
add, addWrapping, canScrollContent, clear, drawCursor, drawItems, drawSelectedItem, drawSelectedItem, enableHorizontalScroll, endSelection, flickEnded, flickStarted, getCursorColor, getEffectH, getEffectW, getEffectX, getEffectY, getFlick, getFocusableControls, getItemHeight, getPreferredHeight, getPreferredWidth, getScrollPosition, handleGeographicalFocusChangeKeys, handleSelection, hasIconItemLeft, hasIconItemRight, hideScrollBarIfNotNeeded, indexOf, leftReached, onBoundsChanged, onColorsChanged, onEvent, onPaint, qsort, scrollContent, selectLast, selectLast, setCursorColor, setEnabled, setSelectedIndex, setSelectedItem, setSelectedItemStartingWith, setSimpleBorder, setTextAreaClip, wasScrolled
-
Methods inherited from class totalcross.ui.Container
add, add, add, add, broadcastEvent, fillBackground, fillBackground, findChild, findNearestChild, findNextFocusControl, getBorderRadius, getBorderStyle, getChildren, getChildrenCount, getClientRect, getClientRect, getFirstChild, getInsets, incLastX, incLastY, initUI, isPressed, moveFocusToNextControl, moveFocusToNextEditable, onAddAgain, onRemove, onSwapFinished, paintChildren, resize, resizeHeight, resizeWidth, setBorderRadius, setBorderStyle, setFocusTraversable, setHighlighting, setInsets, 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, 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, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, 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
-
-
-
-
Method Detail
-
setDisplayCol
public void setDisplayCol(int displayCol)
Sets the column of the String matrix that will be used to display the elements.
-
getColumnCount
public int getColumnCount()
Returns the number of columns, if there are items.
-
add
public void add(java.lang.Object[] items)
REPLACES the current items with the given ones.
-
add
public void add(java.lang.Object item)
REPLACES the current items with the given ones.
-
insert
public void insert(java.lang.Object item, int index)Does nothing
-
removeAll
public void removeAll()
Empties 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 ('cos they use the same array reference), and you'll get a null pointer exception!
-
setItemAt
public void setItemAt(int i, java.lang.Object s)Does nothing
-
getItemAt
public java.lang.Object getItemAt(int i)
Get the Object at the given Index. Returns a String array, or null if i is out of range.
-
getSelectedItem
public java.lang.Object getSelectedItem()
Returns the selected item of the Listbox or null if none is selected- Overrides:
getSelectedItemin classListBox
-
getSelectedIndex
public int getSelectedIndex()
Returns the position of the selected item of the Listbox or -1 if the listbox has no selected index yet.- Overrides:
getSelectedIndexin classListBox
-
getItems
public java.lang.Object[] getItems()
Returns all items in this ListBox. The array can be casted to String[][].
-
getItemsArray
protected java.lang.Object[] getItemsArray()
Description copied from class:ListBoxUsed internally- Overrides:
getItemsArrayin classListBox
-
indexOf
public int indexOf(java.lang.Object name, int col)Returns the index of the object at the given column.
-
setSelectedIndex
public void setSelectedIndex(int i)
Select an item and scroll to it if necessary. Note: select must be called only after the control has been added to the container and its rect has been set.- Overrides:
setSelectedIndexin classListBox
-
drawItem
protected void drawItem(Graphics g, int index, int dx, int dy)
You can extend ListBox and overide this method to draw the items
-
getItemWidth
protected int getItemWidth(int index)
Returns the width of the given item index with the current fontmetrics. Note: if you overide this class you must implement this method.- Overrides:
getItemWidthin classListBox
-
qsort
public void qsort()
Sorts the elements of this ListBox. The current selection is cleared.
-
-