public class TextInputControlSearchable extends Searchable<java.lang.String>
TextComponentSearchable is an concrete implementation of Searchable that enables the search
function in TextInputControl. It's very simple to use it. Assuming you have a TextArea, all you need to do is to call
TextArea textArea = ....;
TextInputControlSearchable searchable = new TextInputControlSearchable(textComponent);
Now the TextInputControl will have the search function.
There is very little customization you need to do to ListSearchable. The only thing you might need is when the element in the TextInputControl needs a special conversion to convert to string. If so, you can override convertElementToString() to provide you own algorithm to do the conversion.
TextArea textArea = ....;
TextInputControlSearchable searchable = new TextInputControlSearchable(textArea) {
protected String convertElementToString(Object object) {
...
}
protected boolean isActivateKey(KeyEvent e) { // change to a different activation key
return ...;
}
};
Additional customization can be done on the base Searchable class such as background and foreground color, keystrokes, case sensitivity.
Due to the special case of TextInputControl, the searching doesn't support wild card '*' or '?' as in other Searchables.
caeSensitiveProperty, fromStartProperty, matchingElementProperty, matchingIndexProperty, popupPositionProperty, popupPositionRelativeToProperty, repeatsProperty, searchingDelayProperty, searchingLabelProperty, searchingProperty, searchingTextProperty, typedTextProperty, wildcardEnabledPropertySearchable.SearchPopup_boundsListener, _keyListener, _node, _visibleListener, PROPERTY_SEARCHABLE| Constructor and Description |
|---|
TextInputControlSearchable(javafx.scene.control.TextInputControl textInputControl) |
| Modifier and Type | Method and Description |
|---|---|
protected void |
addHighlight(int index,
java.lang.String text,
boolean incremental)
Adds highlight to text component at specified index and text.
|
protected java.lang.String |
convertElementToString(java.lang.String element)
Converts the element in TextInputControl to string.
|
int |
findFirst(java.lang.String s)
Finds the first element that matches the searching text.
|
int |
findFromCursor(java.lang.String s)
Finds the next matching index from the cursor.
|
int |
findLast(java.lang.String s)
Finds the last element that matches the searching text.
|
int |
findNext(java.lang.String s)
Finds the next matching index from the cursor.
|
int |
findPrevious(java.lang.String s)
Finds the previous matching index from the cursor.
|
protected java.lang.String |
getElementAt(int index)
Gets the element at the specified index.
|
protected int |
getElementCount()
Gets the total element count in the control.
|
protected int |
getSelectedIndex()
Gets the selected index in the control.
|
void |
hidePopup()
Hides the popup.
|
void |
installListeners()
Installs necessary listeners to the control.
|
protected boolean |
isActivateKey(javafx.scene.input.KeyEvent e)
Checks if the key in KeyEvent should activate the search popup.
|
protected void |
keyTypedOrPressed(javafx.scene.input.KeyEvent e)
This method is called when a key is typed or pressed.
|
protected void |
removeAllHighlights()
Removes all highlights from the text component.
|
int |
reverseFindFromCursor(java.lang.String s)
Finds the previous matching index from the cursor.
|
protected void |
setSelectedIndex(int index,
boolean incremental)
Sets the selected index.
|
void |
showPopup(java.lang.String searchingText)
Shows the search popup.
|
void |
uninstallListeners()
Uninstall the listeners that installed before.
|
adjustSelectedIndex, caeSensitiveProperty, compare, compareAsString, createSearchPopup, findAll, fromStartProperty, getCurrentIndex, getCursor, getElementAtAsString, getHidePopupDelay, getMatchingElement, getMatchingIndex, getNode, getPopupPosition, getPopupPositionRelativeTo, getResourceString, getSearchable, getSearchingDelay, getSearchingText, getSearchLabel, getWildcardSupport, highlightAll, isCaseSensitive, isDeactivateKey, isFindFirstKey, isFindLastKey, isFindNextKey, isFindPreviousKey, isFromStart, isIncrementalSelectKey, isNavigationKey, isPopupVisible, isRepeats, isReverseOrder, isSearching, isSelectAllKey, isWildcardEnabled, matchingElementProperty, matchingIndexProperty, popupPositionProperty, popupPositionRelativeToProperty, repeatsProperty, searchingDelayProperty, searchingLabelProperty, searchingProperty, searchingTextProperty, select, setCaseSensitive, setCursor, setCursor, setFromStart, setHidePopupDelay, setMatchingElement, setMatchingIndex, setPopupPosition, setPopupPositionRelativeTo, setRepeats, setReverseOrder, setSearching, setSearchingDelay, setSearchingText, setSearchLabel, setWildcardEnabled, setWildcardSupport, typedTextProperty, wildcardEnabledPropertypublic TextInputControlSearchable(javafx.scene.control.TextInputControl textInputControl)
public void installListeners()
SearchableinstallListeners in class Searchable<java.lang.String>public void uninstallListeners()
SearchableuninstallListeners in class Searchable<java.lang.String>protected void keyTypedOrPressed(javafx.scene.input.KeyEvent e)
SearchablekeyTypedOrPressed in class Searchable<java.lang.String>e - the KeyEvent.protected void setSelectedIndex(int index,
boolean incremental)
SearchablesetSelectedIndex in class Searchable<java.lang.String>index - the index to be selectedincremental - a flag to enable multiple selection. If the flag is true, the element at the index should be
added to current selection. If false, you should clear previous selection and then select the
element.protected void addHighlight(int index,
java.lang.String text,
boolean incremental)
index - the index of the text to be highlightedtext - the text to be highlightedincremental - if this is an incremental adding highlightprotected void removeAllHighlights()
protected int getSelectedIndex()
SearchableHere are some examples. In the case of ListView, the index is the row index. In the case of TreeView, the index is the row index too. In the case of TableView, depending on the selection mode, the index could be row index (in row selection mode), or could be the cell index (in cell selection mode).
getSelectedIndex in class Searchable<java.lang.String>protected java.lang.String getElementAt(int index)
SearchablegetElementAt in class Searchable<java.lang.String>index - the indexprotected int getElementCount()
SearchablegetElementCount in class Searchable<java.lang.String>protected java.lang.String convertElementToString(java.lang.String element)
toString() of
whatever element that returned from list.getModel().getElementAt(i).convertElementToString in class Searchable<java.lang.String>element - the element to be convertedprotected boolean isActivateKey(javafx.scene.input.KeyEvent e)
SearchableisActivateKey in class Searchable<java.lang.String>e - the key eventpublic int findLast(java.lang.String s)
SearchablefindLast in class Searchable<java.lang.String>s - the searching textpublic int findFirst(java.lang.String s)
SearchablefindFirst in class Searchable<java.lang.String>s - the searching textpublic int findFromCursor(java.lang.String s)
SearchablefindFromCursor in class Searchable<java.lang.String>s - the searching textpublic int reverseFindFromCursor(java.lang.String s)
SearchablereverseFindFromCursor in class Searchable<java.lang.String>s - the searching textpublic int findNext(java.lang.String s)
SearchablefindNext in class Searchable<java.lang.String>s - the searching textpublic int findPrevious(java.lang.String s)
SearchablefindPrevious in class Searchable<java.lang.String>s - the searching textpublic void showPopup(java.lang.String searchingText)
SearchableshowPopup in class Searchable<java.lang.String>searchingText - the searching textpublic void hidePopup()
SearchablehidePopup in class Searchable<java.lang.String>