Source Code Cross Referenced for PTIteratorImpl.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:
027:        package com.sun.midp.chameleon.input;
028:
029:        import com.sun.midp.io.Util;
030:        import com.sun.midp.log.LogChannels;
031:        import com.sun.midp.log.Logging;
032:
033:        /** 
034:         * Implements PTIterator using machine-dependent KNI interface.
035:         *
036:         */
037:        public class PTIteratorImpl implements  PTIterator {
038:            /** 
039:             * Internal array size to hold KNI word completion
040:             */
041:            static final int MAX_STRING = 128;
042:
043:            /** 
044:             * Internal array to hold KNI word completion
045:             */
046:            private byte[] entry;
047:
048:            /** 
049:             * current handle
050:             */
051:            private int handle;
052:
053:            /** 
054:             * create a new iterator
055:             * @param dictionary dictionary id 
056:             */
057:            public PTIteratorImpl(int dictionary) {
058:                entry = new byte[MAX_STRING];
059:                handle = ptNewIterator0(dictionary);
060:            }
061:
062:            /** 
063:             * create a new handle and clear completion state by
064:             * calling ptNewIterator0()
065:             */
066:            public void reset() {
067:                ptClear0(handle);
068:            }
069:
070:            /** 
071:             * check if current handle is valid
072:             * @return true is valid, false otherwise
073:             */
074:            public boolean isValid() {
075:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
076:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
077:                            "isValid = " + (handle != 0));
078:                }
079:                return handle > 0;
080:            }
081:
082:            /** 
083:             * Adds a key to current completion string
084:             * @param keyCode char in the range '0'-'9', '#', or '*'
085:             */
086:            public void nextLevel(int keyCode) {
087:                if (isValid()) {
088:                    ptAddKey0(handle, keyCode);
089:                }
090:            }
091:
092:            /** 
093:             * Backspace on key in current completion string.
094:             */
095:            public void prevLevel() {
096:                if (isValid()) {
097:                    ptDeleteKey0(handle);
098:                }
099:            }
100:
101:            /**
102:             * Returns true if the iteration has more elements. (In other words,
103:             * returns <code>true</code> if <code>next</code> would return an
104:             * element rather than throwing an exception.)
105:             *
106:             * @return true if the iterator has more elements.
107:             */
108:            public boolean hasNext() {
109:                boolean ret = false;
110:                if (isValid()) {
111:                    ret = ptHasCompletionOption0(handle);
112:                }
113:                return ret;
114:            }
115:
116:            /** 
117:             * Reverts to first possible completion.
118:             * If next() has been called uptil hasNext() returns false, then after 
119:             * calling reviewCompletionOptions(), calling next() will return
120:             * the 1st completion
121:             */
122:            public void resetNext() {
123:                if (isValid()) {
124:                    ptRenewCompletionOptions0(handle);
125:                }
126:            }
127:
128:            /**
129:             * Returns the next element in the iteration.
130:             *
131:             * @return next element in the iteration.
132:             *
133:             * @exception NoSuchElementException iteration has no more elements.
134:             */
135:            public String next() {
136:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
137:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
138:                            "[iter.nextCompletionOption] >>");
139:                }
140:                String ret = null;
141:
142:                if (isValid()) {
143:                    ret = ptNextCompletionOption0(handle, entry.length);
144:                }
145:
146:                if (ret == null)
147:                    ret = "";
148:
149:                if (Logging.REPORT_LEVEL <= Logging.INFORMATION) {
150:                    Logging.report(Logging.INFORMATION, LogChannels.LC_HIGHUI,
151:                            "[iter.nextCompletionOption] : " + ret);
152:                }
153:
154:                return ret;
155:            }
156:
157:            /** 
158:             * NATIVE CODE
159:             */
160:
161:            /**
162:             * Create a new iterator instance
163:             *
164:             * @param dictionary library handle
165:             * @return handle of new iterator.
166:             */
167:            private static native int ptNewIterator0(int dictionary);
168:
169:            /**
170:             * Clear all text from the predictive text iterator 
171:             *
172:             * @param handle the handle of the iterator 
173:             * @return true if iterator has been cleared successfully otherwise false.
174:             */
175:            private static native boolean ptClear0(int handle);
176:
177:            /**
178:             * Advances the predictive text iterator using the next key code
179:             *
180:             * @param handle the handle of the iterator 
181:             * @param keyCode the next key ('0'-'9')
182:             *
183:             * @return true if key code has been added successfully otherwise false
184:             */
185:            private static native boolean ptAddKey0(int handle, int keyCode);
186:
187:            /**
188:             * Backspace the iterator one key 
189:             *
190:             * @param handle the handle of the iterator 
191:             * @return true if key has been deleted successfully otherwise false.
192:             */
193:            private static native boolean ptDeleteKey0(int handle);
194:
195:            /**
196:             * reset completion options for for the current predictive text entry
197:             * After this call, ptNextCompletionOption() will return all
198:             * completion options starting from 1st one.
199:             *
200:             * @param handle the handle of the iterator 
201:             * @return true if iterator has been reset successfully otherwise false.
202:             */
203:            private static native boolean ptRenewCompletionOptions0(int handle);
204:
205:            /**
206:             * return the current predictive text completion option
207:             *
208:             * @param handle the handle of the iterator 
209:             * @param outMaxSize max size of the outArray 
210:             *
211:             * @return next element in the iteration
212:             */
213:            private static native String ptNextCompletionOption0(int handle,
214:                    int outMaxSize);
215:
216:            /**
217:             * see if exist further completion options for the current
218:             * predictive text entry
219:             *
220:             * @param handle the handle of the iterator 
221:             *
222:             * @return true if more completion options exist, false otherwise
223:             */
224:            private static native boolean ptHasCompletionOption0(int handle);
225:
226:        }
www.java2java.com | Contact Us
Copyright 2009 - 12 Demo Source and Support. All rights reserved.
All other trademarks are property of their respective owners.