Package totalcross.ui

Class 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.
    • Field Detail

      • choices

        protected java.lang.String[] choices
      • selected

        protected int selected
      • 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).
    • Method Detail

      • getPreferredWidth

        public int getPreferredWidth()
        Description copied from class: Control
        Returns the preferred width of this control.
        Overrides:
        getPreferredWidth in class Control
      • getPreferredHeight

        public int getPreferredHeight()
        Description copied from class: Control
        Returns the preferred height of this control.
        Overrides:
        getPreferredHeight in class Control
      • setChoices

        public void setChoices​(java.lang.String[] choices)
                        throws InvalidNumberException
        Sets 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
      • 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: Control
        Called 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.
        Overrides:
        onPaint in class Control
        Parameters:
        g - the graphics object for drawing
        See Also:
        Graphics
      • onEvent

        public void onEvent​(Event event)
        Description copied from class: Control
        Called to process key, pen, control and other posted events.
        Overrides:
        onEvent in class Control
        Parameters:
        event - the event to process
        See Also:
        Event, KeyEvent, PenEvent
      • clear

        public void clear()
        Clears this control, selecting element clearValueInt.
        Overrides:
        clear in class Control
      • handleGeographicalFocusChangeKeys

        public Control handleGeographicalFocusChangeKeys​(KeyEvent ke)
        Description copied from class: Control
        Used by the main event loop to give the currently focused control an opportunity to act directly on the KeyEvent.
        Overrides:
        handleGeographicalFocusChangeKeys in class Control
        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