|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectca.odell.glazedlists.swing.AutoCompleteSupport<E>
public final class AutoCompleteSupport<E>
This class install(javax.swing.JComboBox, ca.odell.glazedlists.EventLists support for filtering and autocompletion into
a standard JComboBox. It also acts as a factory class for
creating autocompleting table cell editors.
All autocompletion behaviour provided is meant to mimic the functionality of the Firefox address field. To be explicit, the following is a list of expected behaviours which are installed:
Typing into the ComboBox Editor
JComboBox, but may be wider to accomodate a
prototype display value
if a non-null value exists
JComboBox.getMaximumRowCount()
rows before scrolling the popup
A single ActionEvent is fired from the JComboBox in these situations:
null values located in the ComboBoxModel are considered
identical to empty Strings ("") for the purposes of locating autocompletion
terms.
When the ComboBoxEditor gains focus it selects the text it contains if
getSelectsTextOnFocusGain() returns true; otherwise it
does nothing.
In order to achieve all of the autocompletion and filtering behaviour,
the following occurs when install(javax.swing.JComboBox, ca.odell.glazedlists.EventList is called:
Warning: This class must be
mutated from the Swing Event Dispatch Thread. Failure to do so will result in
an IllegalStateException thrown from any one of:
install(JComboBox, EventList)
install(JComboBox, EventList, TextFilterator)
uninstall()
setCorrectsCase(boolean)
setStrict(boolean)
| Field Summary | |
|---|---|
protected JButton |
arrowButton
The arrow button that invokes the popup. |
| Method Summary | ||
|---|---|---|
static
|
createTableCellEditor(TableFormat<E> tableFormat,
EventList<E> tableData,
int columnIndex)
This factory method creates and returns a DefaultCellEditor
which adapts an autocompleting JComboBox for use as a Table
Cell Editor. |
|
JComboBox |
getComboBox()
Returns the autocompleting JComboBox or null if
AutoCompleteSupport has been uninstall()ed. |
|
boolean |
getCorrectsCase()
Returns true if user specified strings are converted to the case of the autocompletion term they match; false otherwise. |
|
EventList<E> |
getItemList()
Returns the filtered EventList of items which backs the
ComboBoxModel of the autocompleting JComboBox. |
|
boolean |
getSelectsTextOnFocusGain()
Returns true if the combo box editor text is selected when it gains focus; false otherwise. |
|
static
|
install(JComboBox comboBox,
EventList<E> items)
Installs support for autocompletion into the comboBox and
returns the support object that is actually providing those facilities. |
|
static
|
install(JComboBox comboBox,
EventList<E> items,
TextFilterator<E> filterator)
Installs support for autocompletion into the comboBox and
returns the support object that is actually providing those facilities. |
|
boolean |
isStrict()
Returns true if the user is able to specify values which do not appear in the popup list of suggestions; false otherwise. |
|
void |
setCorrectsCase(boolean correctCase)
If correctCase is true, user specified strings
will be converted to the case of the element they match. |
|
void |
setSelectsTextOnFocusGain(boolean selectsTextOnFocusGain)
If selectsTextOnFocusGain is true, all text in the
editor is selected when the combo box editor gains focus. |
|
void |
setStrict(boolean strict)
If strict is true, the user can specify values not
appearing within the ComboBoxModel. |
|
void |
uninstall()
This method removes autocompletion support from the JComboBox
it was installed on. |
|
| Methods inherited from class java.lang.Object |
|---|
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Field Detail |
|---|
protected JButton arrowButton
| Method Detail |
|---|
public static <E> AutoCompleteSupport install(JComboBox comboBox,
EventList<E> items)
comboBox and
returns the support object that is actually providing those facilities.
The support object is returned so that the caller may invoke
uninstall() at some later time to remove the autocompletion
features.
This method assumes that the items can be converted into
reasonable String representations via Object.toString().
comboBox - the JComboBox to decorate with autocompletionitems - the objects to display in the comboBox
IllegalStateException - if this method is called from any Thread
other than the Swing Event Dispatch Thread
public static <E> AutoCompleteSupport<E> install(JComboBox comboBox,
EventList<E> items,
TextFilterator<E> filterator)
comboBox and
returns the support object that is actually providing those facilities.
The support object is returned so that the caller may invoke
uninstall() at some later time to remove the autocompletion
features.
The filterator will be used to extract searchable text
strings from each of the items.
The following must be true in order to successfully install support
for autocompletion on a JComboBox:
JTextField as its editor
AbstractDocument as its model
comboBox - the JComboBox to decorate with autocompletionitems - the objects to display in the comboBoxfilterator - extracts searchable text strings from each item
IllegalStateException - if this method is called from any Thread
other than the Swing Event Dispatch Threadpublic JComboBox getComboBox()
JComboBox or null if
AutoCompleteSupport has been uninstall()ed.
public EventList<E> getItemList()
EventList of items which backs the
ComboBoxModel of the autocompleting JComboBox.
public boolean getCorrectsCase()
public void setCorrectsCase(boolean correctCase)
correctCase is true, user specified strings
will be converted to the case of the element they match. Otherwise
they will be left unaltered.
Note: this flag only has meeting when strict mode is turned off. When strict mode is on, case is corrected regardless of this setting.
IllegalStateException - if this method is called from any Thread
other than the Swing Event Dispatch ThreadsetStrict(boolean)public boolean isStrict()
public void setStrict(boolean strict)
strict is true, the user can specify values not
appearing within the ComboBoxModel. If it is false each
keystroke must continue to match some value in the ComboBoxModel or it
will be discarded.
Note: When strict mode is turned on then all user input is corrected to the case of the autocompletion term, regardless of the correctsCase setting.
IllegalStateException - if this method is called from any Thread
other than the Swing Event Dispatch ThreadsetCorrectsCase(boolean)public boolean getSelectsTextOnFocusGain()
public void setSelectsTextOnFocusGain(boolean selectsTextOnFocusGain)
selectsTextOnFocusGain is true, all text in the
editor is selected when the combo box editor gains focus. If it is
false the selection state of the editor is not effected by
focus changes.
IllegalStateException - if this method is called from any Thread
other than the Swing Event Dispatch Threadpublic void uninstall()
JComboBox
it was installed on. This method is useful when the EventList of
items that backs the combo box must outlive the combo box itself.
Calling this method will return the combo box to its original state
before autocompletion was installed, and it will be available for
garbage collection independently of the EventList of items.
IllegalStateException - if this method is called from any Thread
other than the Swing Event Dispatch Thread
public static <E> DefaultCellEditor createTableCellEditor(TableFormat<E> tableFormat,
EventList<E> tableData,
int columnIndex)
DefaultCellEditor
which adapts an autocompleting JComboBox for use as a Table
Cell Editor. The values within the table column are used as
autocompletion terms within the ComboBoxModel.
If the appearance or function of the autocompleting JComboBox
is to be customized, it can be retrieved using
DefaultCellEditor.getComponent().
tableFormat - specifies how each row object within a table is
broken apart into column valuestableData - the EventList backing the TableModelcolumnIndex - the index of the column for which to return a Table
Cell Editor
DefaultCellEditor which contains an autocompleting
combobox whose contents remain consistent with the data in the
table column at the given columnIndex
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||