net.talvi.puffinplot
Class RecentFileList

java.lang.Object
  extended by net.talvi.puffinplot.RecentFileList

public class RecentFileList
extends java.lang.Object

RecentFileList manages a list of file-sets. It is intended to be used to manage a collection of recently used files for convenient re-opening by a user. Note that each item in the list can comprise multiple files. The length of the list is currently hard-wired to 8, though this would be trivial to change if necessary.

RecentFileList loads and saves its data to a Preferences object, using the keys of the form recentFileX, where X is a non-negative integer less than the maximum number of file-sets.


Constructor Summary
RecentFileList(java.util.prefs.Preferences prefs)
          Creates a new file list, reading data (if any) from the supplied Preferences object.
 
Method Summary
 void add(java.util.List<java.io.File> files)
          Adds a new file-set to the top of the list.
 java.util.List<java.io.File> getFilesAndReorder(int index)
          Returns a specified file-set and moves it to the top of the list.
 java.lang.String[] getFilesetNames()
          Gets a list containing the names of the file-sets in the file list.
 void save(java.util.prefs.Preferences prefs)
          Saves the recent file list to the specified Preferences object.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

RecentFileList

public RecentFileList(java.util.prefs.Preferences prefs)
Creates a new file list, reading data (if any) from the supplied Preferences object. If any recentFile0 (and so on) keys are absent, no error is raised, and the corresponding slots in the file list are left empty.

Parameters:
prefs - the preferences object from which the read file list data
Method Detail

save

public void save(java.util.prefs.Preferences prefs)
Saves the recent file list to the specified Preferences object.

Parameters:
prefs - the Preferences to which to save the recent file list

getFilesetNames

public java.lang.String[] getFilesetNames()
Gets a list containing the names of the file-sets in the file list. The names are expected to be displayed to the user. If a file-set contains only one file, its leafname is used. If it contains more than one file, the leafname of the first file is used, followed by ‘etc.’.

Returns:
the list of file-set names from this recent files list

getFilesAndReorder

public java.util.List<java.io.File> getFilesAndReorder(int index)
Returns a specified file-set and moves it to the top of the list. This method is intended to be called when a user selects a recently used file. It returns the file at a specified index within the list, and (since this file is now the most recently used) moves it to the top of the list.

Parameters:
index - the index of a file-set within the list
Returns:
the requested file-set

add

public void add(java.util.List<java.io.File> files)
Adds a new file-set to the top of the list. If the list is already at its maximum length, the last item will be removed to make room.

Parameters:
files - the files to be added (as a single file-set) to the list