|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
java.lang.Object
|
+--net.rim.device.api.ui.Field
|
+--net.rim.device.api.ui.component.ChoiceField
Base implementation of a choice field.
Behaviour
The field shows a label followed by the text of the currently selected
choice. When this field has the focus, the text of the currently selected
choice is shown inverted.
If the choice field is created with the Field#EDITABLE style (it is
by default), then the user may alter the currently selected choice when the
field has the focus. The selection wraps around, so when the end of the list
of choices is reached, selection is set to the other end.
Methods of selecting a choice
Pressing the space bar moves the selection to the next choice in the list.
You can use the trackwheel to change the selection by holding the ALT key
down while rolling. If Ui.getIncreaseDirection() is -1, then
ALT-rolling the trackwheel down should move through selections in an
increasing manner. If Ui.getIncreaseDirection() is +1, the ALT-rolling
the trackwheel up should move through selections in an increasing manner.
Character presses will jump to the first letter of the next item starting with the character, regardless of case.
Finally, the field adds a menu item added to change its selected value. When the use selects this menu item, a dialog appears allowing the user to employ the trackwheel to select a new value without holding the ALT key. Pressing ENTER or clicking dismisses this dialog and changes the choice. Pressing ESCAPE dismisses the dialog and cancels the change. Other keys will work as defined above.
| Field Summary | ||
static int |
CONTEXT_CHANGE_OPTION
Context hint for the event being triggered from a change option dialog dismissal. |
|
| Constructor Summary | ||
protected |
ChoiceField()
Constructs a new ChoiceField instance. |
|
protected |
ChoiceField(long style)
Constructs a new choice field instance with provided style. |
|
protected |
ChoiceField(String label,
int numChoices,
int index)
Constructs a new ChoiceField instance with provided label and number of choices, setting initially selected value. |
|
protected |
ChoiceField(String label,
int numChoices,
int index,
long style)
Constructs a new ChoiceField instance and sets initially selected value. |
|
| Method Summary | ||
abstract Object |
getChoice(int index)
Retrieves value for specified index. |
|
void |
getFocusRect(XYRect rect)
Retrieves this field's current focus region. |
|
protected int |
getHeightOfChoices()
Retrieves the maximum height required by any one of the choices in the field. |
|
String |
getLabel()
Retrieves this field's label. |
|
int |
getPreferredHeight()
Retrieves this field's preferred height. |
|
int |
getPreferredWidth()
Retrieves this field's preferred width. |
|
int |
getSelectedIndex()
Retrieves index of the currently selected choice. |
|
int |
getSize()
Retrieves number of choices in this field. |
|
protected int |
getWidthOfChoice(int index)
Retrieves the width of a particular choice. |
|
|
protected boolean |
invokeAction(int action)
Invokes an action on this field. |
protected boolean |
keyChar(char key,
int status,
int time)
Traps key events to seek to appropriate choice. |
|
protected boolean |
keyStatus(int keycode,
int time)
Handles key status events. |
|
protected void |
layout(int width,
int height)
Lays out this field's contents. |
|
protected void |
makeContextMenu(ContextMenu contextMenu)
Builds this field's context menu. |
|
protected int |
moveFocus(int amount,
int status,
int time)
Handles moving the focus within this field. |
|
protected void |
paint(Graphics graphics)
Redraws this field. |
|
void |
setLabel(String label)
Sets the label string for this field. |
|
void |
setSelectedIndex(int index)
Sets the currently chosen value. |
|
protected void |
setSelectedIndex(int index,
int context)
Sets the currently chosen value. |
|
void |
setSelectedIndex(Object object)
Selects first value that matches an object. |
|
protected void |
setSize(int size)
Sets the number of choices in this field. |
|
String |
toString()
Returns a string representation of the object. |
|
| Methods inherited from class java.lang.Object |
equals, getClass, hashCode, notify, notifyAll, wait, wait, wait |
| Field Detail |
public static final int CONTEXT_CHANGE_OPTION
| Constructor Detail |
protected ChoiceField(long style)
style - Field style for this field: can be a combation of any
generic field style, Field#FOCUSABLE and
Field#NON_FOCUSABLE.protected ChoiceField(String label, int numChoices, int index)
label - Label for this field.numChoices - Number of choices; if zero, then the index parameter is
set to zero regardless of its value.index - Index of the initially selected value.protected ChoiceField(String label, int numChoices, int index, long style)
label - Label for this field.numChoices - Number of choices; if zero, then the index parameter is
set to zero regardless of its value.index - Index of the initially selected value.| Method Detail |
public abstract Object getChoice(int index) throws IllegalArgumentException
Subclasses must implement this method to provide this functionality.
index - Index of choice for which to retrieve value.IllegalArgumentException - If index is out of bounds.public void getFocusRect(XYRect rect)
This method sets the focus region to the width of the selectable portion of this field (the part of the field containing the selectable value, not the label).
getFocusRect in class Fieldrect - To contain the local coordinates of the focus rect.protected int getHeightOfChoices()
public String getLabel()
public int getPreferredHeight()
Field.getPreferredHeight() for more information.getPreferredHeight in class Fieldpublic int getPreferredWidth()
Field.getPreferredWidth() for more information.
This field's manager invokes this method to assist in its layout.
getPreferredWidth in class Fieldpublic int getSelectedIndex()
For an empty ChoiceField, returns -1.
public int getSize()
protected int getWidthOfChoice(int index)
index - Index of the choice whose width should be returned.protected boolean invokeAction(int action)
Field.ACTION_INVOKE, which opens this field to have its value changed by the user.
If action is not a recognized action then this method does nothing and
returns false, indicating that the action was not consumed.
Note that if this field is not editable (ie. Field.isEditable() returns false)
then the action will not be consumed.
invokeAction in class Fieldaction - the action to be performed on this field.true if the action was consumed or false
if the action was not consumed.
protected boolean keyChar(char key,
int status,
int time)
This method handles and consumes a key generation event, only if this
field is EDITABLE; otherwise, it does nothing and
does not consume the event.
If the key generated was a SPACE character, this method moves the selection to the next choice in the list. If the previous selection was the last in the list, the selection wraps around to the first value in the list.
If the key generated was a letter key, this method moves the selection to the first subsequent value that begins with the generated letter. If there are no matches before the end of the list, the search wraps around. If there are no matches anywhere in the list, the selection does not move (but this method still consumes the key event).
If the selection does move, this field is invalidated to force a repaint.
key - Character generated by the event.status - State of the modifier keys (this parameter is ignored).time - Number of milliseconds since the device was turned on.
protected void layout(int width,
int height)
This field's manager invokes this method during the layout process to instruct this field to arrange its contents, given an amount of available space.
width - Amount of available horizontal space.height - Amount of available vertical space.protected void makeContextMenu(ContextMenu contextMenu)
Field.getContextMenu() invokes this method to construct this field's
context menu.
If the UI is not operating in MODE_ADVANCD mode (and
this field is Field.EDITABLE), this method builds this field's context
menu adding a menu item for changing this field's value.
makeContextMenu in class Field
FieldcontextMenu - Context menu to build.ContextMenu
protected int moveFocus(int amount,
int status,
int time)
FieldThis method is called by the framework only when the field already has focus.
By default, this method returns the amount parameter provided to it; custom fields must override this method to handle focus movement events.
Prior to invoking this method, the framework invokes
Field.focusRemove(). After invoking this method, the framework invokes
Field.focusAdd(boolean).
This method also clears this field's muddy state.
Fieldamount - Number of positions to move, positive means down, negative
means up.status - Modifier key status applied when the trackwheel
roll occurred (combination of applicable modifier keycode values from
KeypadListener).time - Number of milliseconds since the device was turned on.public void setLabel(String label)
label - Label string for this field.public void setSelectedIndex(int index)
index - Index of the selected value.IllegalArgumentException - If index parameter is out of bounds.
protected void setSelectedIndex(int index,
int context)
index - Index of the selected value.context - Information specifying the origin of the change.IllegalArgumentException - If index parameter is out of bounds.FieldChangeListenerpublic void setSelectedIndex(Object object)
Provide this method with an object, and it sets the selection on the
first value in this field's list (starting from the first item) that
matches this object (using Object.equals(java.lang.Object)). If a match is not
found, this method does not alter the current the selection.
object - Object to seek for.NullPointerException - If object parameter is null.protected void setSize(int size)
Invoking this method resets the number of choices in this field. It also resets the index of the initially chosen value to 0 (the first item in the list).
size - Number of choices for this field.setSelectedIndex(int)public String toString()
ObjecttoString method returns a string that
"textually represents" this object. The result should
be a concise but informative representation that is easy for a
person to read.
It is recommended that all subclasses override this method.
The toString method for class Object
returns a string consisting of the name of the class of which the
object is an instance, the at-sign character `@', and
the unsigned hexadecimal representation of the hash code of the
object. In other words, this method returns a string equal to the
value of:
getClass().getName() + '@' + Integer.toHexString(hashCode())
Object
|
|||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | ||||||||
| SUMMARY: INNER | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | ||||||||
Copyright 1999-2008 Research In Motion Limited. 295 Phillip Street, Waterloo, Ontario, Canada, N2L 3W8. All Rights Reserved.
Copyright 1993-2003 Sun Microsystems, Inc. 901 San Antonio Road, Palo Alto, California, 94303, U.S.A.
Copyright 2002-2003 Nokia Corporation All Rights Reserved.
Java is a trademark or registered trademark of Sun Microsystems, Inc. in the US and other countries.