Package totalcross.ui
Class SpinList
- java.lang.Object
-
- totalcross.ui.gfx.GfxSurface
-
- totalcross.ui.Control
-
- totalcross.ui.SpinList
-
public class SpinList extends Control
Creates a control with two arrows, so you can scroll values and show the current one. It supports auto-scroll (by clicking and holding) and can also dynamically compute the items based on ranges. The SpinList can be horizontal or vertical. You can use something like:SpinList sl = new SpinList(..., !Settings.fingerTouch);
This way, in finger-touch devices, it will use the horizontal appearance, which is easier to deal on such devices.
-
-
Nested Class Summary
-
Nested classes/interfaces inherited from class totalcross.ui.Control
Control.TranslucentShape
-
-
Field Summary
Fields Modifier and Type Field Description booleanallowsNoneSelectedAllows -1 as selected index (nothing selected).protected java.lang.String[]choicesintchoicesLenBy default, equals the choices' length.inthAlignThe horizontal text alignment of the SpinList: LEFT, CENTER or RIGHTprotected intselectedprotected TimerEventtimerinttimerInitialDelayNumber of ticks of the timer interval that will be waiten until the scroll starts.inttimerIntervalTimer interval in which the scroll will be done.booleanuseCalculatorBoxSet to true if there are only numbers in the SpinList and you want to open a NumericBox to let the user enter a value.booleanuseNumericBoxSet to true if there are only numbers in the SpinList and you want to open a NumericBox to let the user enter a value.booleanwrapAroundSet to false to disallow the wrap around that happens when the user is at the first or last items.-
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 SpinList(java.lang.String[] choices)Constructs a vertical SpinList with the given choices, selecting index 0 by default.SpinList(java.lang.String[] choices, boolean isVertical)Constructs a vertical SpinList with the given choices, selecting index 0 by default.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method Description voidclear()Clears this control, selecting element clearValueInt.static voidexpand(Vector v, java.lang.String str)Expands the items in the format "prefix [start,end] suffix", where prefix and suffix are optional.java.lang.String[]getChoices()Returns the choices array, after the expansion (if any).intgetPreferredHeight()Returns the preferred height of this control.intgetPreferredWidth()Returns the preferred width of this control.intgetSelectedIndex()Returns the selected index.java.lang.StringgetSelectedItem()Returns the selected item.ControlhandleGeographicalFocusChangeKeys(KeyEvent ke)Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.intindexOf(java.lang.String elem)Returns the index of the given item.voidinsertInOrder(java.lang.String elem)Inserts the given element in order (based in the assumption that the original choices was ordered).voidonEvent(Event event)Called to process key, pen, control and other posted events.voidonPaint(Graphics g)Called to draw the control.java.lang.StringremoveAt(int index)Removes the item at the given index.java.lang.StringremoveCurrent()Removes the current itemvoidreplaceChoices(java.lang.String[] choices)Just replaces the choices array.voidsetChoices(java.lang.String[] choices)Sets the choices to the given ones.voidsetSelectedIndex(int i)Sets the selected item; -1 is NOT accepted.voidsetSelectedIndex(int i, boolean sendPress)Sets the selected item; -1 is NOT accepted.voidsetSelectedItem(java.lang.String item)Selects the given item.voidsetSelectedItem(java.lang.String item, boolean sendPress)Selects the given item.-
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, hasFocus, internalSetEnabled, intXYWH, isActionEvent, isChildOf, isDisplayed, isEnabled, isFloating, isInsideOrNear, isObscured, isTopMost, isVisible, isVisibleAndInside, onBoundsChanged, onColorsChanged, 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, setEnabled, setFloating, setFocusLess, setFont, setForeColor, setNinePatch, setNinePatch, setRect, setRect, setRect, setRect, setSet, setTextShadowColor, setTranslucent, setVisible, showTip, takeInitialScreenShot, takeScreenShot, translateFromOrigin, uiStyleChanged, updateScreen, updateTemporary, willOpenKeyboard
-
-
-
-
Field Detail
-
choices
protected java.lang.String[] choices
-
selected
protected int selected
-
timer
protected TimerEvent timer
-
timerInterval
public int timerInterval
Timer interval in which the scroll will be done.
-
timerInitialDelay
public int timerInitialDelay
Number of ticks of the timer interval that will be waiten until the scroll starts.
-
hAlign
public int hAlign
The horizontal text alignment of the SpinList: LEFT, CENTER or RIGHT
-
useNumericBox
public boolean useNumericBox
Set to true if there are only numbers in the SpinList and you want to open a NumericBox to let the user enter a value. The SpinList is divided into 3 areas: left (decrease), right (increase), middle (opens the NumericBox). Works only when isVertical is false. The area that pops up the NumericBox is drawn in a darker background.- Since:
- TotalCross 1.5 Setting this to true shows a numeric box.
-
useCalculatorBox
public boolean useCalculatorBox
Set to true if there are only numbers in the SpinList and you want to open a NumericBox to let the user enter a value. The SpinList is divided into 3 areas: left (decrease), right (increase), middle (opens the NumericBox). Works only when isVertical is false. The area that pops up the NumericBox is drawn in a darker background. Setting this to true shows a calculator box.- Since:
- TotalCross 1.53
-
wrapAround
public boolean wrapAround
Set to false to disallow the wrap around that happens when the user is at the first or last items.- Since:
- TotalCross 2.0
-
choicesLen
public int choicesLen
By default, equals the choices' length. You can define its length and then create a single array shared by a set of SpinLists with different lengths on each SpinList.
-
allowsNoneSelected
public boolean allowsNoneSelected
Allows -1 as selected index (nothing selected).
-
-
Constructor Detail
-
SpinList
public SpinList(java.lang.String[] choices) throws InvalidNumberExceptionConstructs a vertical SpinList with the given choices, selecting index 0 by default.- Throws:
InvalidNumberException- See Also:
setChoices(java.lang.String[])
-
SpinList
public SpinList(java.lang.String[] choices, boolean isVertical) throws InvalidNumberExceptionConstructs a vertical SpinList with the given choices, selecting index 0 by default.- Throws:
InvalidNumberException- See Also:
setChoices(java.lang.String[])
-
-
Method Detail
-
getPreferredWidth
public int getPreferredWidth()
Description copied from class:ControlReturns the preferred width of this control.- Overrides:
getPreferredWidthin classControl
-
getPreferredHeight
public int getPreferredHeight()
Description copied from class:ControlReturns the preferred height of this control.- Overrides:
getPreferredHeightin classControl
-
setChoices
public void setChoices(java.lang.String[] choices) throws InvalidNumberExceptionSets the choices to the given ones. Searches for [i0,if] and then expands the items. For example, passing some string as "Day [1,31]" will expand that to an array of"Day 1","Day 2",...,"Day 31".- Throws:
InvalidNumberException
-
replaceChoices
public void replaceChoices(java.lang.String[] choices) throws InvalidNumberExceptionJust replaces the choices array.- Throws:
InvalidNumberException
-
expand
public static void expand(Vector v, java.lang.String str) throws InvalidNumberException
Expands the items in the format "prefix [start,end] suffix", where prefix and suffix are optional. For example, passing some string as "Day [1,31]" will expand that to an array of"Day 1","Day 2",...,"Day 31".- Throws:
InvalidNumberException
-
getChoices
public java.lang.String[] getChoices()
Returns the choices array, after the expansion (if any).
-
getSelectedItem
public java.lang.String getSelectedItem()
Returns the selected item.
-
getSelectedIndex
public int getSelectedIndex()
Returns the selected index.
-
setSelectedIndex
public void setSelectedIndex(int i)
Sets the selected item; -1 is NOT accepted.
-
setSelectedIndex
public void setSelectedIndex(int i, boolean sendPress)Sets the selected item; -1 is NOT accepted.
-
setSelectedItem
public void setSelectedItem(java.lang.String item)
Selects the given item. If the item is not found, the selected index remains unchanged.
-
setSelectedItem
public void setSelectedItem(java.lang.String item, boolean sendPress)Selects the given item. If the item is not found, the selected index remains unchanged.
-
removeAt
public java.lang.String removeAt(int index)
Removes the item at the given index.
-
removeCurrent
public java.lang.String removeCurrent()
Removes the current item
-
indexOf
public int indexOf(java.lang.String elem)
Returns the index of the given item.
-
insertInOrder
public void insertInOrder(java.lang.String elem)
Inserts the given element in order (based in the assumption that the original choices was ordered).
-
onPaint
public void onPaint(Graphics g)
Description copied from class:ControlCalled to draw the control. When this method is called, the graphics object passed has been translated into the coordinate system of the control and the area behind the control has already been painted.
-
onEvent
public void onEvent(Event event)
Description copied from class:ControlCalled to process key, pen, control and other posted events.
-
clear
public void clear()
Clears this control, selecting element clearValueInt.
-
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 classControl- 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
-
-