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: * Aniterator that provides predictive text browsing capabilities
31: * Requires only single word predictive text librray support.
32: * Traversal is done by using nextLevel(keyCode) to enter keys and
33: * next() to get possible completions.
34: *
35: * Exmaple of using predictive text iterators:
36: *
37: * PTDictionary dictionary;
38: * Iterator iter=dictionary.iterator();
39: * iter.nextLevel('2');
40: * iter.nextLevel('2');
41: * iter.nextLevel('2');
42: * while(iter.hasNext()) {
43: * String completion=iter.next();
44: * System.out.println(completion);
45: * //will print "aca" (short of "academy") "cab" (short of "cabin"),
46: * // "acc" (short of "accelerate") etc.
47: * }
48: *
49: * PTIterator operations:
50: * next() : get next possible completion string
51: * hasNext() : check if another possible completion exists
52: * nextLevel(int key) : add a char to the current completion
53: * prevLevel() : backspace last char from current completion
54: * reset() : clear current completion
55: * resetNext() : revert to first possible completion string
56: */
57: public interface PTIterator {
58:
59: /**
60: * add a key to current completion string
61: * @param keyCode char in the range '0'-'9', '#', or '*'
62: */
63: public void nextLevel(int keyCode);
64:
65: /**
66: * backspace on key in current completion string
67: */
68: public void prevLevel();
69:
70: /**
71: * Returns true if the iteration has more elements. (In other words,
72: * returns <code>true</code> if <code>next</code> would return an
73: * element rather than throwing an exception.)
74: *
75: * @return true if the iterator has more elements.
76: */
77: public boolean hasNext();
78:
79: /**
80: * Revert to first possible completion.
81: * If next() has been called uptil hasNext() returns false, then after
82: * calling resetNext(), calling next() will return the 1st completion
83: */
84: public void resetNext();
85:
86: /**
87: * Returns the next element in the iteration.
88: * @return next element in the iteration.
89: * @exception NoSuchElementException iteration has no more elements.
90: */
91: public String next();
92:
93: /**
94: * create a new handle and clear completion state by calling
95: * ptNewIterator0()
96: */
97: public void reset();
98: }
|