gov.sns.tools.apputils.files
Class RecentFileTracker

java.lang.Object
  |
  +--gov.sns.tools.apputils.files.RecentFileTracker

public class RecentFileTracker
extends java.lang.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.


Field Summary
protected static int DEFAULT_BUFFER_SIZE
           
protected  java.lang.String PREFERENCE_ID
           
protected  java.util.prefs.Preferences PREFS
           
protected  int RECENT_URLS_BUFFER_SIZE
           
 
Constructor Summary
RecentFileTracker(java.lang.Class preferenceNode, java.lang.String preferenceID)
          Constructor with a default buffer size of 10
RecentFileTracker(int bufferSize, java.lang.Class preferenceNode, java.lang.String preferenceID)
          Constructor which generates the preferences from teh specified preference node
RecentFileTracker(int bufferSize, java.util.prefs.Preferences prefs, java.lang.String preferenceID)
          Primary constructor
 
Method Summary
 javax.swing.JFileChooser applyRecentFolder(javax.swing.JFileChooser fileChooser)
          Set the file chooser's current directory to the recent folder.
 void cacheURL(java.io.File file)
          Cache the URL of the specified file.
 void cacheURL(java.lang.String urlSpec)
          Cache the URL
 void cacheURL(java.net.URL url)
          Cache the URL.
 void clearCache()
          Clear the cache of the recent URL specs
 java.io.File getRecentFolder()
          Get the folder corresponding to the most recently cached URL.
 java.lang.String getRecentFolderPath()
          Get the folder path corresponding to the most recently cached URL.
 java.lang.String[] getRecentURLSpecs()
          Get the array of URLs corresponding to recently registered URLs.
protected static java.lang.String[] getTokens(java.lang.String string)
          Parse a string into tokens where whitespace is the delimiter.
protected static java.lang.String[] getTokens(java.lang.String string, java.lang.String delim)
          Parse a string into tokens with the specified delimiter.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

DEFAULT_BUFFER_SIZE

protected static final int DEFAULT_BUFFER_SIZE
See Also:
Constant Field Values

RECENT_URLS_BUFFER_SIZE

protected final int RECENT_URLS_BUFFER_SIZE

PREFS

protected final java.util.prefs.Preferences PREFS

PREFERENCE_ID

protected final java.lang.String PREFERENCE_ID
Constructor Detail

RecentFileTracker

public RecentFileTracker(int bufferSize,
                         java.util.prefs.Preferences prefs,
                         java.lang.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,
                         java.lang.Class preferenceNode,
                         java.lang.String preferenceID)
Constructor which generates the preferences from teh 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(java.lang.Class preferenceNode,
                         java.lang.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 Detail

clearCache

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


cacheURL

public void cacheURL(java.io.File file)
Cache the URL of the specified file.

Parameters:
file - the file whose URL is to be cached.

cacheURL

public void cacheURL(java.net.URL url)
Cache the URL.

Parameters:
url - the URL to cache.

cacheURL

public void cacheURL(java.lang.String urlSpec)
Cache the URL

Parameters:
urlSpec - the URL Spec to cache.

getRecentURLSpecs

public java.lang.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 java.io.File getRecentFolder()
Get the folder corresponding to the most recently cached URL.

Returns:
the most recent folder accessed

getRecentFolderPath

public java.lang.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

applyRecentFolder

public javax.swing.JFileChooser applyRecentFolder(javax.swing.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)

getTokens

protected static java.lang.String[] getTokens(java.lang.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 java.lang.String[] getTokens(java.lang.String string,
                                              java.lang.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.