jMobileCore toolkit

com.jmobilecore.ui.core
Class TextFieldComposer

java.lang.Object
  extended by com.jmobilecore.ui.core.TextFieldComposer
All Implemented Interfaces:
AbstractComposer
Direct Known Subclasses:
TextBlockComposer

public class TextFieldComposer
extends java.lang.Object
implements AbstractComposer

The TextFieldComposer defines set of methods that supports a text caret's handling and basic text editing.

Author:
Greg Gridin

Field Summary
protected  int caretPosition
          Current caret position
protected  int curLen
          Current text length
protected  char[] text
          The text to edit
 
Constructor Summary
TextFieldComposer(int maxSize)
          Constructs new instance of TextFieldComposer.
 
Method Summary
 boolean addChar(char ch, boolean insertMode)
          Adds new symbol or replaces the current one
 boolean backspace()
          Deletes previous symbol, moves cursor one position left
 boolean caretLeft()
          Moves the caret one position left
 boolean caretRight()
          Moves the caret one position right
 boolean deleteChar()
          Deletes current symbol
 void destructor()
          Default destructor.
 int getCaretPosition()
          Returns the caret position
 char[] getChars()
          Returns the edited text
 int getCurrentLength()
          Returns the current text length
 int getCursorOffset(javax.microedition.lcdui.Font font, char echoChar)
          Returns the cursor offset (in pixels) for the composed string
 int getMaxSize()
          Get maximum lenght of the text which can be entered in TextFieldComposer
 java.lang.String getText()
          Returns the string that is presented by this text component.
 boolean setCaretPosition(int caretPosition)
          Sets the caret position
 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 java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

caretPosition

protected int caretPosition
Current caret position


curLen

protected int curLen
Current text length


text

protected char[] text
The text to edit

Constructor Detail

TextFieldComposer

public TextFieldComposer(int maxSize)
Constructs new instance of TextFieldComposer.

Parameters:
maxSize - max size of editable text
Method Detail

addChar

public boolean addChar(char ch,
                       boolean insertMode)
Adds new symbol or replaces the current one

Specified by:
addChar in interface AbstractComposer
Parameters:
ch - new symbol
insertMode - if true then new symbol will be added, otherwise the current symbol will be replaced
Returns:
true if the add/replace is possible, false otherwise

backspace

public boolean backspace()
Deletes previous symbol, moves cursor one position left

Specified by:
backspace in interface AbstractComposer
Returns:
true if the delete and moving is possible/done, false otherwise

caretLeft

public boolean caretLeft()
Moves the caret one position left

Specified by:
caretLeft in interface AbstractComposer
Returns:
true if the moving is possible/done, false otherwise

caretRight

public boolean caretRight()
Moves the caret one position right

Specified by:
caretRight in interface AbstractComposer
Returns:
true if the moving is possible/done, false otherwise

deleteChar

public boolean deleteChar()
Deletes current symbol

Specified by:
deleteChar in interface AbstractComposer
Returns:
true if the delete possible/done, false otherwise

destructor

public void destructor()
Default destructor. Helps VM to perform garbage collection

Specified by:
destructor in interface AbstractComposer

getCaretPosition

public int getCaretPosition()
Returns the caret position

Specified by:
getCaretPosition in interface AbstractComposer

getChars

public char[] getChars()
Returns the edited text

Specified by:
getChars in interface AbstractComposer

getCurrentLength

public int getCurrentLength()
Returns the current text length

Specified by:
getCurrentLength in interface AbstractComposer

getCursorOffset

public int getCursorOffset(javax.microedition.lcdui.Font font,
                           char echoChar)
Returns the cursor offset (in pixels) for the composed string

Parameters:
font - the current font.
echoChar - the echo character, not used if equal to 0

getMaxSize

public int getMaxSize()
Get maximum lenght of the text which can be entered in TextFieldComposer

Returns:
maxSize max length of the text

getText

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

Specified by:
getText in interface AbstractComposer

setCaretPosition

public boolean setCaretPosition(int caretPosition)
Sets the caret position

Specified by:
setCaretPosition in interface AbstractComposer
Parameters:
caretPosition - new caret position
Returns:
true if operation is successful, false otherwise

setText

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

Specified by:
setText in interface AbstractComposer
Parameters:
newText - the new text.

jMobileCore toolkit