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

AlphaNumericInputMode

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

Fields Summary
private static char[]
upperKeyMap
set of chars for alpha upper-case input
private static char[]
lowerKeyMap
set of chars for alpha low-case input
private static char[]
longPressKeyMap
set of chars for long key press
protected static final int[]
CAPS_MODES
array of sub-inputModes supported by this inputMode
private static final String[]
CAPS_MODES_LABELS
array of sub-inputModes labels, corresponding to CAPS_MODES array
private static char[]
keyMaps
the possible key maps for this input mode
protected int
capsModePointer
points to an element of CAPS_MODES which is the current sub-inputMode
private static final boolean[]
isMap
input subset x constraint map
Constructors Summary
public AlphaNumericInputMode()
Default constructor. Init key maps for all constraints



             
      
        String upperInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_CAPS_ALPHA_KEY_MAP);
        upperKeyMap = getMapByLine(upperInLine);
        String lowerInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_ALPHA_KEY_MAP);
        lowerKeyMap = getMapByLine(lowerInLine);
        String longInLine = Resource.getString(
                             ResourceConstants.LCDUI_TF_ALPHA_DIGIT_KEY_MAP);
        longPressKeyMap = getMapByLine(longInLine);

        keyMaps = new char[3][][];
        keyMaps[0] = upperKeyMap;
        keyMaps[1] = lowerKeyMap;
        keyMaps[2] = upperKeyMap;
    
Methods Summary
protected booleancommitPendingChar()
This method is used to immediately commit the pending character because a new character is now pending.

return
true if char has been committed otherwise false

        boolean committed = super.commitPendingChar();
        if (committed) {
            if (CAPS_MODES[capsModePointer] == CAPS_SENTENCE) {
                nextCapsMode();
            }
        }
        return committed;
    
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;
    
        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_POUND:
            chars = keyMap[10];
            break;
        case Canvas.KEY_STAR:
            nextCapsMode();
            break;
                
        default:
            // This can actually happen if the Timer went off without
            // a pending key, which can sometimes happen.
            break;

        }
       
        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 CAPS_MODES_LABELS[capsModePointer];
    
protected voidnextCapsMode()
Set the next capital mode for this input method

        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
            Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
                "[A.nextCapsMode]");
        }
        capsModePointer++;
        if (capsModePointer == CAPS_MODES.length) {
            capsModePointer = 0;
        }
        if (CAPS_MODES[capsModePointer] == CAPS_OFF) {
            keyMap = lowerKeyMap;
        } else {
            keyMap = upperKeyMap;
        }

        mediator.subInputModeChanged();
    
protected voidsetInputSubset(java.lang.String inputSubset)
Notify about current input subset

param
inputSubset current input subset

        int mode = -1;
        if ("MIDP_UPPERCASE_LATIN".equals(inputSubset)) {
            mode = CAPS_ON;
        } else if ("MIDP_LOWERCASE_LATIN".equals(inputSubset)) {
            mode = CAPS_OFF;
        }
        for (int i = CAPS_MODES.length - 1; i >= 0; i--) {
            if (CAPS_MODES[i] == mode) {
                capsModePointer = i;
                break;
            }
        }
    
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;
            
        keyMap = longPress ?
            longPressKeyMap: 
        keyMaps[capsModePointer];
        
        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

        switch (constraints & TextField.CONSTRAINT_MASK) {
            case TextField.NUMERIC:
            case TextField.DECIMAL:
            case TextField.PHONENUMBER:
                return false;
            default:
                return true;
        }