Package org.jdesktop.swingx.search
Class RecentSearches
java.lang.Object
org.jdesktop.swingx.search.RecentSearches
- All Implemented Interfaces:
ActionListener
,EventListener
Maintains a list of recent searches and persists this list automatically
using
Preferences
. A recent searches popup menu can be installed on
a JXSearchField
using install(JXSearchField)
.- Author:
- Peter Weishapl petw@gmx.net
-
Nested Class Summary
Nested ClassesModifier and TypeClassDescriptionstatic class
The popup menu returned bycreatePopupMenu(JXSearchField)
. -
Constructor Summary
ConstructorsConstructorDescriptionRecentSearches
(String saveName) Creates a list of recent searches and usessaveName
to persist this list under thePreferences
user root node.RecentSearches
(Preferences prefs, String saveName) Creates a list of recent searches and usessaveName
to persist this list under theprefs
node. -
Method Summary
Modifier and TypeMethodDescriptionvoid
Callsput(String)
with theActionEvent
s action command as the search string.void
Add a change listener.protected JPopupMenu
createPopupMenu
(JTextField searchField) Creates the recent searches popup menu which will be used byinstall(JXSearchField)
to set a search popup menu onsearchField
.Returns all registeredChangeListener
s.int
The number of recent searches.int
Returns the maximum number of recent searches.String[]
Returns all recent searches in this list.void
install
(JTextField searchField) Install a recent the searches popup menu returned bycreatePopupMenu(JXSearchField)
onsearchField
.void
Add a search string as the first element.void
Remove all recent searches.void
Remove a change listener.void
setMaxRecents
(int maxRecents) Set the maximum number of recent searches.void
uninstall
(JXSearchField searchField) Remove the recent searches popup fromsearchField
when installed and stop listening forActionEvent
s fired by the search field.
-
Constructor Details
-
RecentSearches
Creates a list of recent searches and usessaveName
to persist this list under thePreferences
user root node. Existing entries will be loaded automatically.- Parameters:
saveName
- a unique name for saving this list of recent searches
-
RecentSearches
Creates a list of recent searches and usessaveName
to persist this list under theprefs
node. Existing entries will be loaded automatically.- Parameters:
prefs
- the preferences node under which this list will be persisted. If prefsNode isnull
the preferences node will be set to the user root nodesaveName
- a unique name for saving this list of recent searches. If saveName isnull
, the list will not be persisted
-
-
Method Details
-
put
Add a search string as the first element. If the search string isnull
or empty nothing will be added. If the search string already exists, the old element will be removed. The modified list will automatically be persisted. If the number of elements exceeds the maximum number of entries, the last entry will be removed.- Parameters:
searchString
- the search string to add- See Also:
-
getRecentSearches
Returns all recent searches in this list.- Returns:
- the recent searches
-
getLength
public int getLength()The number of recent searches.- Returns:
- number of recent searches
-
removeAll
public void removeAll()Remove all recent searches. -
getMaxRecents
public int getMaxRecents()Returns the maximum number of recent searches.- Returns:
- the maximum number of recent searches
- See Also:
-
setMaxRecents
public void setMaxRecents(int maxRecents) Set the maximum number of recent searches.- Parameters:
maxRecents
- maximum number of recent searches- See Also:
-
addChangeListener
Add a change listener. AChangeEvent
will be fired whenever a search is added or removed.- Parameters:
l
- theChangeListener
-
removeChangeListener
Remove a change listener.- Parameters:
l
- a registeredChangeListener
-
getChangeListeners
Returns all registeredChangeListener
s.- Returns:
- all registered
ChangeListener
s
-
createPopupMenu
Creates the recent searches popup menu which will be used byinstall(JXSearchField)
to set a search popup menu onsearchField
. Override to return a custom popup menu.- Parameters:
searchField
- the search field the returned popup menu will be installed on- Returns:
- the recent searches popup menu
-
install
Install a recent the searches popup menu returned bycreatePopupMenu(JXSearchField)
onsearchField
. Also registers anActionListener
onsearchField
and adds the search string to the list of recent searches whenever aActionEvent
is received. UsesNativeSearchFieldSupport
to achieve compatibility with the native search field support provided by the Mac Look And Feel since Mac OS 10.5.- Parameters:
searchField
- the search field to install a recent searches popup menu on
-
uninstall
Remove the recent searches popup fromsearchField
when installed and stop listening forActionEvent
s fired by the search field.- Parameters:
searchField
- uninstall recent searches popup menu
-
actionPerformed
Callsput(String)
with theActionEvent
s action command as the search string.- Specified by:
actionPerformed
in interfaceActionListener
-