Source Code Cross Referenced for PredictiveTextInputMode.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:         *
004:         * Copyright  1990-2007 Sun Microsystems, Inc. All Rights Reserved.
005:         * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS FILE HEADER
006:         * 
007:         * This program is free software; you can redistribute it and/or
008:         * modify it under the terms of the GNU General Public License version
009:         * 2 only, as published by the Free Software Foundation.
010:         * 
011:         * This program is distributed in the hope that it will be useful, but
012:         * WITHOUT ANY WARRANTY; without even the implied warranty of
013:         * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
014:         * General Public License version 2 for more details (a copy is
015:         * included at /legal/license.txt).
016:         * 
017:         * You should have received a copy of the GNU General Public License
018:         * version 2 along with this work; if not, write to the Free Software
019:         * Foundation, Inc., 51 Franklin St, Fifth Floor, Boston, MA
020:         * 02110-1301 USA
021:         * 
022:         * Please contact Sun Microsystems, Inc., 4150 Network Circle, Santa
023:         * Clara, CA 95054 or visit www.sun.com if you need additional
024:         * information or have any questions.
025:         */
026:        package com.sun.midp.chameleon.input;
027:
028:        import javax.microedition.lcdui.*;
029:        import com.sun.midp.lcdui.*;
030:        import com.sun.midp.configurator.Constants;
031:        import com.sun.midp.i18n.Resource;
032:        import com.sun.midp.i18n.ResourceConstants;
033:        import com.sun.midp.log.LogChannels;
034:        import com.sun.midp.log.Logging;
035:
036:        /**
037:         * An InputMode instance which processes the numeric 0-9 keys
038:         * as their literal numeric values.
039:         */
040:        public class PredictiveTextInputMode implements  InputMode {
041:
042:            /** The InputModeMediator for the current input session */
043:            protected InputModeMediator mediator;
044:
045:            /**
046:             * Currently formatted predictive word from the PTIterator
047:             */
048:            private String part;
049:
050:            /**
051:             * Iterator interface to the predictive dictionary
052:             */
053:            private PTIterator iterator;
054:
055:            /**
056:             * Keeps the current state strign and compares diffs between current and
057:             * next states Class StringDiff is an inner-class defined below
058:             */
059:            private StringDiff diff;
060:
061:            /** array of sub-inputModes supported by this inputMode */
062:            private static final int[] CAPS_MODES = { CAPS_SENTENCE, CAPS_OFF,
063:                    CAPS_ON };
064:
065:            /** array of sub-inputModes labels, corresponding to CAPS_MODES array */
066:            private static final String[] CAPS_MODES_LABELS = {
067:                    Resource
068:                            .getString(ResourceConstants.LCDUI_TF_CAPS_SENTENCE_LB_PTI),
069:                    Resource
070:                            .getString(ResourceConstants.LCDUI_TF_CAPS_OFF_LB_PTI),
071:                    Resource
072:                            .getString(ResourceConstants.LCDUI_TF_CAPS_ON_LB_PTI) };
073:
074:            /** points to an element of CAPS_MODES which is the current sub-inputMode */
075:            private int capsMode = 0;
076:
077:            /** Init predictive text input mode */
078:            private void init() {
079:                iterator = PTDictionaryFactory.getDictionary().iterator();
080:                if (diff == null) {
081:                    diff = new StringDiff();
082:                }
083:                clear();
084:            }
085:
086:            /**
087:             * This method is called to determine if this InputMode supports
088:             * the given text input constraints. The semantics of the constraints
089:             * value are defined in the javax.microedition.lcdui.TextField API. 
090:             * If this InputMode returns false, this InputMode must not be used
091:             * to process key input for the selected text component.
092:             * @param constraints current constraints.
093:             * The constraints format is defined in TextField. 
094:             *
095:             * @return true if this InputMode supports the given text component
096:             *         constraints, as defined in the MIDP TextField API
097:             */
098:            public boolean supportsConstraints(int constraints) {
099:                boolean isSupported = false;
100:                if ((constraints & TextField.CONSTRAINT_MASK) == TextField.ANY
101:                        || (constraints & TextField.CONSTRAINT_MASK) == TextField.URL) {
102:                    isSupported = true;
103:                }
104:                if ((constraints & TextField.NON_PREDICTIVE) > 0) {
105:                    isSupported = false;
106:                }
107:                if ((constraints & TextField.SENSITIVE) > 0) {
108:                    isSupported = false;
109:                }
110:                if ((constraints & TextField.PASSWORD) > 0) {
111:                    isSupported = false;
112:                }
113:                return isSupported;
114:            }
115:
116:            /**
117:             * Returns the display name which will represent this InputMode to 
118:             * the user, such as in a selection list or the softbutton bar.
119:             *
120:             * @return the locale-appropriate name to represent this InputMode
121:             *         to the user
122:             */
123:            public String getName() {
124:                return CAPS_MODES_LABELS[capsMode];
125:            }
126:
127:            /**
128:             * Returns the command name which will represent this InputMode to 
129:             * the user
130:             *
131:             * @return the locale-appropriate command name to represent this InputMode
132:             *         to the user
133:             */
134:            public String getCommandName() {
135:                return Resource.getString(ResourceConstants.LCDUI_TF_CMD_PTI);
136:            }
137:
138:            /**
139:             * This method will be called before any input keys are passed
140:             * to this InputMode to allow the InputMode to perform any needed
141:             * initialization. A reference to the InputModeMediator which is
142:             * currently managing the relationship between this InputMode and
143:             * the input session is passed in. This reference can be used
144:             * by this InputMode to commit text input as well as end the input
145:             * session with this InputMode. The reference is only valid until
146:             * this InputMode's endInput() method is called.
147:             *
148:             * @param constraints text input constraints. The semantics of the 
149:             * constraints value are defined in the TextField API.
150:             *
151:             * @param mediator the InputModeMediator which is negotiating the
152:             *        relationship between this InputMode and the input session
153:             *
154:             * @param inputSubset current input subset
155:             */
156:            public void beginInput(InputModeMediator mediator,
157:                    String inputSubset, int constraints) {
158:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
159:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
160:                            "[*** beginInput]");
161:                }
162:                validateState(false);
163:                this .mediator = mediator;
164:                // need to re-init dictionary every time because the language/locale
165:                // can be changed.
166:                init();
167:            }
168:
169:            /**
170:             * Mark the end of this InputMode's processing. The only possible call
171:             * to this InputMode after a call to endInput() is a call to beginInput()
172:             * to begin a new input session.
173:             */
174:            public void endInput() {
175:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
176:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
177:                            "********[endInput]");
178:                }
179:                validateState(true);
180:                this .mediator = null;
181:                clear();
182:            }
183:
184:            /**
185:             * By default the regular input method has no specific displayable
186:             * representation so it returns null.  
187:             * @return null by default 
188:             */
189:            public Displayable getDisplayable() {
190:                return null;
191:            }
192:
193:            /** 
194:             * Returns true if input mode is using its own displayable, false ifinput
195:             * mode does not require the speial displayable for its representation.
196:             * By default returns false 
197:             * @return true if input mode is using its own displayable, otherwise false
198:             */
199:            public boolean hasDisplayable() {
200:                return false;
201:            }
202:
203:            /**
204:             * Clear the iterator
205:             */
206:            public void clear() {
207:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
208:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
209:                            "[clear]");
210:                }
211:                diff.clear();
212:                part = "";
213:                iterator.reset();
214:            }
215:
216:            /**
217:             * Process the given key code as input.
218:             * 
219:             * This method will return true if the key was processed successfully,
220:             * false otherwise.
221:             *
222:             * @param keyCode the keycode of the key which was input
223:             * @param longPress true if long key press happens, otherwise false.
224:             * @return the key code if the key has been committed for the input, or
225:             * KEYCODE_NONE if the key has not been habdled by the input mode, or
226:             * KEYCODE_INVISIBLE if the key has been handled by the input mode but
227:             * this key has not been displayed
228:             */
229:            public int processKey(int keyCode, boolean longPress) {
230:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
231:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
232:                            "[PT.processKey] keyCode = " + keyCode);
233:                }
234:
235:                int ret = KEYCODE_NONE;
236:                boolean gotoNextState = true;
237:                boolean needClear = false;
238:                boolean needFinishWord = false;
239:
240:                validateState(true);
241:
242:                if (mediator != null && mediator.isClearKey(keyCode)) {
243:                    if (longPress) {
244:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
245:                            Logging.report(Logging.INFORMATION,
246:                                    LogChannels.LC_HIGHUI,
247:                                    "         **isClearALL**");
248:                        }
249:                        clear();
250:                        gotoNextState = false;
251:                    } else {
252:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
253:                            Logging.report(Logging.INFORMATION,
254:                                    LogChannels.LC_HIGHUI,
255:                                    "         **isClearOne**");
256:                        }
257:                        if (part.length() <= 1) {
258:                            clear();
259:                            gotoNextState = false;
260:                            //                    return KEYCODE_NONE;
261:                        } else {
262:                            if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
263:                                Logging.report(Logging.INFORMATION,
264:                                        LogChannels.LC_HIGHUI,
265:                                        "           part.length()>1");
266:                            }
267:                            iterator.prevLevel();
268:                            part = getNextMatch();
269:                            // part=part.substring(0, part.length()-1);
270:                            // diff.stateModified(part);
271:                            ret = KEYCODE_INVISIBLE;
272:                        }
273:                    }
274:                } else if (longPress) {
275:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
276:                        Logging
277:                                .report(Logging.INFORMATION,
278:                                        LogChannels.LC_HIGHUI,
279:                                        "         **longPress**");
280:                    }
281:                    needFinishWord = true;
282:                    if (isValidKey(keyCode)) {
283:                        // if (part.length()>0) {
284:                        // }
285:                        part = part.substring(0, part.length() - 1)
286:                                + String.valueOf((char) keyCode);
287:                    }
288:                    needClear = true;
289:                } else if (isNextOption(keyCode)) {
290:                    /**
291:                     * 2. handle '#' (show next completion option) case 
292:                     */
293:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
294:                        Logging.report(Logging.INFORMATION,
295:                                LogChannels.LC_HIGHUI,
296:                                "         **isNextOption**");
297:                    }
298:
299:                    if (part.length() == 0) {
300:                        gotoNextState = false;
301:                    } else {
302:                        part = getNextMatch();
303:                    }
304:                } else if (isPrevOption(keyCode)) {
305:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
306:                        Logging.report(Logging.INFORMATION,
307:                                LogChannels.LC_HIGHUI, "         **isPrev**");
308:                    }
309:                    part = getPrevMatch();
310:                } else if (isKeyMapChange(keyCode)) {
311:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
312:                        Logging.report(Logging.INFORMATION,
313:                                LogChannels.LC_HIGHUI,
314:                                "         **isKeyMapChange**");
315:                    }
316:                    /**
317:                     * 3. handle '*' (key map change) case 
318:                     */
319:                    nextCapsMode();
320:                } else if (isWhiteSpace(keyCode)) {
321:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
322:                        Logging.report(Logging.INFORMATION,
323:                                LogChannels.LC_HIGHUI,
324:                                "         **isWhiteSpace**");
325:                    }
326:                    /**
327:                     * 4. handle whitespace  
328:                     */
329:                    needFinishWord = true;
330:                    if (keyCode == '#') {
331:                        part = part + ' ';
332:                    }
333:                    needClear = true;
334:                } else {
335:                    /**
336:                     * 5. handle standard '2'-'9' keys
337:                     */
338:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
339:                        Logging.report(Logging.INFORMATION,
340:                                LogChannels.LC_HIGHUI,
341:                                "         **is key to process**");
342:                    }
343:                    if (isValidKey(keyCode)) {
344:                        processKeyCode(keyCode);
345:                    } else {
346:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
347:                            Logging.report(Logging.INFORMATION,
348:                                    LogChannels.LC_HIGHUI,
349:                                    "invalid key, returning KEYCODE_NONE.");
350:                        }
351:                        gotoNextState = false;
352:                    }
353:                }
354:
355:                /**
356:                 * Call StringDiff.nextState() method with the next resulting entry
357:                 * output StringDiff will check if the underlying entry changed and 
358:                 * will invoke the InputMethodClient with the differences.
359:                 */
360:                if (gotoNextState) {
361:                    diff.nextState(part);
362:                    if (needClear) {
363:                        clear();
364:                    }
365:                }
366:                if (needFinishWord) {
367:                    finishWord();
368:                }
369:                return ret;
370:            }
371:
372:            /**
373:             * return the pending char
374:             * used to bypass the asynchronous commit mechanism
375:             * e.g. to immediately commit a char before moving the cursor
376:             * @return return the pending char
377:             */
378:            public char getPendingChar() {
379:                return 0;
380:            }
381:
382:            /**
383:             * Process a new key in range '2'-'9'.
384:             * Advnace the iterator and update the word part
385:             *
386:             * @param keyCode char in range '0'-'9','#', '*'
387:             */
388:            void processKeyCode(int keyCode) {
389:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
390:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
391:                            "[processKeyCode] keyCode=" + keyCode);
392:                }
393:                iterator.nextLevel(keyCode);
394:                if (iterator.hasNext()) {
395:                    part = iterator.next();
396:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
397:                        Logging
398:                                .report(
399:                                        Logging.INFORMATION,
400:                                        LogChannels.LC_HIGHUI,
401:                                        "iterator.hasNext = true\n"
402:                                                + "iterator part\n"
403:                                                + "     :) [processKeyCode] iterator.hasNext: part="
404:                                                + part);
405:                    }
406:                } else {
407:                    // ignore the key
408:                    // part=part+keyCode2Char(keyCode);
409:                    // IMPL NOTE: Consider a better solution: maybe jump to standard mode?
410:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
411:                        Logging
412:                                .report(
413:                                        Logging.INFORMATION,
414:                                        LogChannels.LC_HIGHUI,
415:                                        "XXXXXXXXXXXXXXXXXXXXXXXXXXX\n\n"
416:                                                + ":( [processKeyCode] !iterator.hasNext part="
417:                                                + part + "\n"
418:                                                + "XXXXXXXXXXXXXXXXXXXXXXXXX");
419:                    }
420:                }
421:                part = modifyCaps(part);
422:            }
423:
424:            /**
425:             * Modify the caps for the string depending on the current caps mode
426:             * @param str text
427:             * @return the same text with required caps 
428:             */
429:            private String modifyCaps(String str) {
430:                // log("[handleCaps] capsMode=" + CAPS_MODES_LABELS[capsMode]);
431:                String ret = str;
432:                if (str != null && str.length() > 0) {
433:                    switch (CAPS_MODES[capsMode]) {
434:                    case CAPS_OFF:
435:                        ret = str.toLowerCase();
436:                        break;
437:                    case CAPS_ON:
438:                        ret = str.toUpperCase();
439:                        break;
440:                    case CAPS_SENTENCE:
441:                        str = str.toLowerCase();
442:                        char[] chars = str.toCharArray();
443:                        chars[0] = Character.toUpperCase(chars[0]);
444:                        ret = new String(chars);
445:                        break;
446:                    }
447:                }
448:                return ret;
449:            }
450:
451:            /**
452:             * Check if keyCode represents a whitespace key (i.e. not in '2'..'9')
453:             *
454:             * @param keyCode char in range '0'-'9','#', '*', CLEAR
455:             * @return true if whitespace, false otherwise
456:             */
457:            private boolean isWhiteSpace(int keyCode) {
458:                return keyCode == '#' || keyCode == Canvas.LEFT
459:                        || keyCode == Canvas.RIGHT
460:                        || keyCode == Constants.KEYCODE_SELECT;
461:            }
462:
463:            /**
464:             * Check if keyCode indicates a next completion key event
465:             *
466:             * @param keyCode key code
467:             * @return true if next completion key, false otherwise
468:             */
469:            private boolean isNextOption(int keyCode) {
470:                return keyCode == Canvas.DOWN;
471:            }
472:
473:            /**
474:             * Check if keyCode indicates a previous completion key event
475:             *
476:             * @param keyCode key code
477:             * @return true if prev completion key, false otherwise
478:             */
479:            private boolean isPrevOption(int keyCode) {
480:                return keyCode == Canvas.UP;
481:            }
482:
483:            /**
484:             * Check if keyCode represents a change of keymap event ('*' key)
485:             *
486:             * @param keyCode key code
487:             * @return true if keymap chage key code, false otherwise
488:             */
489:            private boolean isKeyMapChange(int keyCode) {
490:                return keyCode == '*';
491:            }
492:
493:            /**
494:             * Check if the key has to be handled this input mode
495:             * @param keyCode key
496:             * @return true if this key can be  handled by this input mode,
497:             * otherwise false
498:             */
499:            private boolean isValidKey(int keyCode) {
500:                int available = mediator != null ? mediator.getAvailableSize()
501:                        : 0;
502:
503:                return available > 0 && keyCode >= '0' && keyCode <= '9';
504:            }
505:
506:            /**
507:             * Return the next possible match for the key input processed thus
508:             * far by this InputMode. A call to this method should be preceeded
509:             * by a check of hasMoreMatches(). If the InputMode has more available
510:             * matches for the given input, this method will return them one by one.
511:             *
512:             * @return a String representing the next available match to the key 
513:             *         input thus far, or 'null' if no pending input is available
514:             */
515:            public String getNextMatch() {
516:                String retStr = null;
517:                if (part == null || part.length() == 0) {
518:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
519:                        Logging.report(Logging.INFORMATION,
520:                                LogChannels.LC_HIGHUI,
521:                                "[getNextMatch] <<< returning null");
522:                    }
523:                    return null;
524:                }
525:
526:                if (!iterator.hasNext()) {
527:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
528:                        Logging.report(Logging.INFORMATION,
529:                                LogChannels.LC_HIGHUI,
530:                                "     [getNextMatch] rewinding...");
531:                    }
532:                    iterator.resetNext();
533:                }
534:                if (iterator.hasNext()) {
535:                    retStr = iterator.next();
536:                    retStr = modifyCaps(retStr);
537:                }
538:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
539:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
540:                            "[getNextMatch] <<< returning " + retStr);
541:                }
542:                return retStr;
543:            }
544:
545:            /**
546:             * Return the previous possible match for the key input processed thus
547:             * far by this InputMode. 
548:             *
549:             * @return a String representing the previous available match to the key 
550:             *         input thus far, or 'null' if no pending input is available
551:             */
552:            public String getPrevMatch() {
553:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
554:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
555:                            "getPrevMatch");
556:                }
557:                String prevMatch = "";
558:                String match = "";
559:                int num;
560:                if (part == null || part.length() == 0
561:                        || (prevMatch = match = getNextMatch()) == null) {
562:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
563:                        Logging.report(Logging.INFORMATION,
564:                                LogChannels.LC_HIGHUI,
565:                                "[getPrevMatch] <<< returning empty str");
566:                    }
567:                    return prevMatch;
568:                }
569:
570:                while (match.compareTo(part) != 0) {
571:                    prevMatch = match;
572:                    match = getNextMatch();
573:                }
574:
575:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
576:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
577:                            "[getPrevMatch] <<< returning " + prevMatch);
578:                }
579:                return prevMatch;
580:
581:            }
582:
583:            /**
584:             * True, if after processing a key, there is more than one possible
585:             * match to the input. If this method returns true, the getNextMatch()
586:             * method can be called to return the value.
587:             *
588:             * @return true if after processing a key, there is more than the one
589:             *         possible match to the given input
590:             */
591:            public boolean hasMoreMatches() {
592:                // log("[hasMoreMatches]");
593:                return iterator.hasNext();
594:            }
595:
596:            /**
597:             * Gets the possible string matches 
598:             *
599:             * @return returns the set of options.
600:             */
601:            public String[] getMatchList() {
602:                String[] ret = null;
603:
604:                if (part == null || part.length() <= 0) {
605:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
606:                        Logging.report(Logging.INFORMATION,
607:                                LogChannels.LC_HIGHUI,
608:                                "getMatchList returning empty array");
609:                    }
610:                    ret = new String[0];
611:                } else {
612:                    int num = 0;
613:                    String[] matches = new String[MAX_MATCHES];
614:                    String match = part;
615:
616:                    do {
617:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
618:                            Logging.report(Logging.INFORMATION,
619:                                    LogChannels.LC_HIGHUI,
620:                                    "    [getMatchList()] got nother match: "
621:                                            + match);
622:                        }
623:                        matches[num] = match;
624:                        num++;
625:                    } while (num < MAX_MATCHES
626:                            && (match = getNextMatch()) != null
627:                            && match.compareTo(part) != 0);
628:
629:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
630:                        Logging.report(Logging.INFORMATION,
631:                                LogChannels.LC_HIGHUI,
632:                                "getMatchList returning array of size " + num);
633:                    }
634:                    ret = new String[num];
635:                    System.arraycopy(matches, 0, ret, 0, num);
636:                }
637:                return ret;
638:            }
639:
640:            /**
641:             * This method will validate the state of this InputMode. If this
642:             * is a check for an "active" operation, the TextInputMediator must
643:             * be non-null or else this method will throw an IllegalStateException.
644:             * If this is a check for an "inactive" operation, then the
645:             * TextInputMediator should be null. 
646:             * @param activeOperation true if any operation is active otherwise false.
647:             */
648:            protected void validateState(boolean activeOperation) {
649:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
650:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
651:                            "[validateState]");
652:                }
653:                if (activeOperation && this .mediator == null) {
654:                    throw new IllegalStateException(
655:                            "Illegal operation on an input session already in progress");
656:                } else if (!activeOperation && this .mediator != null) {
657:                    throw new IllegalStateException(
658:                            "Illegal operation on an input session which is not in progress");
659:                }
660:            }
661:
662:            /**
663:             * Set the next capital mode for this input method
664:             */
665:            private void nextCapsMode() {
666:                capsMode++;
667:                if (capsMode == CAPS_MODES.length) {
668:                    capsMode = 0;
669:                }
670:                part = modifyCaps(part);
671:                mediator.subInputModeChanged();
672:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
673:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
674:                            "[nextCapsMode] capsMode = " + capsMode + ", "
675:                                    + CAPS_MODES_LABELS[capsMode]);
676:                }
677:            }
678:
679:            /**
680:             * Finish the word
681:             */
682:            private void finishWord() {
683:                if (CAPS_MODES[capsMode] == CAPS_SENTENCE) {
684:                    nextCapsMode();
685:                }
686:            }
687:
688:            /**
689:             * Class StringDiff 
690:             *
691:             * Inner class to handle state changes and to output the differeces to 
692:             * listener InputMethodHandler.
693:             */
694:            private class StringDiff {
695:                /**
696:                 * holds current entry state
697:                 */
698:                private String state;
699:
700:                /**
701:                 * constructor
702:                 */
703:                public StringDiff() {
704:                    clear();
705:                }
706:
707:                /**
708:                 * clear current state
709:                 */
710:                public void clear() {
711:                    state = "";
712:                }
713:
714:                /**
715:                 * Update string
716:                 * @param modified new string 
717:                 */
718:                public void stateModified(String modified) {
719:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
720:                        Logging.report(Logging.INFORMATION,
721:                                LogChannels.LC_HIGHUI,
722:                                "[stateModified] state = " + state);
723:                    }
724:                    state = modified;
725:                }
726:
727:                /**
728:                 * Change of state processing.
729:                 * Find the differences between state and nextState:
730:                 * - If the diffrences are in new chars added to nextState, send
731:                 * them to the listener.
732:                 * - If chars submitted to the listener were retroactively changes,
733:                 * resend all
734:                 *   
735:                 * @param nextState sets next state
736:                 */
737:                public void nextState(String nextState) {
738:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
739:                        Logging.report(Logging.INFORMATION,
740:                                LogChannels.LC_HIGHUI,
741:                                "[nextState] nextState = " + nextState
742:                                        + "(length = " + nextState.length()
743:                                        + ") state=" + state + "(length="
744:                                        + state.length() + ")");
745:                    }
746:
747:                    if (mediator != null) {
748:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
749:                            Logging.report(Logging.INFORMATION,
750:                                    LogChannels.LC_HIGHUI,
751:                                    "           resending all");
752:                            Logging.report(Logging.INFORMATION,
753:                                    LogChannels.LC_HIGHUI, "clearing " + state
754:                                            + ": " + state.length() + " chars");
755:                        }
756:                        mediator.clear(state.length());
757:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
758:                            Logging.report(Logging.INFORMATION,
759:                                    LogChannels.LC_HIGHUI,
760:                                    "         commiting " + nextState);
761:                        }
762:                        mediator.commit(nextState);
763:                        if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
764:                            Logging.report(Logging.INFORMATION,
765:                                    LogChannels.LC_HIGHUI, "[resendAll] <<<<");
766:                        }
767:                        state = nextState;
768:                    }
769:                    if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
770:                        Logging.report(Logging.INFORMATION,
771:                                LogChannels.LC_HIGHUI, "[nextState] <<<<");
772:                    }
773:                }
774:            }
775:
776:            /** this mode is not set as default. So the map is initialoized by false */
777:            private static final boolean[][] isMap = new boolean[TextInputSession.INPUT_SUBSETS.length][TextInputSession.MAX_CONSTRAINTS];
778:
779:            /**
780:             * Returns the map specifying this input mode is proper one for the
781:             * particular pair of input subset and constraint. The form of the map is
782:             *
783:             *                       |ANY|EMAILADDR|NUMERIC|PHONENUMBER|URL|DECIMAL|
784:             * ---------------------------------------------------------------------
785:             * IS_FULLWIDTH_DIGITS   |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
786:             * IS_FULLWIDTH_LATIN    |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
787:             * IS_HALFWIDTH_KATAKANA |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
788:             * IS_HANJA              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
789:             * IS_KANJI              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
790:             * IS_LATIN              |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
791:             * IS_LATIN_DIGITS       |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
792:             * IS_SIMPLIFIED_HANZI   |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
793:             * IS_TRADITIONAL_HANZI  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
794:             * MIDP_UPPERCASE_LATIN  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
795:             * MIDP_LOWERCASE_LATIN  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
796:             * NULL                  |t|f|   t|f   |  t|f  |    t|f    |t|f|  t|f  |
797:             *
798:             * @return input subset x constraint map
799:             */
800:            public boolean[][] getIsConstraintsMap() {
801:                return isMap;
802:            }
803:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.