FileDocCategorySizeDatePackage
NumericInputMode.javaAPI DocphoneME MR2 API (J2ME)10620Wed May 02 18:00:20 BST 2007com.sun.midp.chameleon.input

NumericInputMode

public class NumericInputMode extends BasicInputMode
An InputMode instance which processes the numeric 0-9 keys as their literal numeric values.

Fields Summary
protected char[]
numericKeyMap
The numeric key map.
protected char[]
decimalKeyMap
The decimal key map.
protected char[]
phoneNumericKeyMap
The phone numeric key map.
protected char[]
anyKeyMap
The any numeric key map.
private static final boolean[]
isMap
input subset x constraint map
Constructors Summary
public NumericInputMode()
Default constructor. Init key maps for all constraints

        String numericInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_NUMERIC_KEY_MAP);
        numericKeyMap = getMapByLine(numericInLine);
        String decimalInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_DECIMAL_KEY_MAP);
        decimalKeyMap = getMapByLine(decimalInLine);
        String phoneInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_PHONE_KEY_MAP);
        phoneNumericKeyMap = getMapByLine(phoneInLine);
        String anyInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_NUMERIC_ANY_KEY_MAP);
        anyKeyMap = getMapByLine(anyInLine);
    
Methods Summary
protected char[]getCharOptions(int lastKey)
Gets the possible matches for the key code

param
lastKey the key code
return
returns the set of options. Return null if matches are not found.

        char[] chars = null;
        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                " getCharOptions lastKey=" + lastKey);
        }

        switch (lastKey) {
            case Canvas.KEY_NUM0:
                chars = keyMap[0];
                break;
            case Canvas.KEY_NUM1:
                chars = keyMap[1];
                break;
            case Canvas.KEY_NUM2:
                chars = keyMap[2];
                break;
            case Canvas.KEY_NUM3:
                chars = keyMap[3];
                break;
            case Canvas.KEY_NUM4:
                chars = keyMap[4];
                break;
            case Canvas.KEY_NUM5:
                chars = keyMap[5];
                break;
            case Canvas.KEY_NUM6:
                chars = keyMap[6];
                break;
            case Canvas.KEY_NUM7:
                chars = keyMap[7];
                break;
            case Canvas.KEY_NUM8:
                chars = keyMap[8];
                break;
            case Canvas.KEY_NUM9:
                chars = keyMap[9];
                break;
            case Canvas.KEY_STAR:
                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                        " getCharOptions got star");
                }
                chars = keyMap[10];
                break;
            case Canvas.KEY_POUND:
                chars = keyMap[11];
                break;

            default:
                // This can actually happen if the Timer went off without
                // a pending key, which can sometimes happen.
                break;
        }
        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                "getCharOptions returning:");
        }
        for (int i = 0; i < chars.length; i++) {
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                    chars[i] + ",");
            }
        }
        return chars;
    
public java.lang.StringgetCommandName()
Returns the command name which will represent this InputMode in the input menu

return
the locale-appropriate name to represent this InputMode to the user

        return getName();
    
public boolean[][]getIsConstraintsMap()
Returns the map specifying this input mode is proper one for the particular pair of input subset and constraint. The form of the map is |ANY|EMAILADDR|NUMERIC|PHONENUMBER|URL|DECIMAL| --------------------------------------------------------------------- IS_FULLWIDTH_DIGITS |t|f| t|f | t|f | t|f |t|f| t|f | IS_FULLWIDTH_LATIN |t|f| t|f | t|f | t|f |t|f| t|f | IS_HALFWIDTH_KATAKANA |t|f| t|f | t|f | t|f |t|f| t|f | IS_HANJA |t|f| t|f | t|f | t|f |t|f| t|f | IS_KANJI |t|f| t|f | t|f | t|f |t|f| t|f | IS_LATIN |t|f| t|f | t|f | t|f |t|f| t|f | IS_LATIN_DIGITS |t|f| t|f | t|f | t|f |t|f| t|f | IS_SIMPLIFIED_HANZI |t|f| t|f | t|f | t|f |t|f| t|f | IS_TRADITIONAL_HANZI |t|f| t|f | t|f | t|f |t|f| t|f | MIDP_UPPERCASE_LATIN |t|f| t|f | t|f | t|f |t|f| t|f | MIDP_LOWERCASE_LATIN |t|f| t|f | t|f | t|f |t|f| t|f | NULL |t|f| t|f | t|f | t|f |t|f| t|f |

return
input subset x constraint map

    
                                                                                                                                                                                                                                                                                                                                                                                                                                        
       
        return isMap;
    
public java.lang.StringgetName()
Returns the display name which will represent this InputMode to the user, such as in a selection list or the softbutton bar.

return
the locale-appropriate name to represent this InputMode to the user

        return Resource.getString(ResourceConstants.LCDUI_TF_NUMERIC);
    
protected booleansetKeyMap(int constraints, boolean longPress)
Set the corresponding key map.

param
constraints text input constraints. The semantics of the constraints value are defined in the TextField API.
param
longPress return true if it's long key press otherwise false
return
true if the key map has been changed otherwise false

        char[][] oldKeyMap = keyMap;
        if (constraints == TextField.PHONENUMBER) {
            keyMap = phoneNumericKeyMap;
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                    "setting keymap to phone");
            }
        } else if (constraints == TextField.DECIMAL) {
            keyMap = decimalKeyMap;
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                    "setting keymap to decimalKeyMap");
            }
        } else if (constraints == TextField.NUMERIC) {
            keyMap = numericKeyMap;
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                    "setting keymap to numeric");
            }
        } else {
            keyMap = anyKeyMap;
            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
                Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                    "setting keymap to any");
            }
        }
        return oldKeyMap != keyMap;
    
public booleansupportsConstraints(int constraints)
This method is called to determine if this InputMode supports the given text input constraints. The semantics of the constraints value are defined in the javax.microedition.lcdui.TextField API. If this InputMode returns false, this InputMode must not be used to process key input for the selected text component.

param
constraints text input constraints. The semantics of the constraints value are defined in the TextField API.
return
true if this InputMode supports the given text component constraints, as defined in the MIDP TextField API

	// Numbers are allowed by any input constraints
	return true;