01: /*
02: *
03: *
04: * Copyright 1990-2007 Sun Microsystems, Inc. All Rights Reserved.
05: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
06: *
07: * This program is free software; you can redistribute it and/or
08: * modify it under the terms of the GNU General Public License version
09: * 2 only, as published by the Free Software Foundation.
10: *
11: * This program is distributed in the hope that it will be useful, but
12: * WITHOUT ANY WARRANTY; without even the implied warranty of
13: * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14: * General Public License version 2 for more details (a copy is
15: * included at /legal/license.txt).
16: *
17: * You should have received a copy of the GNU General Public License
18: * version 2 along with this work; if not, write to the Free Software
19: * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
20: * 02110-1301 USA
21: *
22: * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
23: * Clara, CA 95054 or visit www.sun.com if you need additional
24: * information or have any questions.
25: */
26: package com.sun.midp.chameleon.input;
27:
28: import javax.microedition.lcdui.Displayable;
29:
30: public class InputModeFactory {
31: public static final int KEYBOARD_INPUT_MODE = 1;
32: public static final int NUMERIC_INPUT_MODE = 2;
33: public static final int ALPHANUMERIC_INPUT_MODE = 3;
34: public static final int PREDICTIVE_TEXT_INPUT_MODE = 4;
35: public static final int SYMBOL_INPUT_MODE = 5;
36: public static final int NATIVE_INPUT_MODE_START = 100;
37:
38: public static native int[] getInputModeIds();
39:
40: protected static int[] inputModeIds = getInputModeIds();
41:
42: public static InputMode createInputMode(int id) {
43: if (id < NATIVE_INPUT_MODE_START) {
44: InputMode im;
45: switch (id) {
46: case KEYBOARD_INPUT_MODE:
47: im = new KeyboardInputMode();
48: break;
49: case NUMERIC_INPUT_MODE:
50: im = new NumericInputMode();
51: break;
52: case ALPHANUMERIC_INPUT_MODE:
53: im = new AlphaNumericInputMode();
54: break;
55: case PREDICTIVE_TEXT_INPUT_MODE:
56: im = new PredictiveTextInputMode();
57: break;
58: case SYMBOL_INPUT_MODE:
59: im = new SymbolInputMode();
60: break;
61: default:
62: throw new IllegalArgumentException(
63: "bad java input mode id: " + id);
64: }
65: return im;
66: } else {
67: NativeInputMode nim = new NativeInputMode();
68: if (0 != nim.initialize(id)) {
69: throw new IllegalArgumentException(
70: "bad native input mode id: " + id);
71: }
72: return nim;
73: }
74: }
75:
76: public static InputMode[] createInputModes() {
77: final int nModes = inputModeIds.length;
78: InputMode[] ims = new InputMode[nModes];
79: for (int i = 0; i < nModes; i++) {
80: ims[i] = createInputMode(inputModeIds[i]);
81: }
82: return ims;
83: }
84:
85: }
|