Class RecentFileTracker

java.lang.Object
xal.tools.apputils.files.RecentFileTracker

public class RecentFileTracker extends Object
RecentFileTracker caches recently accessed files into the the user's preferences and has accessors for getting the recent files and the most recent folder.
Author:
tap
  • Field Details

    • DEFAULT_BUFFER_SIZE

      protected static final int DEFAULT_BUFFER_SIZE
      default buffer size for a tracker
      See Also:
    • recentUrlsBufferSize

      protected final int recentUrlsBufferSize
      buffer size for this tracker
    • prefs

      protected final Preferences prefs
      preferences storage
    • preferenceId

      protected final String preferenceId
      ID for the preferences
  • Constructor Details

    • RecentFileTracker

      public RecentFileTracker(int bufferSize, Preferences prefs, String preferenceID)
      Primary constructor
      Parameters:
      bufferSize - the buffer size of the recent URL specs to cache
      prefs - the preferences used to save the cache of recent URL specs
      preferenceID - the ID of the preference to save
    • RecentFileTracker

      public RecentFileTracker(int bufferSize, Class<?> preferenceNode, String preferenceID)
      Constructor which generates the preferences from the specified preference node
      Parameters:
      bufferSize - the buffer size of the recent URL specs to cache
      preferenceNode - the node used for saving the preference
      preferenceID - the ID of the preference to save
    • RecentFileTracker

      public RecentFileTracker(Class<?> preferenceNode, String preferenceID)
      Constructor with a default buffer size of 10
      Parameters:
      preferenceNode - the node used for saving the preference
      preferenceID - the ID of the preference to save
  • Method Details

    • clearCache

      public void clearCache()
      Clear the cache of the recent URL specs
    • cacheURL

      public void cacheURL(File file)
      Cache the URL of the specified file.
      Parameters:
      file - the file whose URL is to be cached.
    • cacheURL

      public void cacheURL(URL url)
      Cache the URL.
      Parameters:
      url - the URL to cache.
    • cacheURL

      public void cacheURL(String urlSpec)
      Cache the URL
      Parameters:
      urlSpec - the URL Spec to cache.
    • getRecentURLSpecs

      public String[] getRecentURLSpecs()
      Get the array of URLs corresponding to recently registered URLs. Fetch the recent items from the list saved in the user's preferences for the preference node.
      Returns:
      The array of recent URLs.
    • getRecentFolder

      public File getRecentFolder()
      Get the folder corresponding to the most recently cached URL.
      Returns:
      the most recent folder accessed
    • getRecentFolderPath

      public String getRecentFolderPath()
      Get the folder path corresponding to the most recently cached URL.
      Returns:
      path to the most recent folder accessed or null if none has been accessed
    • getMostRecentFile

      public File getMostRecentFile()
      Get the most recent file
      Returns:
      the most recently accessed file.
    • applyRecentFolder

      public JFileChooser applyRecentFolder(JFileChooser fileChooser)
      Set the file chooser's current directory to the recent folder.
      Parameters:
      fileChooser - the file chooser for which to set the current directory
      Returns:
      the file chooser (same as the argument)
    • applyMostRecentFile

      public JFileChooser applyMostRecentFile(JFileChooser fileChooser)
      Set the file chooser's selected file to the most recent file.
      Parameters:
      fileChooser - the file chooser for which to set the current directory
      Returns:
      the file chooser (same as the argument)
    • getTokens

      protected static String[] getTokens(String string)
      Parse a string into tokens where whitespace is the delimiter.
      Parameters:
      string - The string to parse.
      Returns:
      The array of tokens.
    • getTokens

      protected static String[] getTokens(String string, String delim)
      Parse a string into tokens with the specified delimiter.
      Parameters:
      string - The string to parse.
      delim - The delimiter
      Returns:
      The array of tokens.