de.enough.polish.predictive
Class TextBuilder

java.lang.Object
  extended by de.enough.polish.predictive.TextBuilder
Direct Known Subclasses:
ArrayTextBuilder, TrieTextBuilder

public abstract class TextBuilder
extends Object


Field Summary
protected  int align
           
static int ALIGN_FOCUS
          Indicates that the caret should be shown to the right of current element and that results should be shown.
static int ALIGN_LEFT
          Indicates that the caret should be shown to the left of current element
static int ALIGN_RIGHT
          Indicates that the caret should be shown to the right of current element.
protected  int caret
           
protected  int element
           
static int JUMP_NEXT
          Indicates that the user pressed the UP button and wishes to jump to the previous line.
static int JUMP_PREV
          Indicates that the user pressed the DOWN button and wishes to jump to the next line.
protected  int mode
           
protected  StringBuffer text
           
protected  ArrayList textElements
           
 
Constructor Summary
TextBuilder(int textSize)
          Initializes the TextElement array, set the current element to -1, the align for the current element to ALIGN_LEFT and the current input mode to MODE_FIRST_UPPERCASE.
 
Method Summary
protected  void addElement(TextElement textElement)
          Adds an instance of TextElement to textElements in compliance with the current align.
abstract  void addReader(PredictiveReader reader)
          Creates a new TextElement carrying reader
abstract  void addString(String string)
          Creates a new TextElement carrying string
 void addWord(String string)
           
 void decreaseCaret()
          Decreases the caret position to set in getCaretPosition() by setting the corresponding align and element index
 boolean decreaseString()
           
abstract  boolean deleteCurrent()
          Deletes the current element
 int getAlign()
          Returns the align of the current TextElement.
 int getCaret()
          Returns the current caret position
 int getCaretPosition()
          Retrieves the field caret position by adding the string length of the elements preceding the current element.
 int getElementLine(String[] textLines)
          Retrieves the line the caret is positioned.
 int getElementLine(WrappedText textLines)
          Retrieves the line the caret is positioned.
 int getJumpPosition(int jumpDirection, String[] textLines)
          Retrieves the caret position if a the caret should be positioned in the previous or the next line
 int getJumpPosition(int jumpDirection, WrappedText textLines)
          Retrieves the caret position if a the caret should be positioned in the previous or the next line
 int getMode()
          Returns the current input mode
 PredictiveReader getReader()
          Returns the TrieReader carried in the current TextElement.
 String getString()
           
 StringBuffer getText()
          Constructs a string to display in the field by concating the string of the elements in textElements
 char getTextChar(int index)
          Returns the character at the given index
 TextElement getTextElement()
          Returns the current TextElement
 boolean hasText()
           
 void increaseCaret()
          Increases the caret position to set in getCaretPosition() by setting the corresponding align and element index
 boolean isString(int offset)
          Returns true, if the element at offset from the current element index is a character or a TrieReader
abstract  boolean keyClear()
           
 void keyNum(int keyCode, PredictiveReader reader)
           
 void keySpace()
           
 void setAlign(int currentAlign)
          Sets the align of the current TextElement
 void setCurrentElementNear(int position)
          Set the element next to caret position offset as the current element.
 void setMode(int mode)
          Sets the current input mode
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ALIGN_LEFT

public static final int ALIGN_LEFT
Indicates that the caret should be shown to the left of current element

See Also:
Constant Field Values

ALIGN_FOCUS

public static final int ALIGN_FOCUS
Indicates that the caret should be shown to the right of current element and that results should be shown. This value only applies to instances of TextElement carrying a TrieReader

See Also:
Constant Field Values

ALIGN_RIGHT

public static final int ALIGN_RIGHT
Indicates that the caret should be shown to the right of current element.

See Also:
Constant Field Values

JUMP_PREV

public static final int JUMP_PREV
Indicates that the user pressed the DOWN button and wishes to jump to the next line.

See Also:
Constant Field Values

JUMP_NEXT

public static final int JUMP_NEXT
Indicates that the user pressed the UP button and wishes to jump to the previous line.

See Also:
Constant Field Values

textElements

protected ArrayList textElements

element

protected int element

align

protected int align

mode

protected int mode

caret

protected int caret

text

protected StringBuffer text
Constructor Detail

TextBuilder

public TextBuilder(int textSize)
Initializes the TextElement array, set the current element to -1, the align for the current element to ALIGN_LEFT and the current input mode to MODE_FIRST_UPPERCASE.

Method Detail

keyNum

public void keyNum(int keyCode,
                   PredictiveReader reader)
            throws RecordStoreException
Throws:
RecordStoreException

keySpace

public void keySpace()

hasText

public boolean hasText()

keyClear

public abstract boolean keyClear()
                          throws RecordStoreException
Throws:
RecordStoreException

addWord

public void addWord(String string)

getReader

public PredictiveReader getReader()
Returns the TrieReader carried in the current TextElement. It must be checked previously via isChar() if the current element is a TrieReader

Returns:
the instance of TrieReader carried in the current TextElement

getString

public String getString()

getTextElement

public TextElement getTextElement()
Returns the current TextElement

Returns:
the current TextElement

getAlign

public int getAlign()
Returns the align of the current TextElement.

Returns:
the align of the current TextElement

setAlign

public void setAlign(int currentAlign)
Sets the align of the current TextElement

Parameters:
currentAlign - the align of the current TextElement

getCaret

public int getCaret()
Returns the current caret position

Returns:
the current caret position

addElement

protected void addElement(TextElement textElement)
Adds an instance of TextElement to textElements in compliance with the current align.

If the align is ALIGN_LEFT, the element is inserted at the current element position

If the align is ALIGN_FOCUS, the element is inserted behind the current element position

If the align is ALIGN_RIGHT, the element is inserted behind the current element position

The index of the current element is set eventually to the position the new element is inserted at.

Parameters:
textElement - the TextElement to add

getElementLine

public int getElementLine(WrappedText textLines)
Retrieves the line the caret is positioned.

Parameters:
textLines - the text lines of the field
Returns:
the index of the line

getJumpPosition

public int getJumpPosition(int jumpDirection,
                           WrappedText textLines)
Retrieves the caret position if a the caret should be positioned in the previous or the next line

Parameters:
jumpDirection - the direction of the caret jump
Returns:
the caret position

getElementLine

public int getElementLine(String[] textLines)
Retrieves the line the caret is positioned.

Parameters:
textLines - the text lines of the field
Returns:
the index of the line

getJumpPosition

public int getJumpPosition(int jumpDirection,
                           String[] textLines)
Retrieves the caret position if a the caret should be positioned in the previous or the next line

Parameters:
jumpDirection - the direction of the caret jump
Returns:
the caret position

setCurrentElementNear

public void setCurrentElementNear(int position)
Set the element next to caret position offset as the current element. If the position is closer to the start of the element the align for the current element is set to ALIGN_LEFT, otherwise to ALIGN_RIGHT

Parameters:
position - the caret position

addString

public abstract void addString(String string)
Creates a new TextElement carrying string

Parameters:
string - the string the TextElement should carry

addReader

public abstract void addReader(PredictiveReader reader)
Creates a new TextElement carrying reader

Parameters:
reader - the instance of TrieReader the TextElement should carry

deleteCurrent

public abstract boolean deleteCurrent()
Deletes the current element

Returns:
true, if an element was deleted, otherwise false

decreaseString

public boolean decreaseString()

increaseCaret

public void increaseCaret()
Increases the caret position to set in getCaretPosition() by setting the corresponding align and element index

If the current align is ALIGN_LEFT, the align is set to ALIGN_FOCUS (for TrieReader elements) or ALIGN_RIGHT (for characters)

If the current align is ALIGN_FOCUS or ALIGN_RIGHT and the element is not the last element in textElements, the align is set to ALIGN_LEFT and the current element index is incremented by 1.


decreaseCaret

public void decreaseCaret()
Decreases the caret position to set in getCaretPosition() by setting the corresponding align and element index

If the current align is ALIGN_LEFT and the current element is not the first element in textElements, the align is set to ALIGN_FOCUS (for TrieReader elements) or ALIGN_LEFT (for characters) and the current index gets decremented by 1.

If the current align is ALIGN_FOCUS, the align is set to ALIGN_LEFT.

If the current align is ALIGN_RIGHT or ALIGN_RIGHT and the element is not the last element in textElements, the align is set to ALIGN_FOCUS (for TrieReader elements) or ALIGN_LEFT (for characters)


isString

public boolean isString(int offset)
Returns true, if the element at offset from the current element index is a character or a TrieReader

Parameters:
offset - the offset for the element
Returns:
true, if the element is a character, otherwise false

getCaretPosition

public int getCaretPosition()
Retrieves the field caret position by adding the string length of the elements preceding the current element. If the current align is ALIGN_FOCUS or ALIGN_RIGHT, the caret position is incremented by the string length of the current element

Returns:
the field caret position

getText

public StringBuffer getText()
Constructs a string to display in the field by concating the string of the elements in textElements

Returns:
the constructed string

getTextChar

public char getTextChar(int index)
Returns the character at the given index

Parameters:
index - the index of the character to return
Returns:
the character at the given index

getMode

public int getMode()
Returns the current input mode

Returns:
the current input mode

setMode

public void setMode(int mode)
Sets the current input mode

Parameters:
mode - the input mode to set