public class RecentSearches extends Object implements ActionListener
Preferences
. A recent searches popup menu can be installed on
a JXSearchField
using #install(JXSearchField)
.Modifier and Type | Class and Description |
---|---|
static class |
RecentSearches.RecentSearchesPopup
The popup menu returned by
RecentSearches#createPopupMenu(JXSearchField) . |
Constructor and Description |
---|
RecentSearches(Preferences prefs,
String saveName)
Creates a list of recent searches and uses
saveName to
persist this list under the prefs node. |
RecentSearches(String saveName)
Creates a list of recent searches and uses
saveName to
persist this list under the Preferences user root node. |
Modifier and Type | Method and Description |
---|---|
void |
actionPerformed(ActionEvent e)
Calls
put(String) with the ActionEvent s action command
as the search string. |
void |
addChangeListener(ChangeListener l)
Add a change listener.
|
protected JPopupMenu |
createPopupMenu(JTextField searchField)
Creates the recent searches popup menu which will be used by
#install(JXSearchField) to set a search popup menu on
searchField . |
ChangeListener[] |
getChangeListeners()
Returns all registered
ChangeListener s. |
int |
getLength()
The number of recent searches.
|
int |
getMaxRecents()
Returns the maximum number of recent searches.
|
String[] |
getRecentSearches()
Returns all recent searches in this list.
|
void |
install(JTextField searchField)
Install a recent the searches popup menu returned by
#createPopupMenu(JXSearchField) on searchField . |
void |
put(String searchString)
Add a search string as the first element.
|
void |
removeAll()
Remove all recent searches.
|
void |
removeChangeListener(ChangeListener l)
Remove a change listener.
|
void |
setMaxRecents(int maxRecents)
Set the maximum number of recent searches.
|
void |
uninstall(JXSearchField searchField)
Remove the recent searches popup from
searchField when
installed and stop listening for ActionEvent s fired by the
search field. |
public RecentSearches(String saveName)
saveName
to
persist this list under the Preferences
user root node. Existing
entries will be loaded automatically.saveName
- a unique name for saving this list of recent searchespublic RecentSearches(Preferences prefs, String saveName)
saveName
to
persist this list under the prefs
node. Existing entries
will be loaded automatically.prefsNode
- the preferences node under which this list will be persisted.
If prefsNode is null
the preferences node will
be set to the user root nodesaveName
- a unique name for saving this list of recent searches. If
saveName is null
, the list will not be
persistedpublic void put(String searchString)
null
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.searchString
- the search string to addgetMaxRecents()
public String[] getRecentSearches()
public int getLength()
public void removeAll()
public int getMaxRecents()
put(String)
public void setMaxRecents(int maxRecents)
maxRecents
- maximum number of recent searchesput(String)
public void addChangeListener(ChangeListener l)
ChangeEvent
will be fired whenever a
search is added or removed.l
- the ChangeListener
public void removeChangeListener(ChangeListener l)
l
- a registered ChangeListener
public ChangeListener[] getChangeListeners()
ChangeListener
s.ChangeListener
sprotected JPopupMenu createPopupMenu(JTextField searchField)
#install(JXSearchField)
to set a search popup menu on
searchField
.
Override to return a custom popup menu.searchField
- the search field the returned popup menu will be installed onpublic void install(JTextField searchField)
#createPopupMenu(JXSearchField)
on searchField
.
Also registers an ActionListener
on searchField
and adds the search string to the list of recent searches whenever a
ActionEvent
is received.
Uses NativeSearchFieldSupport
to achieve compatibility with the native
search field support provided by the Mac Look And Feel since Mac OS 10.5.searchField
- the search field to install a recent searches popup menu onpublic void uninstall(JXSearchField searchField)
searchField
when
installed and stop listening for ActionEvent
s fired by the
search field.searchField
- uninstall recent searches popup menupublic void actionPerformed(ActionEvent e)
put(String)
with the ActionEvent
s action command
as the search string.actionPerformed
in interface ActionListener
Copyright © 2016. All rights reserved.