Package lejos.utility

Class TextMenu


  • public class TextMenu
    extends java.lang.Object
    Displays a list of items. The select() method allows the user to scroll the list using the right and left keys to scroll forward and backward through the list. The location of the list , and an optional title can be specified.
    Author:
    Roger Glassey Feb 20, 2007
    • Field Summary

      Fields 
      Modifier and Type Field Description
      protected int _height
      number of rows displayed; set by constructor, used by display()
      protected java.lang.String[] _items
      array of items to be displayed ;set by constructor, used by select();
      protected int _length
      effective length of items array - number of items before null
      protected boolean _quit
      boolean to cause select to quit
      protected int _startTime
      start time for select()
      protected java.lang.String _title
      optional menu title displayed immediately above the list of items
      protected int _topIndex
      index of the list item at the top of the list; set by constructor, used by select()
      protected int _topRow
      location of the top row of the list; set by constructor, used by display()
      protected static int BUTTON_POLL_INTERVAL
      protected TextLCD lcd  
      protected static char SEL_CHAR
      identifies the currently selected item
    • Constructor Summary

      Constructors 
      Constructor Description
      TextMenu​(java.lang.String[] items)
      This constructor sets location of the top row of the item list to row 0 of the display.
      TextMenu​(java.lang.String[] items, int topRow)
      This constructor allows specification location of the item list .
      TextMenu​(java.lang.String[] items, int topRow, java.lang.String title)
      This constuctor allows the specfication of a title (of up to 16 characters) and the location of the item list
      The title is displayed in the row above the item list.
    • Method Summary

      All Methods Instance Methods Concrete Methods 
      Modifier and Type Method Description
      protected void display​(int selectedIndex, int topIndex)
      helper method used by select()
      java.lang.String[] getItems()
      Returns list of items in this menu;
      void quit()
      method to call from another thread to quit the menu
      void resetTimeout()
      Reset the timeout period.
      int select()
      Allows the user to scroll through the items, using the right and left buttons (forward and back) The Enter key closes the menu
      and returns the index of the selected item.
      int select​(int selectedIndex)
      Version of select without timeout
      int select​(int selectedIndex, int timeout)
      Allows the user to scroll through the items, using the right and left buttons (forward and back) The Enter key closes the menu
      and returns the index of the selected item.
      void setItems​(java.lang.String[] items)
      set the array of items to be displayed
      void setTitle​(java.lang.String title)
      set menu title.
      • Methods inherited from class java.lang.Object

        clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
    • Field Detail

      • _topRow

        protected int _topRow
        location of the top row of the list; set by constructor, used by display()
      • _height

        protected int _height
        number of rows displayed; set by constructor, used by display()
      • _title

        protected java.lang.String _title
        optional menu title displayed immediately above the list of items
      • _items

        protected java.lang.String[] _items
        array of items to be displayed ;set by constructor, used by select();
      • _length

        protected int _length
        effective length of items array - number of items before null
      • _topIndex

        protected int _topIndex
        index of the list item at the top of the list; set by constructor, used by select()
      • SEL_CHAR

        protected static final char SEL_CHAR
        identifies the currently selected item
        See Also:
        Constant Field Values
      • _quit

        protected boolean _quit
        boolean to cause select to quit
      • _startTime

        protected int _startTime
        start time for select()
    • Constructor Detail

      • TextMenu

        public TextMenu​(java.lang.String[] items)
        This constructor sets location of the top row of the item list to row 0 of the display.
      • TextMenu

        public TextMenu​(java.lang.String[] items,
                        int topRow)
        This constructor allows specification location of the item list .
      • TextMenu

        public TextMenu​(java.lang.String[] items,
                        int topRow,
                        java.lang.String title)
        This constuctor allows the specfication of a title (of up to 16 characters) and the location of the item list
        The title is displayed in the row above the item list.
        Parameters:
        items - - string array containing the menu items. No items beyond the first null will be displayed.
    • Method Detail

      • setTitle

        public void setTitle​(java.lang.String title)
        set menu title.
        Parameters:
        title - the new title
      • setItems

        public void setItems​(java.lang.String[] items)
        set the array of items to be displayed
        Parameters:
        items -
      • select

        public int select()
        Allows the user to scroll through the items, using the right and left buttons (forward and back) The Enter key closes the menu
        and returns the index of the selected item.
        The menu display wraps items that scroll off the top will reappear on the bottom and vice versa. The selectedIndex is set to the first menu item.
        Returns:
        the index of the selected item
      • select

        public int select​(int selectedIndex)
        Version of select without timeout
      • select

        public int select​(int selectedIndex,
                          int timeout)
        Allows the user to scroll through the items, using the right and left buttons (forward and back) The Enter key closes the menu
        and returns the index of the selected item.
        The menu display wraps items that scroll off the top will reappear on the bottom and vice versa. This version of select allows the selected index to be set when the menu is first displayed.
        Parameters:
        selectedIndex - the index to start the menu on
        Returns:
        the index of the selected item
      • quit

        public void quit()
        method to call from another thread to quit the menu
      • display

        protected void display​(int selectedIndex,
                               int topIndex)
        helper method used by select()
      • getItems

        public java.lang.String[] getItems()
        Returns list of items in this menu;
        Returns:
        the array of item names
      • resetTimeout

        public void resetTimeout()
        Reset the timeout period.