Class RecentSearches

    • Constructor Detail

      • RecentSearches

        public RecentSearches​(String saveName)
        Creates a list of recent searches and uses saveName to persist this list under the Preferences user root node. Existing entries will be loaded automatically.
        Parameters:
        saveName - a unique name for saving this list of recent searches
      • RecentSearches

        public RecentSearches​(Preferences prefs,
                              String saveName)
        Creates a list of recent searches and uses saveName to persist this list under the prefs node. Existing entries will be loaded automatically.
        Parameters:
        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 node
        saveName - a unique name for saving this list of recent searches. If saveName is null, the list will not be persisted
    • Method Detail

      • put

        public void put​(String searchString)
        Add a search string as the first element. If the search string is 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.
        Parameters:
        searchString - the search string to add
        See Also:
        getMaxRecents()
      • getRecentSearches

        public String[] 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:
        put(String)
      • setMaxRecents

        public void setMaxRecents​(int maxRecents)
        Set the maximum number of recent searches.
        Parameters:
        maxRecents - maximum number of recent searches
        See Also:
        put(String)
      • addChangeListener

        public void addChangeListener​(ChangeListener l)
        Add a change listener. A ChangeEvent will be fired whenever a search is added or removed.
        Parameters:
        l - the ChangeListener
      • removeChangeListener

        public void removeChangeListener​(ChangeListener l)
        Remove a change listener.
        Parameters:
        l - a registered ChangeListener
      • createPopupMenu

        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. 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

        public void install​(JTextField searchField)
        Install a recent the searches popup menu returned by #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.
        Parameters:
        searchField - the search field to install a recent searches popup menu on
      • uninstall

        public void uninstall​(JXSearchField searchField)
        Remove the recent searches popup from searchField when installed and stop listening for ActionEvents fired by the search field.
        Parameters:
        searchField - uninstall recent searches popup menu