Searchable is such a class that can make JList, JTable and JTree searchable.
User can simply type in any string they want to search for and use arrow keys to navigate
to next or previous occurrence.
Searchable is a base abstract class. ListSearchable, TableSearchable and TreeSearchable
are implementations to make JList, JTable and JTree searchable respectively. For each implementation, there are
five methods need to be implemented.
protected abstract int getSelectedIndex()
protected abstract void setSelectedIndex(int index, boolean incremental)
protected abstract int getElementCount()
protected abstract Object getElementAt(int index)
protected abstract String convertElementToString(Object element)
Searchable. All you need to do
is to override compare(String, String) method
and implement by yourself.
As this is an abstract class, please refer to to javadoc of ListSearchable , TreeSearchable , and TableSearchable to find out
how to use it with JList, JTree and JTable respectively.
This component has a timer. If user types very fast, it will accumulate them together and generate only one searching action.
The timer can be controlled by setSearchingDelay(int) .
By default we will use lightweight popup for the sake of performance. But if you use heavyweight component
which could obscure the lightweight popup, you can call setHeavyweightComponentEnabled(boolean) to true
so that heavyweight popup will be used. | Nested Class Summary | |
|---|---|
| protected class |
|
|
|
|
| Field Summary | |
|---|---|
| protected EventListenerList |
A list of event listeners for this component. |
| static String |
No description provided. |
| protected JComponent |
No description provided. |
| protected ComponentAdapter |
No description provided. |
| Constructor Summary |
|---|
|
Creates a Searchable. |
|
Creates a Searchable. |
| Method Summary | |
|---|---|
| void |
Adds the property change listener. |
| void |
Adds the specified listener to receive searchable events from this searchable. |
| protected boolean |
Checks if the element matches the searching text. |
| protected boolean |
Checks if the element string matches the searching text. |
| protected String |
Converts the element that returns from getElementAt() to string. |
| protected Searchable.SearchPopup |
Creates the popup to hold the searching text. |
| int |
Finds the first element that matches the searching text. |
| int |
Finds the next matching index from the cursor. |
| int |
Finds the last element that matches the searching text. |
| int |
Finds the next matching index from the cursor. |
| int |
Finds the previous matching index from the cursor. |
| void |
No description provided. |
| protected void |
Fires a searchable event. |
| Color |
Gets the background color used inn the search popup. |
| Component |
Gets the actual component which installed this Searchable. |
| int |
Gets the cursor which is the index of current location when searching. |
| protected Object |
Gets the element at the specified index. |
| protected int |
Gets the total element count in the component. |
| Color |
Gets the foreground color used inn the search popup. |
| Color |
Gets the foreground color when the searching text doesn't match with any of the elements in the component. |
| int |
Gets the popup location. |
| Component |
Gets the component that the location of the popup relative to. |
| protected String |
Gets the localized string from resource bundle. |
| SearchableListener[] |
Returns an array of all the SearchableListeners added
to this SearchableGroup with
addSearchableListener.
|
| SearchableProvider |
No description provided. |
| int |
If it returns a positive number, it will wait for that many ms before doing the search. |
| String |
Gets the searching text. |
| String |
Gets the current text that appears in the search popup. |
| protected int |
Gets the selected index in the component. |
| void |
Hides the popup. |
| void |
Installs necessary listeners to the component. |
| protected boolean |
Checks if the key in KeyEvent should activate the search popup. |
| boolean |
Checks if the case is sensitive during searching. |
| protected boolean |
Checks if the key in KeyEvent should hide the search popup. |
| protected boolean |
Checks if the key is used as a key to find the first occurence. |
| protected boolean |
Checks if the key is used as a key to find the last occurence. |
| protected boolean |
Checks if the key is used as a key to find the next occurence. |
| protected boolean |
Checks if the key is used as a key to find the previous occurence. |
| boolean |
No description provided. |
| protected boolean |
Checks if the key will trigger incremental selection. |
| protected boolean |
Checks if the key is used as a navigation key. |
| boolean |
Check if the searchable popup is visible. |
| boolean |
Checks if restart from the beginning when searching reaches the end or restart from the end when reaches beginning. |
| boolean |
Checks the searching order. |
| protected boolean |
Checks if the key will trigger selecting all. |
| boolean |
Checks if it supports wildcard in searching text. |
| protected void |
This method is called when a key is typed or pressed. |
| void |
Removes the property change listener. |
| void |
Removes the specified searchable listener so that it no longer receives searchable events. |
| int |
Finds the previous matching index from the cursor. |
| void |
Sets the background color used by popup. |
| void |
Sets the case sensitive flag. |
| void |
Sets the cursor which is the index of current location when searching. |
| void |
Sets the foreground color used by popup. |
| void |
No description provided. |
| void |
Sets the foreground for mismatch. |
| void |
Sets the popup location. |
| void |
Sets the location of the popup relative to the specified component. |
| void |
Sets the repeat flag. |
| void |
Sets the searching order. |
| void |
No description provided. |
| void |
If this flag is set to a positive number, it will wait for that many ms before doing the search. |
| void |
Sets the text that appears in the search popup. |
| protected void |
Sets the selected index. |
| void |
Enable or disable the usage of wildcard. |
| void |
Shows the search popup. |
| void |
Uninstall the listeners that installed before. |
| Methods inherited from java.langObject |
|---|
public
int
getCursor
(
)
protected
int
getElementCount
(
)
public
int
getPopupLocation
(
)
SearchableListeners added
to this SearchableGroup with
addSearchableListener.
public
int
getSearchingDelay
(
)
protected
int
getSelectedIndex
(
)
Here are some examples. In the case of JList, the index is the row index. In the case of JTree, the index is the row index too. In the case of JTable, depending on the seleection mode, the index could be row index (in row selection mode), could be column index (in column selection mode) or could the cell index (in cell selection mode).
public
void
installListeners
(
)
public
boolean
isCaseSensitive
(
)
public
boolean
isPopupVisible
(
)
public
boolean
isRepeats
(
)
public
boolean
isReverseOrder
(
)
public
boolean
isWildcardEnabled
(
)
public
void
setCaseSensitive
(
boolean
caseSensitive
)
public
void
setCursor
(
int
cursor
)
public
void
setHeavyweightComponentEnabled
(
boolean
heavyweightComponentEnabled
)
public
void
setRepeats
(
boolean
repeats
)
public
void
setReverseOrder
(
boolean
reverseOrder
)
public
void
setSearchingDelay
(
int
searchingDelay
)
protected
void
setSelectedIndex
(
int
index,
boolean
incremental
)
public
void
setWildcardEnabled
(
boolean
wildcardEnabled
)
public
void
uninstallListeners
(
)