de.enough.polish.ui
Class PredictiveAccess

java.lang.Object
  extended by de.enough.polish.ui.PredictiveAccess
All Implemented Interfaces:
TrieSetupCallback

public class PredictiveAccess
extends java.lang.Object
implements TrieSetupCallback


Field Summary
static javax.microedition.lcdui.Command ADD_WORD_CMD
          The command to start the dialog to add a custom word to the predictive dictionary
static int ARRAY
           
static javax.microedition.lcdui.Command DISABLE_PREDICTIVE_CMD
          The command for disabling the predictive input and returning to the standard input method
static javax.microedition.lcdui.Command ENABLE_PREDICTIVE_CMD
          The command for enabling the predictive input
static java.lang.String INDICATOR
          The indicator which is shown in the info box of a textfield indication the predictive mode is activated
static javax.microedition.lcdui.Command INSTALL_PREDICTIVE_CMD
          The command for starting the setup dialog of the predictive input
static int ORIENTATION_BOTTOM
           
static int ORIENTATION_TOP
           
static TrieProvider PROVIDER
          The provider for retrieving rms records, implemented as a static variable for use of a single provider in multiple textfields
static int TRIE
           
 
Constructor Summary
PredictiveAccess()
           
 
Method Summary
 void addWord(java.lang.String word)
           
 void animateChoices(long currentTime, ClippingRegion region)
           
 boolean commandAction(javax.microedition.lcdui.Command cmd, javax.microedition.lcdui.Displayable box)
           
 boolean commandAction(javax.microedition.lcdui.Command cmd, Item item)
           
 void disablePredictiveInput()
           
 void enablePredictiveInput()
           
 TextBuilder getBuilder()
           
 Container getChoicesContainer()
           
protected  int getChoicesX(int leftBorder, int rightBorder, int itemWidth)
          Returns the x offset for the choices list based on the currently active TextElement.
protected  int getChoicesY(int paddingVertical, int borderWidth)
          Retrieves the y offset for the choices list based on the currently active TextElement.
 java.lang.String getInfo()
           
 TextField getParent()
           
 int getPredictiveType()
           
 ArrayList getResults()
           
static int getSpaceKey()
          Returns the key code for the space key of the model running the application
 boolean handleKeyReleased(int keyCode, int gameAction)
          Handles the key-released event.
 void init(TextField parent)
          Initializes the predictive input for a textfield by creating objects for the choices container and setting the input mode
 void initPredictiveInput(java.lang.String[] allowedWords)
          Initializes the predictive input.
 boolean isOpen()
           
 boolean isPredictiveEnabled()
           
protected  boolean keyClear(int keyCode, int gameAction)
           
protected  boolean keyInsert(int keyCode, int gameAction)
           
protected  boolean keyMode(int keyCode, int gameAction)
           
protected  boolean keyNavigation(int keyCode, int gameAction)
           
 void paintChoices(int x, int y, int caretX, int caretY, int leftBorder, int rightBorder, javax.microedition.lcdui.Graphics g)
          Paints the choices
 void setAlert(Alert alert)
           
 void setBuilder(TextBuilder builder)
           
 void setChoicesContainer(Container choicesContainer)
           
 void setInfo(java.lang.String info)
           
 void setParent(TextField parent)
           
 void setPredictiveType(int predictiveType)
           
 void setupFinished(boolean finishedGraceful)
           
protected  void showWordNotFound()
           
 void synchronize()
          Synchronizes the TextBuilder object used for the predictive input by deleting all current entries of the builder, splitting the current text at spaces, inserting the resulting chunks as objects of TextElement to the builder and finally setting the caret position
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

ORIENTATION_BOTTOM

public static final int ORIENTATION_BOTTOM
See Also:
Constant Field Values

ORIENTATION_TOP

public static final int ORIENTATION_TOP
See Also:
Constant Field Values

TRIE

public static final int TRIE
See Also:
Constant Field Values

ARRAY

public static final int ARRAY
See Also:
Constant Field Values

PROVIDER

public static TrieProvider PROVIDER
The provider for retrieving rms records, implemented as a static variable for use of a single provider in multiple textfields


INSTALL_PREDICTIVE_CMD

public static javax.microedition.lcdui.Command INSTALL_PREDICTIVE_CMD
The command for starting the setup dialog of the predictive input


ENABLE_PREDICTIVE_CMD

public static javax.microedition.lcdui.Command ENABLE_PREDICTIVE_CMD
The command for enabling the predictive input


DISABLE_PREDICTIVE_CMD

public static javax.microedition.lcdui.Command DISABLE_PREDICTIVE_CMD
The command for disabling the predictive input and returning to the standard input method


ADD_WORD_CMD

public static javax.microedition.lcdui.Command ADD_WORD_CMD
The command to start the dialog to add a custom word to the predictive dictionary


INDICATOR

public static java.lang.String INDICATOR
The indicator which is shown in the info box of a textfield indication the predictive mode is activated

Constructor Detail

PredictiveAccess

public PredictiveAccess()
Method Detail

init

public void init(TextField parent)
Initializes the predictive input for a textfield by creating objects for the choices container and setting the input mode

Parameters:
parent - the textfield which likes to use the predictive input

initPredictiveInput

public void initPredictiveInput(java.lang.String[] allowedWords)
Initializes the predictive input. If words is not null, the predictive type ARRAY is set and the dictionary for this type is words. Otherwise, the method tries to read from the dictionary located in the RMS by calling PROVIDER.init(). Based on the outcome of this operation, commands are set for the parent textfield like INSTALL_PREDICTIVE_CMD if the dictionary is not installed. If the dictionary is already installed, the predictive input is activated and the commands DISABLE_PREDICTIVE_CMD and ADD_WORD_CMD is added to the textfield.

Parameters:
allowedWords - the words array

getSpaceKey

public static int getSpaceKey()
Returns the key code for the space key of the model running the application


disablePredictiveInput

public void disablePredictiveInput()

enablePredictiveInput

public void enablePredictiveInput()

synchronize

public void synchronize()
Synchronizes the TextBuilder object used for the predictive input by deleting all current entries of the builder, splitting the current text at spaces, inserting the resulting chunks as objects of TextElement to the builder and finally setting the caret position


getChoicesY

protected int getChoicesY(int paddingVertical,
                          int borderWidth)
Retrieves the y offset for the choices list based on the currently active TextElement.

Parameters:
paddingVertical - the vertical padding between the textfield lines
borderWidth - the width of the border of the textfield
Returns:
the y offset

getChoicesX

protected int getChoicesX(int leftBorder,
                          int rightBorder,
                          int itemWidth)
Returns the x offset for the choices list based on the currently active TextElement.

Parameters:
leftBorder - the width of the left border
rightBorder - the width of the right border
itemWidth - the width of the textfield
Returns:
the x offset

showWordNotFound

protected void showWordNotFound()

keyInsert

protected boolean keyInsert(int keyCode,
                            int gameAction)

keyClear

protected boolean keyClear(int keyCode,
                           int gameAction)

keyMode

protected boolean keyMode(int keyCode,
                          int gameAction)

keyNavigation

protected boolean keyNavigation(int keyCode,
                                int gameAction)

paintChoices

public void paintChoices(int x,
                         int y,
                         int caretX,
                         int caretY,
                         int leftBorder,
                         int rightBorder,
                         javax.microedition.lcdui.Graphics g)
Paints the choices

Parameters:
x - horizontal content start position of the textfield
y - vertical content start position of the text
caretX - the relative horizontal offset of the caret
caretY - the relative vertical offset of the caret
leftBorder - left border
rightBorder - right border
g - graphics context

animateChoices

public void animateChoices(long currentTime,
                           ClippingRegion region)

commandAction

public boolean commandAction(javax.microedition.lcdui.Command cmd,
                             javax.microedition.lcdui.Displayable box)

addWord

public void addWord(java.lang.String word)

commandAction

public boolean commandAction(javax.microedition.lcdui.Command cmd,
                             Item item)

getBuilder

public TextBuilder getBuilder()

setBuilder

public void setBuilder(TextBuilder builder)

getPredictiveType

public int getPredictiveType()

setPredictiveType

public void setPredictiveType(int predictiveType)

getChoicesContainer

public Container getChoicesContainer()

setChoicesContainer

public void setChoicesContainer(Container choicesContainer)

getResults

public ArrayList getResults()

handleKeyReleased

public boolean handleKeyReleased(int keyCode,
                                 int gameAction)
Handles the key-released event. Please note, that implementation should first try to handle the given key-code, before the game-action is processed.

Parameters:
keyCode - the code of the pressed key, e.g. Canvas.KEY_NUM2
gameAction - the corresponding game-action, e.g. Canvas.UP
Returns:
true when the key has been handled / recognized

setAlert

public void setAlert(Alert alert)

setInfo

public void setInfo(java.lang.String info)

getInfo

public java.lang.String getInfo()

setupFinished

public void setupFinished(boolean finishedGraceful)
Specified by:
setupFinished in interface TrieSetupCallback

getParent

public TextField getParent()

setParent

public void setParent(TextField parent)

isOpen

public boolean isOpen()

isPredictiveEnabled

public boolean isPredictiveEnabled()