Recent File Lists

The RecentFileList is a custom group implementation that displays a list of recently used files. This list automatically insert accelerators and can optionally display an entry for clearing the list. The responsibility for opening the files is handled by the open executor. This is just an ActionCommandExecutor that recognises the AbstractFileOpenCommand.FILE_TO_OPEN parameter.

The following shows the RecentFileList in use:

Recent File List
Recent File List Example

The following is an example of using a RecentFileList. We specify an OpenCommand to handle the open operation that recognises the parameter AbstractFileOpenCommand .FILE_TO_OPEN:

   RecentFileList recentFileList = new RecentFileList("recent-files");
   recentFileList.getClearCommand().setVisible(true);

   OpenCommand myOpenCommand = new OpenCommand();
   recentFileList.setOpenExecutor(myOpenCommand);

The list also allows you to specify a list of excluded files that are to be temporarily removed from the list. You typically use this to exclude the currently open file or files.

The list is backed by an instance of RecentFileListModel that can be shared between multiple list instances. The default implementation also supports loading and storing the list to and from a java.util.prefs.Preference node.

The following is an example of using the RecentFileList with a DefaultRecentFileListModel. It configures the list to exclude the current file and demonstrates loading and saving the model from a Preference node:

   // create the model and load the previous list.
   DefaultRecentFileListModel model = new DefaultRecentFileListModel();
   model.load(preferenceNode);

   RecentFileList recentFiles = new RecentFileList("recent-files", model);

   // when the current file changes..
   recentFiles.setExcludedFile(currentFile);

   // and before we exit...
   model.store(preferenceNode);