All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class tea.set.Spinner

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Container
                   |
                   +----java.awt.Panel
                           |
                           +----tea.set.Spinner

public class Spinner
extends Panel
implements TextEdit
Spinner widget is a TextEdit with scrollable list. The type of the Spinner can either be a number, or a list of strings. If a numeric Spinner is used, the values are defined by a low and high integer range. Users can click on the up or down button to increment or decrement the value within the specified range. If a string list is used, users can click the up or down button to go the the next or previous string in the list. Editing can optionally be enabled. If editing is done in string list mode, when user hit return or tab key, the newly entered text is inserted to the list at current position. By default editable is set to false.

 Example:
 Spinner spinner = new Spinner("first|second|third|forth", "|");
 

Spinner supports the following properties:
Property NameProperty TypeDescription
Numericboolean (Readonly) True if Spinner is in numeric mode.
RangeLowint Lower bound of the numeric range.
RangeHighint Higher bound of the numeric range.
ItemsString[] (Readonly) Items list of the spinner.
Currentint The current value or index.
InsertModeboolean Text insert (overwrite) mode.
TextString Current text.
SelectedTextString (Readonly) Selected text string.
Editableboolean Editable flag.
SelectionStartint (Readonly) Starting index of select substring.
SelectionEndint (Readonly) Ending index of selected substring.
Columnsint (Readonly) Width in characters.
CursorPosint Cursor position.

Spinner generates the following events:
Event TypeEvent IDGenerated Description
ActionEventActionEvent.ACTION_PERFORMED Return or Tab key, or up/down spin button is pressed. ActionEvent.getActionCommand() contains the text.
TextEventTextEvent.TEXT_VALUE_CHANGED Text changed by user. Generated for every key stroke.

See Also:
ListText

Variable Index

 o eventMgr
EventMgr object handles added event processing and dispatching.

Constructor Index

 o Spinner()
Construct an empty item list spinner with border.
 o Spinner(int, int)
Construct a numeric spinner with allowable values in the range specified by low and high.
 o Spinner(int, int, boolean)
Construct a numeric spinner with allowable values in the range specified by low and high.
 o Spinner(String[])
Construct a list spinner using the strings in items.
 o Spinner(String[], boolean)
Construct a list spinner using the strings in items.

Method Index

 o add(String)
Add an item to the list.
 o addActionListener(ActionListener)
Add an action listener.
 o addTextListener(TextListener)
Add an text listener.
 o append(String)
Append text to the end.
 o clearSelection()
Clear selection.
 o getColumns()
Returns the number of columns in this TextEdit.
 o getCurrent()
If Spinner is in number mode, return the current value as integer.
 o getCursorPos()
Get cursor position.
 o getItems()
Get the item list of the spinner.
 o getRangeHigh()
Get the higher bound of the numeric range.
 o getRangeLow()
Get the lower bound of the numeric range.
 o getSelectedText()
Return selected (highlighted) text.
 o getSelectionEnd()
Get the end position of selection.
 o getSelectionStart()
Get the starting position of selection.
 o getText()
Get text value.
 o insert(String, int)
Insert text at the position.
 o isEditable()
Return true if editable (default).
 o isInsertMode()
Get the insertion mode flag.
 o isNumeric()
Get the mode of this spinner.
 o processActionEvent(ActionEvent)
Process and dispatch action event.
 o processEvent(AWTEvent)
Process and dispatch event.
 o processTextEvent(TextEvent)
Process and dispatch text event.
 o remove(int, int)
Remove text in the range.
 o remove(String)
Remove the specified item from the list.
 o removeActionListener(ActionListener)
Remove an action listener.
 o removeTextListener(TextListener)
Remove an text listener.
 o select(int, int)
Select the text in the range.
 o selectAll()
Select all text.
 o setColumns(int)
Sets the number of columns in this TextEdit.
 o setCurrent(int)
Set the current item to the item at specified index.
 o setCursorPos(int)
Set cursor at position.
 o setEditable(boolean)
Set editable to true of false.
 o setInsertMode(boolean)
Set insertion mode to true or false (overwrite).
 o setRange(int, int)
Set the range for the numeric spinner.
 o setRangeHigh(int)
Set the higher bound of the numeric range.
 o setRangeLow(int)
Set the higher bound of the numeric range.
 o setText(String)
Set the value of text.

Variables

 o eventMgr
 protected EventMgr eventMgr
EventMgr object handles added event processing and dispatching.

Constructors

 o Spinner
 public Spinner()
Construct an empty item list spinner with border.

 o Spinner
 public Spinner(int low,
                int high)
Construct a numeric spinner with allowable values in the range specified by low and high. The low value is shown initially. A border will be drawn around the text area by default.

Parameters:
low - lower bound of range.
high - higher bound of range.
 o Spinner
 public Spinner(int low,
                int high,
                boolean border)
Construct a numeric spinner with allowable values in the range specified by low and high. The low value is shown initially. If border is true, a 3D border will be drawn around the text area.

Parameters:
low - lower bound of range.
high - higher bound of range.
border - draw 3D border if true.
 o Spinner
 public Spinner(String items[])
Construct a list spinner using the strings in items. If Spinner is editable, user can enter new items by entering a new text value and hit return key. The first string in the list is shown initially. A border will be drawn around the text area by default.

Parameters:
items - items list for list spinner.
 o Spinner
 public Spinner(String items[],
                boolean border)
Construct a list spinner using the strings in items. If Spinner is editable, user can enter new items by entering a new text value and hit return key. The first string in the list is shown initially. If border is true, a 3D border will be drawn around the text area.

Parameters:
items - items list for list spinner.
border - draw 3D border if true.

Methods

 o getColumns
 public int getColumns()
Returns the number of columns in this TextEdit.

 o setColumns
 public void setColumns(int columns)
Sets the number of columns in this TextEdit.

Parameters:
columns - the number of columns
 o setRange
 public synchronized void setRange(int low,
                                   int high)
Set the range for the numeric spinner. The spinner will be changed to numeric and the low value will be shown. Spinner editable is set to false by this method.

Parameters:
low - lower bound of range.
high - higher bound of range.
 o isNumeric
 public boolean isNumeric()
Get the mode of this spinner.

Returns:
true if spinner is in numeric mode, false if the spinner is in list mode.
 o setRangeLow
 public void setRangeLow(int low)
Set the higher bound of the numeric range.

Parameters:
low - lower bound of the range.
 o getRangeLow
 public int getRangeLow()
Get the lower bound of the numeric range. If this spinner is not in numeric mode, -1 is returned.

Returns:
the lower bound of the numeric range.
 o setRangeHigh
 public void setRangeHigh(int high)
Set the higher bound of the numeric range.

Parameters:
high - higher bound of the range.
 o getRangeHigh
 public int getRangeHigh()
Get the higher bound of the numeric range. If this spinner is not in numeric mode, -1 is returned.

Returns:
the higher bound of the numeric range.
 o getItems
 public String[] getItems()
Get the item list of the spinner.

Returns:
the spinner item list.
 o add
 public synchronized void add(String item)
Add an item to the list. If the type of spinner is numeric, it will be changed to list. The new item is appended to the end of the list.

Parameters:
item - list item.
 o remove
 public synchronized void remove(String item)
Remove the specified item from the list. If the item removed is currently displayed, then display the previous item.

Parameters:
item - list item.
 o setCurrent
 public synchronized void setCurrent(int idx)
Set the current item to the item at specified index. If the Spinner is in number mode, the index must be in the range specified. Otherwise it must be less than the total number of items in the item list.

Parameters:
idx - current value if numeric spinner, or item index if list spinner.
 o getCurrent
 public int getCurrent()
If Spinner is in number mode, return the current value as integer. Otherwise, return the current index of the item inside the item list.

Returns:
current index or value.
 o setInsertMode
 public void setInsertMode(boolean mode)
Set insertion mode to true or false (overwrite).

Parameters:
mode - true for overwrite mode, false for insert mode.
 o isInsertMode
 public boolean isInsertMode()
Get the insertion mode flag.

Returns:
true if it is in insert mode.
 o setText
 public void setText(String t)
Set the value of text.

Parameters:
t - cell text.
 o getText
 public String getText()
Get text value.

Returns:
cell text.
 o getSelectedText
 public String getSelectedText()
Return selected (highlighted) text.

Returns:
selected text.
 o isEditable
 public boolean isEditable()
Return true if editable (default).

Returns:
true if cell is editable.
 o setEditable
 public void setEditable(boolean t)
Set editable to true of false.

Parameters:
t - cell editable flag.
 o getSelectionStart
 public int getSelectionStart()
Get the starting position of selection.

Returns:
starting position of selected text.
 o getSelectionEnd
 public int getSelectionEnd()
Get the end position of selection.

Returns:
ending position of selected text.
 o select
 public void select(int selStart,
                    int selEnd)
Select the text in the range.

Parameters:
selStart - starting position of selection.
selEnd - ending position of selection.
 o selectAll
 public void selectAll()
Select all text.

 o clearSelection
 public void clearSelection()
Clear selection.

 o append
 public void append(String str)
Append text to the end.

Parameters:
str - text to append to cell.
 o insert
 public void insert(String str,
                    int pos)
Insert text at the position.

Parameters:
str - text to insert.
pos - insertion position.
 o setCursorPos
 public void setCursorPos(int pos)
Set cursor at position.

Parameters:
pos - cursor position.
 o getCursorPos
 public int getCursorPos()
Get cursor position.

Returns:
cursor position.
 o remove
 public void remove(int start,
                    int end)
Remove text in the range.

Parameters:
start - starting position of text to remove.
end - ending position of text to remove.
 o addActionListener
 public void addActionListener(ActionListener listener)
Add an action listener.

Parameters:
listener - action listener.
 o removeActionListener
 public void removeActionListener(ActionListener listener)
Remove an action listener.

Parameters:
listener - action listener.
 o addTextListener
 public void addTextListener(TextListener listener)
Add an text listener.

Parameters:
listener - text listener.
 o removeTextListener
 public void removeTextListener(TextListener listener)
Remove an text listener.

Parameters:
listener - text listener.
 o processEvent
 public void processEvent(AWTEvent e)
Process and dispatch event.

Parameters:
e - event object.
Overrides:
processEvent in class Container
 o processActionEvent
 public void processActionEvent(ActionEvent e)
Process and dispatch action event.

Parameters:
e - action event.
 o processTextEvent
 public void processTextEvent(TextEvent e)
Process and dispatch text event.

Parameters:
e - text event.

All Packages  Class Hierarchy  This Package  Previous  Next  Index