de.matthiasmann.twl.model
Class AutoCompletionResult

java.lang.Object
  extended by de.matthiasmann.twl.model.AutoCompletionResult
Direct Known Subclasses:
SimpleAutoCompletionResult

public abstract class AutoCompletionResult
extends java.lang.Object

An abstract container for auto completion results.


Field Summary
static int DEFAULT_CURSOR_POS
          Return value for getCursorPosForResult(int) to use EditField's default cursor position for EditField.setText(java.lang.String)
protected  int prefixLength
           
protected  java.lang.String text
           
 
Constructor Summary
AutoCompletionResult(java.lang.String text, int prefixLength)
           
 
Method Summary
 int getCursorPosForResult(int idx)
          Returns the desired cursor position for the given result entry.
abstract  int getNumResults()
          Returns the number of results
 int getPrefixLength()
          The prefix length is the length of prefix which was used to collect the data.
abstract  java.lang.String getResult(int idx)
          Returns a selected result entry
 java.lang.String getText()
          Returns the text which was used for this auto completion
 AutoCompletionResult refine(java.lang.String text, int cursorPos)
          Tries to refine the results.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_CURSOR_POS

public static final int DEFAULT_CURSOR_POS
Return value for getCursorPosForResult(int) to use EditField's default cursor position for EditField.setText(java.lang.String)

See Also:
Constant Field Values

text

protected final java.lang.String text

prefixLength

protected final int prefixLength
Constructor Detail

AutoCompletionResult

public AutoCompletionResult(java.lang.String text,
                            int prefixLength)
Method Detail

getPrefixLength

public int getPrefixLength()
The prefix length is the length of prefix which was used to collect the data. The remaining part of the text is used for high lighting the results. This is used for things like tree completion.

Returns:
the prefix length

getText

public java.lang.String getText()
Returns the text which was used for this auto completion

Returns:
the text which was used for this auto completion

getNumResults

public abstract int getNumResults()
Returns the number of results

Returns:
the number of results

getResult

public abstract java.lang.String getResult(int idx)
Returns a selected result entry

Parameters:
idx - the index of the desired result entry
Returns:
the result entry
See Also:
getNumResults()

getCursorPosForResult

public int getCursorPosForResult(int idx)
Returns the desired cursor position for the given result entry. The default implementation returns DEFAULT_CURSOR_POS

Parameters:
idx - the index of the desired result entry
Returns:
the cursor position
See Also:
getNumResults(), getResult(int), DEFAULT_CURSOR_POS

refine

public AutoCompletionResult refine(java.lang.String text,
                                   int cursorPos)
Tries to refine the results. Refining can result in a different order of results then a new query but is faster. If refining resulted in no results then an empty AutoCompletionResult is returned.

Parameters:
text - The new text
cursorPos - The new cursor position
Returns:
the new refined AutoCompletionResult or null if refining was not possible