Source Code Cross Referenced for NumericInputMode.java in  » 6.0-JDK-Modules » j2me » com » sun » midp » chameleon » input » Java Source Code / Java DocumentationJava Source Code and Java Documentation

Java Source Code / Java Documentation
1. 6.0 JDK Core
2. 6.0 JDK Modules
3. 6.0 JDK Modules com.sun
4. 6.0 JDK Modules com.sun.java
5. 6.0 JDK Modules sun
6. 6.0 JDK Platform
7. Ajax
8. Apache Harmony Java SE
9. Aspect oriented
10. Authentication Authorization
11. Blogger System
12. Build
13. Byte Code
14. Cache
15. Chart
16. Chat
17. Code Analyzer
18. Collaboration
19. Content Management System
20. Database Client
21. Database DBMS
22. Database JDBC Connection Pool
23. Database ORM
24. Development
25. EJB Server geronimo
26. EJB Server GlassFish
27. EJB Server JBoss 4.2.1
28. EJB Server resin 3.1.5
29. ERP CRM Financial
30. ESB
31. Forum
32. GIS
33. Graphic Library
34. Groupware
35. HTML Parser
36. IDE
37. IDE Eclipse
38. IDE Netbeans
39. Installer
40. Internationalization Localization
41. Inversion of Control
42. Issue Tracking
43. J2EE
44. JBoss
45. JMS
46. JMX
47. Library
48. Mail Clients
49. Net
50. Parser
51. PDF
52. Portal
53. Profiler
54. Project Management
55. Report
56. RSS RDF
57. Rule Engine
58. Science
59. Scripting
60. Search Engine
61. Security
62. Sevlet Container
63. Source Control
64. Swing Library
65. Template Engine
66. Test Coverage
67. Testing
68. UML
69. Web Crawler
70. Web Framework
71. Web Mail
72. Web Server
73. Web Services
74. Web Services apache cxf 2.0.1
75. Web Services AXIS2
76. Wiki Engine
77. Workflow Engines
78. XML
79. XML UI
Java
Java Tutorial
Java Open Source
Jar File Download
Java Articles
Java Products
Java by API
Photoshop Tutorials
Maya Tutorials
Flash Tutorials
3ds-Max Tutorials
Illustrator Tutorials
GIMP Tutorials
C# / C Sharp
C# / CSharp Tutorial
C# / CSharp Open Source
ASP.Net
ASP.NET Tutorial
JavaScript DHTML
JavaScript Tutorial
JavaScript Reference
HTML / CSS
HTML CSS Reference
C / ANSI-C
C Tutorial
C++
C++ Tutorial
Ruby
PHP
Python
Python Tutorial
Python Open Source
SQL Server / T-SQL
SQL Server / T-SQL Tutorial
Oracle PL / SQL
Oracle PL/SQL Tutorial
PostgreSQL
SQL / MySQL
MySQL Tutorial
VB.Net
VB.Net Tutorial
Flash / Flex / ActionScript
VBA / Excel / Access / Word
XML
XML Tutorial
Microsoft Office PowerPoint 2007 Tutorial
Microsoft Office Excel 2007 Tutorial
Microsoft Office Word 2007 Tutorial
Java Source Code / Java Documentation » 6.0 JDK Modules » j2me » com.sun.midp.chameleon.input 
Source Cross Referenced  Class Diagram Java Document (Java Doc) 


001:        /*
002:         *
003:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
004:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
005:         * 
006:         * This program is free software; you can redistribute it and/or
007:         * modify it under the terms of the GNU General Public License version
008:         * 2 only, as published by the Free Software Foundation.
009:         * 
010:         * This program is distributed in the hope that it will be useful, but
011:         * WITHOUT ANY WARRANTY; without even the implied warranty of
012:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
013:         * General Public License version 2 for more details (a copy is
014:         * included at /legal/license.txt).
015:         * 
016:         * You should have received a copy of the GNU General Public License
017:         * version 2 along with this work; if not, write to the Free Software
018:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
019:         * 02110-1301 USA
020:         * 
021:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
022:         * Clara, CA 95054 or visit www.sun.com if you need additional
023:         * information or have any questions.
024:         */
025:        package com.sun.midp.chameleon.input;
026:
027:        import javax.microedition.lcdui.Canvas;
028:        import javax.microedition.lcdui.TextField;
029:        import com.sun.midp.i18n.Resource;
030:        import com.sun.midp.i18n.ResourceConstants;
031:        import com.sun.midp.log.Logging;
032:        import com.sun.midp.log.LogChannels;
033:
034:        /**
035:         * An InputMode instance which processes the numeric 0-9 keys
036:         * as their literal numeric values.
037:         */
038:        public class NumericInputMode extends BasicInputMode {
039:
040:            /**
041:             * The numeric key map.
042:             */
043:            protected char[][] numericKeyMap;
044:
045:            /**
046:             * The decimal key map.
047:             */
048:            protected char[][] decimalKeyMap;
049:
050:            /**
051:             * The phone numeric key map.
052:             */
053:            protected char[][] phoneNumericKeyMap;
054:
055:            /**
056:             * The any numeric key map.
057:             */
058:            protected char[][] anyKeyMap;
059:
060:            /** Default constructor. Init key maps for all constraints */
061:            public NumericInputMode() {
062:                String numericInLine = Resource
063:                        .getString(ResourceConstants.LCDUI_TF_NUMERIC_KEY_MAP);
064:                numericKeyMap = getMapByLine(numericInLine);
065:                String decimalInLine = Resource
066:                        .getString(ResourceConstants.LCDUI_TF_DECIMAL_KEY_MAP);
067:                decimalKeyMap = getMapByLine(decimalInLine);
068:                String phoneInLine = Resource
069:                        .getString(ResourceConstants.LCDUI_TF_PHONE_KEY_MAP);
070:                phoneNumericKeyMap = getMapByLine(phoneInLine);
071:                String anyInLine = Resource
072:                        .getString(ResourceConstants.LCDUI_TF_NUMERIC_ANY_KEY_MAP);
073:                anyKeyMap = getMapByLine(anyInLine);
074:            }
075:
076:            /**
077:             * This method is called to determine if this InputMode supports
078:             * the given text input constraints. The semantics of the constraints
079:             * value are defined in the javax.microedition.lcdui.TextField API. 
080:             * If this InputMode returns false, this InputMode must not be used
081:             * to process key input for the selected text component.
082:             *
083:             * @param constraints text input constraints. The semantics of the 
084:             * constraints value are defined in the TextField API.
085:             *
086:             * @return true if this InputMode supports the given text component
087:             *         constraints, as defined in the MIDP TextField API
088:             */
089:            public boolean supportsConstraints(int constraints) {
090:                // Numbers are allowed by any input constraints
091:                return true;
092:            }
093:
094:            /**
095:             * Returns the display name which will represent this InputMode to 
096:             * the user, such as in a selection list or the softbutton bar.
097:             *
098:             * @return the locale-appropriate name to represent this InputMode
099:             *         to the user
100:             */
101:            public String getName() {
102:                return Resource.getString(ResourceConstants.LCDUI_TF_NUMERIC);
103:            }
104:
105:            /**
106:             * Returns the command name which will represent this InputMode in
107:             * the input menu
108:             *
109:             * @return the locale-appropriate name to represent this InputMode
110:             *         to the user
111:             */
112:            public String getCommandName() {
113:                return getName();
114:            }
115:
116:            /**
117:             * Set the corresponding key map.
118:             *
119:             * @param constraints text input constraints. The semantics of the 
120:             * constraints value are defined in the TextField API.
121:             *
122:             * @param longPress return true if it's long key press otherwise false
123:             *
124:             * @return true if the key map has been changed otherwise false
125:             */
126:            protected boolean setKeyMap(int constraints, boolean longPress) {
127:                char[][] oldKeyMap = keyMap;
128:                if (constraints == TextField.PHONENUMBER) {
129:                    keyMap = phoneNumericKeyMap;
130:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
131:                        Logging.report(Logging.INFORMATION,
132:                                LogChannels.LC_HIGHUI,
133:                                "setting keymap to phone");
134:                    }
135:                } else if (constraints == TextField.DECIMAL) {
136:                    keyMap = decimalKeyMap;
137:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
138:                        Logging.report(Logging.INFORMATION,
139:                                LogChannels.LC_HIGHUI,
140:                                "setting keymap to decimalKeyMap");
141:                    }
142:                } else if (constraints == TextField.NUMERIC) {
143:                    keyMap = numericKeyMap;
144:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
145:                        Logging.report(Logging.INFORMATION,
146:                                LogChannels.LC_HIGHUI,
147:                                "setting keymap to numeric");
148:                    }
149:                } else {
150:                    keyMap = anyKeyMap;
151:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
152:                        Logging.report(Logging.INFORMATION,
153:                                LogChannels.LC_HIGHUI, "setting keymap to any");
154:                    }
155:                }
156:                return oldKeyMap != keyMap;
157:            }
158:
159:            /**
160:             * Gets the possible matches for the key code
161:             *
162:             * @param lastKey the key code
163:             *
164:             * @return returns the set of options. Return null if matches are not found.
165:             */
166:
167:            protected char[] getCharOptions(int lastKey) {
168:                char[] chars = null;
169:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
170:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
171:                            " getCharOptions lastKey=" + lastKey);
172:                }
173:
174:                switch (lastKey) {
175:                case Canvas.KEY_NUM0:
176:                    chars = keyMap[0];
177:                    break;
178:                case Canvas.KEY_NUM1:
179:                    chars = keyMap[1];
180:                    break;
181:                case Canvas.KEY_NUM2:
182:                    chars = keyMap[2];
183:                    break;
184:                case Canvas.KEY_NUM3:
185:                    chars = keyMap[3];
186:                    break;
187:                case Canvas.KEY_NUM4:
188:                    chars = keyMap[4];
189:                    break;
190:                case Canvas.KEY_NUM5:
191:                    chars = keyMap[5];
192:                    break;
193:                case Canvas.KEY_NUM6:
194:                    chars = keyMap[6];
195:                    break;
196:                case Canvas.KEY_NUM7:
197:                    chars = keyMap[7];
198:                    break;
199:                case Canvas.KEY_NUM8:
200:                    chars = keyMap[8];
201:                    break;
202:                case Canvas.KEY_NUM9:
203:                    chars = keyMap[9];
204:                    break;
205:                case Canvas.KEY_STAR:
206:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
207:                        Logging.report(Logging.INFORMATION,
208:                                LogChannels.LC_HIGHUI,
209:                                " getCharOptions got star");
210:                    }
211:                    chars = keyMap[10];
212:                    break;
213:                case Canvas.KEY_POUND:
214:                    chars = keyMap[11];
215:                    break;
216:
217:                default:
218:                    // This can actually happen if the Timer went off without
219:                    // a pending key, which can sometimes happen.
220:                    break;
221:                }
222:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
223:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
224:                            "getCharOptions returning:");
225:                }
226:                for (int i = 0; i < chars.length; i++) {
227:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
228:                        Logging.report(Logging.INFORMATION,
229:                                LogChannels.LC_HIGHUI, chars[i] + ",");
230:                    }
231:                }
232:                return chars;
233:            }
234:
235:            /** input subset x constraint map */
236:            private static final boolean[][] isMap = {
237:            // |ANY|EMAILADDR|NUMERIC|PHONENUMBER|URL|DECIMAL
238:                    { true, true, true, true, true, true }, // IS_FULLWIDTH_DIGITS
239:                    { false, false, true, true, false, true }, // IS_FULLWIDTH_LATIN
240:                    { false, false, true, true, false, true }, // IS_HALFWIDTH_KATAKANA 
241:                    { false, false, true, true, false, true }, // IS_HANJA              
242:                    { false, false, true, true, false, true }, // IS_KANJI              
243:                    { false, false, true, true, false, true }, // IS_LATIN              
244:                    { false, false, true, true, false, true }, // IS_LATIN_DIGITS       
245:                    { false, false, true, true, false, true }, // IS_SIMPLIFIED_HANZI 
246:                    { false, false, true, true, false, true }, // IS_TRADITIONAL_HANZI
247:                    { false, false, true, true, false, true }, // MIDP_UPPERCASE_LATIN
248:                    { false, false, true, true, false, true }, // MIDP_LOWERCASE_LATIN
249:                    { false, false, true, true, false, true } // NULL
250:            };
251:
252:            /**
253:             * Returns the map specifying this input mode is proper one for the
254:             * particular pair of input subset and constraint. The form of the map is
255:             *
256:             *                       |ANY|EMAILADDR|NUMERIC|PHONENUMBER|URL|DECIMAL|
257:             * ---------------------------------------------------------------------
258:             * IS_FULLWIDTH_DIGITS   |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
259:             * IS_FULLWIDTH_LATIN    |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
260:             * IS_HALFWIDTH_KATAKANA |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
261:             * IS_HANJA              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
262:             * IS_KANJI              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
263:             * IS_LATIN              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
264:             * IS_LATIN_DIGITS       |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
265:             * IS_SIMPLIFIED_HANZI   |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
266:             * IS_TRADITIONAL_HANZI  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
267:             * MIDP_UPPERCASE_LATIN  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
268:             * MIDP_LOWERCASE_LATIN  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
269:             * NULL                  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
270:             *
271:             * @return input subset x constraint map
272:             */
273:            public boolean[][] getIsConstraintsMap() {
274:                return isMap;
275:            }
276:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.