jMobileCore toolkit

com.jmobilecore.ui.core
Class TextField

java.lang.Object
  extended by com.jmobilecore.ui.core.Component
      extended by com.jmobilecore.ui.core.TextComponent
          extended by com.jmobilecore.ui.core.TextField
Direct Known Subclasses:
BankCardField, CurrencyField, DateField, IPv4Field, PhoneNumberField, PostalCodeField, TimeField

public class TextField
extends TextComponent

A TextField object is a text component that allows for the editing of a single line of text.

Author:
Greg Gridin

Field Summary
 int adjustment
           
protected  int calculatedCaretPosition
           
protected  int calculatedCursorOffset
           
protected  AbstractComposer composer
          Handles input of the phone keys
protected  int currentLength
           
static int DEFAULT_SIZE
          Default text size
 char echoChar
          The echo character, which is used when the user wishes to disguise the characters typed into the text field.
protected static int HOFFSET
          The total horizontal gap for textfield text
protected static boolean SCROLLABLE
           
protected static int VOFFSET
          The total vertical gap for textfield text
 
Fields inherited from class com.jmobilecore.ui.core.TextComponent
ALL_SPEC_CHARS, BORDER_GAP, BORDER_WIDTH, C_ALL_SPEC_CHARS, C_ALPHA, C_ALPHA_NUMERIC, C_ANY, C_EMAIL, C_EMAIL_SPEC_CHARS, C_LOWER_CASE, C_NO_CHARS, C_NUMERIC, C_SPACE, C_UPPER_CASE, cHandler, CHAR_OPTIONS, charOptionCounter, constraint, CURSOR_DELAY, CURSOR_TYPE_LINE, CURSOR_TYPE_SYMBOL, editable, EMAIL_SPEC_CHARS, insertMode, KEY_OPTIONS, lastKeyCode, LC_CHARS, NUMERIC_CHARS, SPACE_CHARS, UC_CHARS, validChars
 
Fields inherited from class com.jmobilecore.ui.core.Component
alignment, background, CENTER, focusable, focusedBackground, focusedForeground, font, foreground, height, isCompletelyVisible, isFocused, isVisible, LEFT, parentScreen, RIGHT, screenY, valid, width
 
Constructor Summary
TextField()
          Constructs a new text field.
TextField(int maxTextLen)
          Constructs a new text field with the specified length.
TextField(int maxTextLen, int constr)
          Constructs a new text field with the specified length and constraints.
 
Method Summary
protected  void adjust(char[] text, int caretPosition, int cursorOffset)
          Adjusts the cursor position
 void destructor()
          Default destructor.
protected  AbstractComposer getComposer()
          Gets current input composer
 int getCursorOffset(char[] text, int caretPosition)
          Returns the cursor offset (in pixels) for the composed string
protected  char[] getFormattedText(boolean calcCursorOffset)
           
 java.lang.String getText()
          Returns the text that is presented by this text component.
protected  void init(int maxTextLen)
           
 boolean keyPressed(int keyCode)
          Responds to a key press.
 void paint(javax.microedition.lcdui.Graphics g)
          Paints the component
protected  void paintCursor(javax.microedition.lcdui.Graphics g, char[] text, int caretPosition, int cursorOffset, byte cursorType)
          Paints the cursor for this component
protected  void setHeight()
          Calculates the height of the component.
 void setText(java.lang.String newText)
          Sets the text that is presented by this text component to be the specified text.
 
Methods inherited from class com.jmobilecore.ui.core.TextComponent
addValidChars, getCaretPosition, getKeyOption, initCursor, isCharValid, preProcessKeyCode, processKeyCode, resetCursor, resetCursorHandler, setCaretPosition
 
Methods inherited from class com.jmobilecore.ui.core.Component
getBackground, getFont, getForeground, getHeight, getWidth, invalidate, isFocusOwner, keyReleased, keyRepeated, paintBackground, pointerDragged, pointerPressed, pointerReleased, prepareForeground, releaseFocus, requestFocus, setFont
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

adjustment

public int adjustment

calculatedCaretPosition

protected int calculatedCaretPosition

calculatedCursorOffset

protected int calculatedCursorOffset

composer

protected AbstractComposer composer
Handles input of the phone keys


currentLength

protected int currentLength

DEFAULT_SIZE

public static final int DEFAULT_SIZE
Default text size

See Also:
Constant Field Values

echoChar

public char echoChar
The echo character, which is used when the user wishes to disguise the characters typed into the text field. The disguises are removed if echoChar = 0.


HOFFSET

protected static final int HOFFSET
The total horizontal gap for textfield text

See Also:
Constant Field Values

SCROLLABLE

protected static final boolean SCROLLABLE
See Also:
Constant Field Values

VOFFSET

protected static final int VOFFSET
The total vertical gap for textfield text

See Also:
Constant Field Values
Constructor Detail

TextField

public TextField()
Constructs a new text field.


TextField

public TextField(int maxTextLen)
Constructs a new text field with the specified length.

Parameters:
maxTextLen - the maximum text length

TextField

public TextField(int maxTextLen,
                 int constr)
Constructs a new text field with the specified length and constraints.

Parameters:
maxTextLen - the maximum text length
constr - constraints binary mask
See Also:
TextComponent
Method Detail

adjust

protected void adjust(char[] text,
                      int caretPosition,
                      int cursorOffset)
Adjusts the cursor position


destructor

public void destructor()
Description copied from class: TextComponent
Default destructor. Helps VM to perform garbage collection

Overrides:
destructor in class TextComponent

getComposer

protected AbstractComposer getComposer()
Gets current input composer

Specified by:
getComposer in class TextComponent

getCursorOffset

public int getCursorOffset(char[] text,
                           int caretPosition)
Returns the cursor offset (in pixels) for the composed string


getFormattedText

protected char[] getFormattedText(boolean calcCursorOffset)

getText

public java.lang.String getText()
Returns the text that is presented by this text component.


init

protected void init(int maxTextLen)

keyPressed

public boolean keyPressed(int keyCode)
Responds to a key press.

If the key is a number key and the constraint is TextComponent.C_NUMERIC only, no timing interval is used, the number is immediately inserted into the field (if there is room). If the key is a number key and the constraint IS NOT ONLY TextComponent.C_NUMERIC, the timing interval begins so that characters may be cycled through via repeated presses of the same key within the timing interval.

Presses of the left and right sides of the 4-way navigation key move the cursor one character left or right within the field. Pressing the * key deletes the character to the left of the cursor. Pressing the # key inserts a space at the cursor position.

You can override this method if you want a custom component to perform additional filtering of key presses. For example, if you want a field that accepts only odd digits you could extend this class, ensure it is TextComponent.C_NUMERIC, then in this method check that the pressed key is an odd digit before passing it to the parent's keyPressed method.

Overrides:
keyPressed in class Component
Parameters:
keyCode - The code for the key that was pressed.
Returns:
true if the key was successfully processed, false otherwise

paint

public void paint(javax.microedition.lcdui.Graphics g)
Paints the component

Overrides:
paint in class Component
Parameters:
g - Graphics object

paintCursor

protected void paintCursor(javax.microedition.lcdui.Graphics g,
                           char[] text,
                           int caretPosition,
                           int cursorOffset,
                           byte cursorType)
Paints the cursor for this component

Parameters:
g - Graphics object

setHeight

protected void setHeight()
Calculates the height of the component.

Overrides:
setHeight in class Component

setText

public void setText(java.lang.String newText)
Sets the text that is presented by this text component to be the specified text.

Parameters:
newText - the new text.

jMobileCore toolkit