Package lejos.utility
Class TextMenu
- java.lang.Object
-
- lejos.utility.TextMenu
-
public class TextMenu extends java.lang.ObjectDisplays 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_heightnumber of rows displayed; set by constructor, used by display()protected java.lang.String[]_itemsarray of items to be displayed ;set by constructor, used by select();protected int_lengtheffective length of items array - number of items before nullprotected boolean_quitboolean to cause select to quitprotected int_startTimestart time for select()protected java.lang.String_titleoptional menu title displayed immediately above the list of itemsprotected int_topIndexindex of the list item at the top of the list; set by constructor, used by select()protected int_topRowlocation of the top row of the list; set by constructor, used by display()protected static intBUTTON_POLL_INTERVALTimout used forButton.waitForAnyPress(int)inselect(int, int).protected TextLCDlcdprotected static charSEL_CHARidentifies 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 voiddisplay(int selectedIndex, int topIndex)helper method used by select()java.lang.String[]getItems()Returns list of items in this menu;voidquit()method to call from another thread to quit the menuvoidresetTimeout()Reset the timeout period.intselect()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.intselect(int selectedIndex)Version of select without timeoutintselect(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.voidsetItems(java.lang.String[] items)set the array of items to be displayedvoidsetTitle(java.lang.String title)set menu title.
-
-
-
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()
-
BUTTON_POLL_INTERVAL
protected static final int BUTTON_POLL_INTERVAL
Timout used forButton.waitForAnyPress(int)inselect(int, int).- See Also:
- Constant Field Values
-
lcd
protected TextLCD lcd
-
-
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.
-
-