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:
27: package com.sun.midp.chameleon.input;
28:
29: /**
30: * Machine dependent API to predictive text library
31: *
32: * This implementation assumes that predictive text library
33: * loaded and handled by platfrom. As a result this class
34: * serves just as a Iteraror factory
35: */
36: public class PTDictionaryImpl implements PTDictionary {
37: /** library language */
38: private String language;
39:
40: /** Library handle. It's given out during library initialization */
41: private int handle;
42:
43: /** library iterator */
44: private PTIterator iterator;
45:
46: /**
47: * call ptInitLibrary0() on 1st execution
48: * @param lang current language
49: */
50: public PTDictionaryImpl(String lang) {
51: language = lang;
52: handle = ptInitLibrary0(lang);
53: }
54:
55: /**
56: * check if current handle is valid
57: * @return true is valid, false otherwise
58: */
59: public boolean isValid() {
60: return handle > 0;
61: }
62:
63: /**
64: * get a machine dependent predictive text Iterattor
65: *
66: * @return an iterator of the class IteratorImpl
67: */
68: public PTIterator iterator() {
69: if (iterator == null && isValid())
70: iterator = new PTIteratorImpl(handle);
71: return iterator;
72: }
73:
74: /**
75: * adding words to the predictive text dictionary is not
76: * supported on the platform. Returns false always
77: *
78: * @param word new word to add
79: * @return false (not supported on the platform)
80: */
81: public boolean addWord(String word) {
82: return false;
83: }
84:
85: /**
86: * NATIVE CODE
87: *
88: */
89:
90: /**
91: * Called 1st time predictive text library is accessed.
92: * it calls platform specific predictive text initialization functions
93: *
94: * @param lang the language used to select the library
95: * @return the handle of the library
96: */
97: private static native int ptInitLibrary0(String lang);
98: }
|