public class JAutoComplete extends Object implements AutoComplete
setOpacity(float)
: the opacity of the Popup WindowsetCaseSensitive(boolean)
: true if case is sensitive for the searchsearchHitsFromStart(boolean)
: true if the Search for hits is performed from the start of the typed text only. For example
the dictionnary word "conf" would be a hit for the text "unconfirmed" if this property was set to false, and false if it was set to true.
There would be a hit in the two cases for the text "confirmed"showPopup(boolean)
: true if a Popup Window presenting the possible hits should be presented. if false, the first hit will be
automatically used for the completionacceptDuplicates(boolean)
: true if the dictionnary accept duplicatesstartSearchOnKeyCode(int)
: the keyCode to use to start the search. By default the search is started immediately during the
typing. If the keyCode is strictly greater than 0, the search will be started by typing this keyCode with the Control key downsearchPerWord(boolean)
: true if the Search is performed per each wordJTextField tf = new JTextField(10); JAutoComplete autoCompleter = new JAutoComplete(tf); autoCompleter.setOpacity(0.9f); autoCompleter.searchHitsFromStart(false); //add the dictionary autoCompleter.addToDictionary("hello"); autoCompleter.addToDictionary("highlight"); autoCompleter.addToDictionary("cruel world"); autoCompleter.addToDictionary("war"); autoCompleter.addToDictionary("wording"); autoCompleter.addToDictionary("world");
Modifier and Type | Class and Description |
---|---|
class |
JAutoComplete.SuggestedHit
The Label used for the Suggested Hits.
|
class |
JAutoComplete.SuggestionHitsPanel
A panel for suggested hits.
|
Modifier and Type | Field and Description |
---|---|
protected JAutoComplete.SuggestionHitsPanel |
suggestedHitsPanel
The suggestion panel.
|
protected JTextComponent |
textComponent
The text component.
|
Constructor and Description |
---|
JAutoComplete(JTextComponent textComponent)
Constructor.
|
JAutoComplete(JTextComponent textComponent,
boolean showPopup)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
acceptDuplicates(boolean acceptDuplicates)
Set if the dictionnary accept duplicates.
|
void |
addAdditionalSearchItem(String text)
Add the additional search item in the popup.
|
void |
addAdditionalSearchSuggestion(String typedText)
Add the additional search text suggestion in the popup Window.
|
void |
addAutoCompleteListener(AutoCompleteListener l)
Add an JAutoComplete listener.
|
boolean |
addCategory(AutoCompleteDictionary.Category category)
Add a category to the dictionary.
|
AutoCompleteDictionary.Category |
addCategory(String category)
Add a category to the dictionary.
|
void |
addCategoryToSuggestions(AutoCompleteDictionary.Category category)
Add a category to the list of suggestions in the Popup Window.
|
boolean |
addItemToSuggestions(String category,
AutoCompleteDictionary.Item item)
Add a category to the list of suggestions in the Popup Window.
|
void |
addSearchTextListener(AdditionalSearchListener l)
Add an containing text listener.
|
boolean |
addToDictionary(AutoCompleteDictionary.Item item)
Add an item to the dictionary to use for the autoComplete.
|
boolean |
addToDictionary(String word)
Add a word to the dictionary to use for the autoComplete.
|
boolean |
addToDictionary(String category,
AutoCompleteDictionary.Item item)
Add an item to the dictionary to use for the autoComplete.
|
boolean |
addToDictionary(String category,
String word)
Add a word to the dictionary to use for the autoComplete.
|
List<AutoCompleteListener> |
getAutoCompleteListeners()
Return the list of JAutoComplete listeners.
|
List<AdditionalSearchListener> |
getContainingTextListeners()
Return the list of containing text listeners.
|
AutoCompleteDictionary |
getDictionary()
Return the dictionnary used for the Autocompletion.
|
float |
getOpacity()
Return the Popup Window opacity.
|
protected Color |
getPopUpBackgroundColor()
Return the background color of the suggested hits panel.
|
protected Color |
getPopUpBorderColor()
Return the borded color of the suggested hits panel.
|
int |
getResultsLimit()
Return the results limits.
|
int |
getSearchOnKeyCode()
Return the keyCode to use to start the search By default the search is started immediately during the typing.
|
protected Color |
getSuggestedHitFocusedColor()
Return the background color of the focused suggested hit.
|
protected Color |
getSuggestedHitTextColor()
Return the color of the suggested hits text.
|
String |
getText()
Return the text component text.
|
JTextComponent |
getTextComponent()
Return the text component.
|
boolean |
hasAdditionalSearchItem()
Return true if there is an additional search item in the popup.
|
boolean |
hasDefaultCategory()
Return true if the dictionnary uses only the default category.
|
boolean |
isAcceptingDuplicates()
Return true if the dictionnary accept duplicates.
|
boolean |
isCaseSensitive()
Return true if the search is case sensitive.
|
boolean |
isSearchingHitsFromStart()
Return true if the search begins from the start of the typed text.
|
boolean |
isSearchingPerWord()
Return true if the search is perfoemd per each typed word.
|
boolean |
isShowingPopup()
Return true if the Popup Window with the words suggestions must be presented during typing.
|
boolean |
isStartingSearchImmediately()
Return true if the search is started immediately during the typing.
|
void |
removeAutoCompleteListener(AutoCompleteListener l)
Removes an JAutoComplete listener.
|
boolean |
removeCategory(AutoCompleteDictionary.Category category)
Remove a category from the dictionary.
|
boolean |
removeCategory(String category)
Add a category to the dictionary.
|
void |
removeContainingTextListener(AdditionalSearchListener l)
Removes a containing text listener.
|
boolean |
removeFromDictionary(AutoCompleteDictionary.Item item)
Remove an item from the dictionary to use for the autoComplete.
|
boolean |
removeFromDictionary(String word)
Remove a word from the dictionary to use for the autoComplete.
|
boolean |
removeFromDictionary(String category,
AutoCompleteDictionary.Item item)
Remove an item from the dictionary to use for the autoComplete.
|
boolean |
removeFromDictionary(String category,
String word)
Remove a word from the dictionary to use for the autoComplete.
|
void |
resetDictionary()
Reset the Dictionnary to use for the autoComplete.
|
void |
searchHitsFromStart(boolean fromStart)
Set if the search begins from the start of the typed text.
|
void |
searchPerWord(boolean searchPerWord)
Set if the search is perfoemd per each typed word.
|
void |
setCaseSensitive(boolean caseSensitive)
Set if the search is case sensitive.
|
void |
setDictionnary(AutoCompleteDictionary dictionary)
Set the dictionnary used for the Autocompletion.
|
void |
setMaximumPopupSize(int maxWidth,
int maxHeight)
Set the maximum width and height of the Popup.
|
void |
setOnlineEngine(AutoCompleteOnlineEngine engine)
Set the search engine used for the Autocomplete without Popup.
|
void |
setOpacity(float opacity)
Set the Popup Window opacity.
|
void |
setPopupEngine(AutoCompleteEngine engine)
Set the search engine used for the Autocomplete with Popup.
|
void |
setResultsLimit(int limit)
Set the results limits.
|
void |
showPopup(boolean showPopup)
Set if the Popup Window with the words suggestions must be presented during typing.
|
void |
startSearchOnKeyCode(int keyCode)
Set the keyCode to use to start the search.
|
protected void |
updatePopupSize(int width,
int height)
Update the PopUp Size.
|
protected JTextComponent textComponent
protected JAutoComplete.SuggestionHitsPanel suggestedHitsPanel
public JAutoComplete(JTextComponent textComponent)
textComponent
- the text Componentpublic JAutoComplete(JTextComponent textComponent, boolean showPopup)
textComponent
- the text ComponentshowPopup
- true if the Popup Window is presented with the suggested words during typingpublic void setMaximumPopupSize(int maxWidth, int maxHeight)
setMaximumPopupSize
in interface AutoComplete
maxWidth
- the maximum width of the PopupmaxHeight
- the maximum height of the Popuppublic void addAdditionalSearchItem(String text)
addAdditionalSearchItem
in interface AutoComplete
text
- the additional search textpublic boolean hasAdditionalSearchItem()
hasAdditionalSearchItem
in interface AutoComplete
public void setOpacity(float opacity)
opacity
- the opacitypublic float getOpacity()
public boolean hasDefaultCategory()
public void acceptDuplicates(boolean acceptDuplicates)
acceptDuplicates
- true if the dictionnary accept duplicatespublic boolean isAcceptingDuplicates()
public void startSearchOnKeyCode(int keyCode)
keyCode
- the keycode to use to start the searchpublic int getSearchOnKeyCode()
public boolean isStartingSearchImmediately()
public void searchPerWord(boolean searchPerWord)
searchPerWord
- true if the search is perfoemd per each typed wordpublic boolean isSearchingPerWord()
public void showPopup(boolean showPopup)
showPopup
- if the Popup Window with the words suggestions must be presentedpublic boolean isShowingPopup()
public void setCaseSensitive(boolean caseSensitive)
caseSensitive
- if the search is case sensitivepublic boolean isCaseSensitive()
isCaseSensitive
in interface AutoComplete
public void searchHitsFromStart(boolean fromStart)
isShowingPopup()
is true, then the search will always
being from start regardless of the value if this property.fromStart
- if the search begins from the start of the typed textpublic boolean isSearchingHitsFromStart()
isSearchingHitsFromStart
in interface AutoComplete
public void setResultsLimit(int limit)
limit
- the results limitspublic int getResultsLimit()
getResultsLimit
in interface AutoComplete
public void setPopupEngine(AutoCompleteEngine engine)
setPopupEngine
in interface AutoComplete
engine
- the search enginepublic void setOnlineEngine(AutoCompleteOnlineEngine engine)
setOnlineEngine
in interface AutoComplete
engine
- the search engineprotected Color getSuggestedHitTextColor()
protected Color getSuggestedHitFocusedColor()
protected Color getPopUpBackgroundColor()
protected Color getPopUpBorderColor()
public void addAutoCompleteListener(AutoCompleteListener l)
l
- the listenerpublic void removeAutoCompleteListener(AutoCompleteListener l)
l
- the listenerpublic List<AutoCompleteListener> getAutoCompleteListeners()
public void addSearchTextListener(AdditionalSearchListener l)
l
- the listenerpublic void removeContainingTextListener(AdditionalSearchListener l)
l
- the listenerpublic List<AdditionalSearchListener> getContainingTextListeners()
public final String getText()
public void addCategoryToSuggestions(AutoCompleteDictionary.Category category)
AutoCompleteEngine
used for the search with a Popup Window.addCategoryToSuggestions
in interface AutoComplete
category
- the categorysetPopupEngine(org.mdiutil.text.autocomplete.AutoCompleteEngine)
public boolean addItemToSuggestions(String category, AutoCompleteDictionary.Item item)
AutoCompleteEngine
used for the search with a Popup Window.addItemToSuggestions
in interface AutoComplete
category
- the category nameitem
- the ItemsetPopupEngine(org.mdiutil.text.autocomplete.AutoCompleteEngine)
public void addAdditionalSearchSuggestion(String typedText)
addAdditionalSearchSuggestion
in interface AutoComplete
typedText
- the typed textprotected final void updatePopupSize(int width, int height)
width
- the width of the elementheight
- the height of the elementpublic void resetDictionary()
resetDictionary
in interface AutoComplete
public AutoCompleteDictionary getDictionary()
getDictionary
in interface AutoComplete
public void setDictionnary(AutoCompleteDictionary dictionary)
setDictionnary
in interface AutoComplete
dictionary
- the dictionnarypublic boolean addCategory(AutoCompleteDictionary.Category category)
addCategory
in interface AutoComplete
category
- the categorypublic AutoCompleteDictionary.Category addCategory(String category)
addCategory
in interface AutoComplete
category
- the category namepublic boolean removeCategory(AutoCompleteDictionary.Category category)
removeCategory
in interface AutoComplete
category
- the categorypublic boolean removeCategory(String category)
removeCategory
in interface AutoComplete
category
- the category namepublic boolean addToDictionary(String word)
addToDictionary
in interface AutoComplete
word
- the wordpublic boolean addToDictionary(AutoCompleteDictionary.Item item)
addToDictionary
in interface AutoComplete
item
- the itempublic boolean addToDictionary(String category, String word)
addToDictionary
in interface AutoComplete
category
- the item categoryword
- the wordpublic boolean addToDictionary(String category, AutoCompleteDictionary.Item item)
addToDictionary
in interface AutoComplete
category
- the item categoryitem
- the itempublic boolean removeFromDictionary(String word)
removeFromDictionary
in interface AutoComplete
word
- the wordpublic boolean removeFromDictionary(AutoCompleteDictionary.Item item)
removeFromDictionary
in interface AutoComplete
item
- the itempublic boolean removeFromDictionary(String category, String word)
removeFromDictionary
in interface AutoComplete
category
- the item categoryword
- the wordpublic boolean removeFromDictionary(String category, AutoCompleteDictionary.Item item)
removeFromDictionary
in interface AutoComplete
category
- the item categoryitem
- the itempublic JTextComponent getTextComponent()