net.rim.device.api.ui.component
Class TextFieldBase

java.lang.Object
  |
  +--net.rim.device.api.ui.Field
        |
        +--net.rim.device.api.ui.component.TextFieldBase
All Implemented Interfaces:
IComponent, IInputLocationRequests, InputMethodListener, InputMethodRequests, ITextInputStyle

public abstract class TextFieldBase
extends Field
implements InputMethodRequests, ITextInputStyle

Provides fundamental text input functionality for components (via inheritance) and containers (via InputHelper class), delivering InputMethod services and AttributedString features.

Implements abstract lightweight text component behaviour, providing (1) input method event handling and (2) attributed text processing.

Unlike TextField class, TextFieldBase doesn't provide: Artic's text formatting, text content laying-out, painting and focus handling.

It is the base class for InputHelper class hierarchy. It was branched out from TextField class to be also the base class for TextField in the nearest future.

Since:
BlackBerry API 5.0.0

Field Summary
static long CONSUME_INPUT
          Determines whether or not this field should consume all input characters; if it would normally.
static long NO_NEWLINE
          Ignore newlines from user input or pasting.
 
Fields inherited from class net.rim.device.api.ui.Field
ACTION_INVOKE, EDITABLE, EDITABLE_MASK, FIELD_BOTTOM, FIELD_HALIGN_MASK, FIELD_HCENTER, FIELD_LEADING, FIELD_LEFT, FIELD_RIGHT, FIELD_TOP, FIELD_TRAILING, FIELD_VALIGN_MASK, FIELD_VCENTER, FOCUSABLE, FOCUSABLE_MASK, HIGHLIGHT_FOCUS, HIGHLIGHT_SELECT, NON_FOCUSABLE, NON_SPELLCHECKABLE, READONLY, SPELLCHECKABLE, SPELLCHECKABLE_MASK, STATUS_MOVE_FOCUS_HORIZONTALLY, STATUS_MOVE_FOCUS_VERTICALLY, USE_ALL_HEIGHT, USE_ALL_WIDTH, VISUAL_STATE_ACTIVE, VISUAL_STATE_DISABLED, VISUAL_STATE_DISABLED_FOCUS, VISUAL_STATE_FOCUS, VISUAL_STATE_NORMAL
 
Method Summary
 boolean backspace()
          Deletes character to the left of the cursor, or deletes selection.
 int backspace(int count)
          Deletes specified number of characters to the left of the cursor.
 int backspace(int count, int context)
          Deletes specified number of characters to the left of the cursor, with indication of source of this action.
 char charAt(int offset)
          Retrieves the character at the specified offset.
 void clear(int context)
          Clears this field's contents.
 void displayFieldFullMessage()
          Displays a 'field full' message.
 void fieldChangeNotify(int context)
          Invoked for this field when a change event occurs.
 int getCursorPosition()
          Retrieves character offset for current cursor position in this field.
 TextFilter getFilter()
          Gets the text filter set for this field.
 String getLabel()
          Retrieves this field's label.
 int getLabelLength()
          Retrieves the length of this field's label The length returned includes any additional character appended for layout purposes.
 int getMaxSize()
          Retrieves the maximum number of characters allowed for this field's value.
 String getText()
          Retrieves this field's text, not including the label.
 String getText(int offset, int length)
          Retrieves a portion of this field's text.
 void getText(int srcBegin, int srcEnd, char[] dst, int dstBegin)
          Retrieves this field's text.
 AbstractString getTextAbstractString()
          Retrieves read-only handle to the underlying buffer.
 int getTextLength()
          Retrieves length of this field's text, not including the label.
 int insert(String text)
          Inserts string programmatically into this field.
 int insert(String text, int context)
          Inserts string into this field.
 boolean isSelectable()
          Determines if this field supports selection of text.
 boolean isSelecting()
          Determines if this field is currently selecting text.
protected  boolean isSymbolScreenAllowed()
          Determines if this field supports use of the symbol screen.
 boolean keyChar(char key, int status, int time)
          Traps key generation events.
protected  boolean keyControl(char key, int status, int time)
          Handles control character generation events.
 boolean paste(Clipboard cb)
          Pastes text scrap into this field.
 void selectionCopy(Clipboard cb)
          Copies the current selection to the clipboard.
 void selectionDelete()
          Deletes character to the right of the cursor, or deletes selection.
 void setCursorPosition(int offset)
          Places cursor on specific character within this field, at user request.
protected  void setCursorPosition(int offset, int context)
          Places cursor on specific character within this field.
 void setFilter(TextFilter filter)
          Sets the text filter for this field.
 void setFont(Font font)
          Sets the font for this field and updates the display if necessary.
 void setLabel(String newLabel)
          Sets this field's label.
 void setMaxSize(int maxSize)
          Sets maximum number of characters allowed for this field's value.
 void setSelection(int aNewCursor, boolean aNewCursorLeadingEdge, int aNewAnchor)
          Set the selection.
 void setText(String text)
          Sets the text value for this field.
protected  void setText(String text, int context)
          Sets the text value for this field, with indication of the source of this action.
protected  void update(int aStart, int aLength, int aNewLength, int aCursorOffset, boolean aMoveCursor, boolean aIsInsertionOrDeletion)
          The update() method is called by the input framework when text or attributes change.
 void wipe()
          Overwrites this field's unused contents.
 
Methods inherited from class net.rim.device.api.ui.Field
drawFocus, drawHighlightRegion, focusAdd, focusRemove, getAccessibleContext, getBackground, getBackground, getBorder, getBorder, getBorder, getChangeListener, getContentHeight, getContentLeft, getContentRect, getContentRect, getContentTop, getContentWidth, getContextMenu, getCookie, getExtent, getExtent, getFieldStyle, getFocusListener, getFocusRect, getFont, getHeight, getIndex, getLeafFieldWithFocus, getLeft, getManager, getOriginal, getPreferredHeight, getPreferredWidth, getScreen, getStyle, getTop, getVisualState, getWidth, invalidate, invalidate, invalidateAll, invokeAction, isDataValid, isDirty, isEditable, isFocus, isFocusable, isMuddy, isPasteable, isSelectionCopyable, isSelectionCutable, isSelectionDeleteable, isSpellCheckable, isStyle, isVisible, keyDown, keyRepeat, keyStatus, keyUp, layout, makeContextMenu, moveFocus, moveFocus, navigationClick, navigationMovement, navigationUnclick, onDisplay, onExposed, onFocus, onMenuDismissed, onMenuDismissed, onObscured, onUndisplay, onUnfocus, onVisibilityChange, paint, select, selectionCut, setBackground, setBackground, setBorder, setBorder, setBorder, setBorder, setChangeListener, setCookie, setDirty, setEditable, setExtent, setFocus, setFocusListener, setMuddy, setNonSpellCheckable, setPosition, setVisualState, touchEvent, trackwheelClick, trackwheelUnclick, updateLayout
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail


CONSUME_INPUT

public static final long CONSUME_INPUT
Determines whether or not this field should consume all input characters; if it would normally.

Useful for fields that have Field.READONLY style set.

Modified value due to conflict with #JUMP_FOCUS_AT_END style.

Since:
BlackBerry API 5.0.0

NO_NEWLINE

public static final long NO_NEWLINE
Ignore newlines from user input or pasting.

Edit fields built with this style ignore newlines entered via cut and paste functionality and the keyboard. Labels can have newlines, but this field will strip newlines out of initial field values.

Since:
BlackBerry API 5.0.0
Method Detail

backspace

public boolean backspace()
Deletes character to the left of the cursor, or deletes selection.

If some characters are currently selected, this method deletes the selection as if it were a single character.

If no characters are selected, this method deletes the character immediately to the left of the cursor. If the cursor is currently on the first character in the field, this method does nothing.

Returns:
True if this method successfully removed a character or selection; otherwise, false.
Since:
BlackBerry API 5.0.0

backspace

public int backspace(int count)
Deletes specified number of characters to the left of the cursor.

This method ignores the current selection and deletes a number of characters to the left of the current cursor position. If this method runs into the beginning of this field's editable value, it deletes as many characters as possible.

Parameters:
count - Number of characters to delete.
Returns:
Number of characters actually deleted.
Since:
BlackBerry API 5.0.0

backspace

public int backspace(int count,
                     int context)
Deletes specified number of characters to the left of the cursor, with indication of source of this action.

This method ignores the current selection and deletes a number of characters to the left of the current cursor position. If this method runs into the beginning of this field's editable value, it deletes as many characters as possible.

You can specify whether this method was invoked programmatically, or as an event prompted by the user.

Parameters:
count - Number of characters to delete.
context - Information specifying the origin of the change.
Returns:
Number of characters actually deleted.
Since:
BlackBerry API 5.0.0

charAt

public char charAt(int offset)
Retrieves the character at the specified offset.

Index zero is the first character position after this field's label.

Parameters:
offset - Index of the character to retrieve.
Returns:
Character at your specified offset.
Throws:
IndexOutOfBoundsException - if offset is less than zero, or greater than or equal to the value returned from getTextLength().
Since:
BlackBerry API 5.0.0

clear

public void clear(int context)
Clears this field's contents.

Override this method if you want the default text to be non empty when the field is cleared. For example, a URLEditField might call setText("http://", context).

Parameters:
context - Context ID for this action.
Since:
BlackBerry API 5.0.0

displayFieldFullMessage

public void displayFieldFullMessage()
Displays a 'field full' message.
Since:
BlackBerry API 5.0.0

fieldChangeNotify

public void fieldChangeNotify(int context)
Invoked for this field when a change event occurs.

Custom fields should call this function when their state changes.

The dirty state is cleared if the change was programmatic, and is set (dirtied) if the change was user driven.

Overrides:
fieldChangeNotify in class Field
Parameters:
context - Information specifying the origin of the change.
Since:
BlackBerry API 5.0.0

getCursorPosition

public int getCursorPosition()
Retrieves character offset for current cursor position in this field.

This method does not include the label as part of its accounting (that is, a returned offset of zero means that the cursor is currently sitting on the first character in this field's value).

Returns:
Character position of current cursor position within this field's value.
Since:
BlackBerry API 5.0.0

getFilter

public TextFilter getFilter()
Gets the text filter set for this field.
Returns:
the text filter set for this field if exist otherwise return null;
Since:
BlackBerry API 5.0.0

getLabel

public String getLabel()
Retrieves this field's label.
Returns:
This field's label, or null if this field has no label.
Since:
BlackBerry API 5.0.0

getLabelLength

public int getLabelLength()
Retrieves the length of this field's label

The length returned includes any additional character appended for layout purposes. Therefore the value may not be the same as #getLabel().length()

Returns:
Length of this field's label string and any additional layout character.
Since:
BlackBerry API 5.0.0

getMaxSize

public int getMaxSize()
Retrieves the maximum number of characters allowed for this field's value.

This method does not include this field's label as part of its accounting.

Returns:
Maximum number of characters allowed in this edit field.
Since:
BlackBerry API 5.0.0

getText

public String getText()
Retrieves this field's text, not including the label.
Returns:
Text value contained in this field.
Since:
BlackBerry API 5.0.0

getText

public String getText(int offset,
                      int length)
Retrieves a portion of this field's text.

Provide a character offset and length to retrieve a substring of this field's contents.

Note: This method includes the label in the field's contents, so if you pass in an offset of zero, the first character returned is the first character of the label.

Note: Different system themes may modify the contents of the label.

Parameters:
offset - First character to return.
length - Number of characters to return.
Returns:
Substring of this field's contents.
Since:
BlackBerry API 5.0.0

getText

public void getText(int srcBegin,
                    int srcEnd,
                    char[] dst,
                    int dstBegin)
Retrieves this field's text.

Note: This method adjusts for the label in the field's contents, so the srcBegin and srcEnd parameters decribe the field's actual contents.

Parameters:
srcBegin - First character in source to retrieve.
srcEnd - Last character in source to retrieve.
dst - Character buffer to contain retrieved text.
dstBegin - Offset into buffer to receive the first retrieved character.
Since:
BlackBerry API 5.0.0

getTextAbstractString

public AbstractString getTextAbstractString()
Retrieves read-only handle to the underlying buffer.

Note: The underlying buffer can be modified by this field if methods such as insert(java.lang.String) or selectionDelete() are invoked.

Returns:
Underlying buffer for this field.
Since:
BlackBerry API 5.0.0

getTextLength

public int getTextLength()
Retrieves length of this field's text, not including the label.
Returns:
Number of characters in this field's text value.
Since:
BlackBerry API 5.0.0

insert

public int insert(String text)
Inserts string programmatically into this field.

This method attempts to insert your specified string string at the current cursor position. If this method (even partially) succeeds with the insertion, it then moves the cursor to just after the last character successfully inserted.

If the maximum size of the field is exceeded while inserting the string, as many characters as possible are inserted.

Note: use this method for programmatic changes to this field; be default, this method simply invokes insert(yourString, FieldChangeListener.PROGRAMMATIC).

Parameters:
text - String to insert.
Returns:
Number of characters successfully inserted.
Since:
BlackBerry API 5.0.0

insert

public int insert(String text,
                  int context)
Inserts string into this field.

This method attempts to insert your specified string string at the current cursor position. If this method (even partially) succeeds with the insertion, it then moves the cursor to just after the last character successfully inserted.

If the maximum size of the field is exceeded while inserting the string, as many characters as possible are inserted.

Parameters:
text - String to insert.
context - Information specifying the origin of the change. false indicates user-initiated insertion.
Returns:
Number of characters successfully inserted.
Since:
BlackBerry API 5.0.0

isSelectable

public boolean isSelectable()
Determines if this field supports selection of text.

This method returns true as long as this field contains at least one character.

Overrides:
isSelectable in class Field
Returns:
True if this field supports the selection of text; otherwise, false.
Since:
BlackBerry API 5.0.0

isSelecting

public final boolean isSelecting()
Determines if this field is currently selecting text.

Overrides:
isSelecting in class Field
Returns:
True if this field currently is in select mode (i.e. rolling the trackwheel expands or contracts the extent of the currently selected text).
Since:
BlackBerry API 5.0.0

isSymbolScreenAllowed

protected boolean isSymbolScreenAllowed()
Determines if this field supports use of the symbol screen.

Use this method to determine if this field supports the symbol screen (all edit fields do by default). The user can press ALT+SPACE to show the symbol screen.

Subclasses may override this method to return different values depending on if they want the symbol screen to be allowed.

The implementation in this class unconditionally returns true.

Returns:
true if this field supports the symbol screen; false if it does not.
Since:
BlackBerry API 5.0.0

keyChar

public boolean keyChar(char key,
                       int status,
                       int time)
Traps key generation events.

This method, invoked by this field's manager, handles all key generation events, except for the special symbol screen event (triggered with ALT+SPACE) which is handled by Field.keyDown(int, int).

This method consumes all key events, except in the following cases:

  • This field does not accept new lines (was built with NO_NEWLINE), and the ENTER key was pressed.
  • This field is not EDITABLE (exception: if in select mode, and the ENTER key was pressed).
  • The ESCAPE key was pressed.
  • This method attempted to insert a typed character into this field, and the insertion failed.
Overrides:
keyChar in class Field
Parameters:
key - Character generated by the event.
status - Modifier key status.
time - Number of milliseconds since the device was turned on.
Returns:
True if the event was consumed; otherwise, false.
Since:
BlackBerry API 5.0.0

keyControl

protected boolean keyControl(char key,
                             int status,
                             int time)
Handles control character generation events.

This field's manager invokes this method to send this field a control character event.

Overrides:
keyControl in class Field
Parameters:
key - Character generated.
status - Modifier key status. See KeypadListener.
time - Number of milliseconds since the device was turned on.
Returns:
True if this method consumed the event; otherwise, false.
Since:
BlackBerry API 5.0.0

paste

public boolean paste(Clipboard cb)
Pastes text scrap into this field.

If this field is EDITABLE, this method pastes the scrap currently on the clipboard after the current cursor position.

This method attempts to insert as many characters as it can into this field. If this field's capacity is reached before all characters are pasted, then only those that fit are pasted.

If this field currently has some text selected, this method replaces the selection with the scrap from the clipboard.

Overrides:
paste in class Field
Parameters:
cb - Clipboard object holding the text scrap.
Returns:
True if this field is editable; otherwise, false.
Since:
BlackBerry API 5.0.0

selectionCopy

public void selectionCopy(Clipboard cb)
Copies the current selection to the clipboard.

Note that this method always succeeds, even if zero characters are copied onto the clipboard. If at least one character exists in the selection to copy, then this method overwrites the clipboard's previous contents.

Overrides:
selectionCopy in class Field
Parameters:
cb - Clipboard to contain copied text.
Since:
BlackBerry API 5.0.0

selectionDelete

public void selectionDelete()
Deletes character to the right of the cursor, or deletes selection.

If some characters are currently selected, this method deletes the selection as if they were a single character.

If no characters are selected, this method deletes the character immediately to the right of the cursor. If the cursor is currently on the last character in the field, this method does nothing.

Overrides:
selectionDelete in class Field
Since:
BlackBerry API 5.0.0
See Also:
Field.isSelectionDeleteable(), Field.selectionCut(net.rim.device.api.system.Clipboard)

setCursorPosition

public void setCursorPosition(int offset)
Places cursor on specific character within this field, at user request.

This method does not include the label as part of its accounting (that is, an offset of zero represents the first character in this field's text value).

This method assumes the repositioning request was user-initiated.

Parameters:
offset - Character position to receive the cursor, counting from the first character in this field's value.
Since:
BlackBerry API 5.0.0

setCursorPosition

protected void setCursorPosition(int offset,
                                 int context)
Places cursor on specific character within this field.

This method does not include the label as part of its accounting (that is, an offset of zero represents the first character in this field's text value).

Parameters:
offset - Character position to receive the cursor, counting from the first character in this field's value.
context - Information specifying the origin of the change.
Since:
BlackBerry API 5.0.0

setFilter

public void setFilter(TextFilter filter)
Sets the text filter for this field.
Parameters:
filter - Text filter for this field.
Since:
BlackBerry API 5.0.0

setFont

public void setFont(Font font)
Sets the font for this field and updates the display if necessary.
Overrides:
setFont in class Field
Parameters:
font - New font for this field.
Since:
BlackBerry API 5.0.0

setLabel

public void setLabel(String newLabel)
Sets this field's label.
Parameters:
newLabel - New label for this field.
Since:
BlackBerry API 5.0.0

setMaxSize

public void setMaxSize(int maxSize)
Sets maximum number of characters allowed for this field's value.

If this field currently holds more than your provided number, this method truncates this field's contents to fit.

This method does not include the label in its accounting.

Parameters:
MaxSize - New maximum number of characters for this edit field's value.
Throws:
IllegalArgumentException - If maxNumChars is less than zero.
Since:
BlackBerry API 5.0.0

setSelection

public void setSelection(int aNewCursor,
                         boolean aNewCursorLeadingEdge,
                         int aNewAnchor)
Set the selection.
Parameters:
aNewCursor - New cursor position.
aNewCursorLeadingEdge - True if the cursor is at the leading edge of the character.
aNewAnchor - New anchor position.
Since:
BlackBerry API 5.0.0

setText

public void setText(String text)
             throws IllegalArgumentException
Sets the text value for this field. The current text in the field is REPLACED by text.
Parameters:
text - New string value for this field; if null, this method clears the field.
Throws:
IllegalArgumentException - If the text cannot be entered into an edit field.
Since:
BlackBerry API 5.0.0

setText

protected void setText(String text,
                       int context)
                throws IllegalArgumentException
Sets the text value for this field, with indication of the source of this action.
Parameters:
text - New string value for this field; if null, this method clears the field.
context - Information specifying the origin of the change.
Throws:
IllegalArgumentException - If the text cannot be entered into an edit field.
Since:
BlackBerry API 5.0.0

update

protected void update(int aStart,
                      int aLength,
                      int aNewLength,
                      int aCursorOffset,
                      boolean aMoveCursor,
                      boolean aIsInsertionOrDeletion)
The update() method is called by the input framework when text or attributes change. The update() method can be overridden in derived classes to format and layout the new text.

Text starting at aStart, of length aLength, has just been replaced by text of aNewLength.

Parameters:
aStart - A position in the text where the update starts.
aLength - Length of the text chunk has been updated.
aNewLength - Length of the new text chunk that replaced old text chunk.
aCursorOffset - indicates cursor offset from aStart (may be non-zero in composed text).
aMoveCursor - if true, cursor and anchor are moved accordingly
aIsInsertionOrDeletion - if true, insertion or deletion of text occurred, as the opposite to attribute change
Since:
BlackBerry API 5.0.0

wipe

public void wipe()
Overwrites this field's unused contents.
Since:
BlackBerry API 5.0.0



Copyright 1999-2009 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.