com.pietschy.command.file
Class DefaultRecentFileListModel

java.lang.Object
  extended by com.pietschy.command.file.DefaultRecentFileListModel
All Implemented Interfaces:
RecentFileListModel

public class DefaultRecentFileListModel
extends java.lang.Object
implements RecentFileListModel

Default implementation of RecentFileListModel. This implementation provides convenience methods for saving and loading the list from a Preferences node.

See Also:
store(Preferences), load(Preferences)

Constructor Summary
DefaultRecentFileListModel()
          Creates a new empty instance.
DefaultRecentFileListModel(java.util.Collection<java.io.File> files)
          Creates a new instance initialised with the specified list of files.
DefaultRecentFileListModel(java.io.File[] files)
          Creates a new instance initialised with the specified list of files.
 
Method Summary
 void add(java.io.File file)
          Adds the specified file to the model.
 void addAll(java.util.Collection<? extends java.io.File> files)
          Adds all files in the specified collection to the list.
 void addAll(java.io.File[] files)
          Adds all files in the specified array to the list.
 void addFileListModelListener(RecentFileListModeListener listener)
          Adds the specified listener to the model.
 java.util.List<java.io.File> asList()
          Returns the model contents as a list.
 void clear()
          Removes all files from the model.
 boolean contains(java.io.File file)
          Checks if this model contains the specified file.
protected  void fireContentsChanged()
          Notifies listeners that the model has changed.
 java.io.File get(int i)
          Gets the file at the specified index.
protected  int indexOf(java.io.File file)
          Checks the index of the specified file.
 void load(java.util.prefs.Preferences prefs)
          Loads the list of files from the specified preference node.
 void load(java.util.prefs.Preferences prefs, boolean includeNonExistentFiles)
          Loads the list of files from the specified preference node.
 void remove(java.io.File file)
          Removes the specified file from the model.
 void removeAll(java.util.Collection<? extends java.io.File> collection)
          Removes all of the specified files from the model.
 void removeFileListModelListener(RecentFileListModeListener listener)
          Removes the specified listener from the model.
 int size()
          Gets the number of files in the model.
 void store(java.util.prefs.Preferences prefs)
          Stores the list of files to the specified preference node.
 void store(java.util.prefs.Preferences prefs, boolean includeNonExistentFiles)
          Stores the list of files to the specified preference node.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DefaultRecentFileListModel

public DefaultRecentFileListModel(java.util.Collection<java.io.File> files)
Creates a new instance initialised with the specified list of files.

Parameters:
files - the files to use.

DefaultRecentFileListModel

public DefaultRecentFileListModel(java.io.File[] files)
Creates a new instance initialised with the specified list of files.

Parameters:
files - the files to use.

DefaultRecentFileListModel

public DefaultRecentFileListModel()
Creates a new empty instance.

Method Detail

size

public int size()
Gets the number of files in the model.

Specified by:
size in interface RecentFileListModel
Returns:
the number of files in the model.

get

public java.io.File get(int i)
Gets the file at the specified index.

Specified by:
get in interface RecentFileListModel
Parameters:
i - the index.
Returns:
the file at the specified index.

contains

public boolean contains(java.io.File file)
Checks if this model contains the specified file.

Parameters:
file - the file to check.
Returns:
true if the model contains the file, false otherwise.

indexOf

protected int indexOf(java.io.File file)
Checks the index of the specified file.

Parameters:
file - the file to check.
Returns:
the index of the specified file, or -1 if the file isn't in the list.

add

public void add(java.io.File file)
Adds the specified file to the model.

Parameters:
file - the file to add.

addAll

public void addAll(java.io.File[] files)
Adds all files in the specified array to the list.

Parameters:
files - the array of files to add.

addAll

public void addAll(java.util.Collection<? extends java.io.File> files)
Adds all files in the specified collection to the list. The files are added in iteration order.

Parameters:
files - the collection of files to add.

remove

public void remove(java.io.File file)
Removes the specified file from the model.

Parameters:
file - the file to remove.

removeAll

public void removeAll(java.util.Collection<? extends java.io.File> collection)
Removes all of the specified files from the model.

Parameters:
collection - the collection of files to remove.

clear

public void clear()
Removes all files from the model.

Specified by:
clear in interface RecentFileListModel

asList

public java.util.List<java.io.File> asList()
Returns the model contents as a list.

Returns:
the model contents as a list

addFileListModelListener

public void addFileListModelListener(RecentFileListModeListener listener)
Adds the specified listener to the model.

Specified by:
addFileListModelListener in interface RecentFileListModel
Parameters:
listener - the listener to add.

removeFileListModelListener

public void removeFileListModelListener(RecentFileListModeListener listener)
Removes the specified listener from the model.

Specified by:
removeFileListModelListener in interface RecentFileListModel
Parameters:
listener - the listener to remove.

fireContentsChanged

protected void fireContentsChanged()
Notifies listeners that the model has changed.


store

public void store(java.util.prefs.Preferences prefs)
           throws java.util.prefs.BackingStoreException
Stores the list of files to the specified preference node. All non existent files will be discarded from the list.

Parameters:
prefs - the preference node in which to save the groups file list.
Throws:
java.util.prefs.BackingStoreException - if the store operation fails.
See Also:
load(Preferences, boolean)

store

public void store(java.util.prefs.Preferences prefs,
                  boolean includeNonExistentFiles)
           throws java.util.prefs.BackingStoreException
Stores the list of files to the specified preference node.

Parameters:
prefs - the preference node in which to save the groups file list.
includeNonExistentFiles - true to store files that no longer exists, false to only store existings files.
Throws:
java.util.prefs.BackingStoreException - if the store operation fails.
See Also:
load(Preferences, boolean)

load

public void load(java.util.prefs.Preferences prefs)
Loads the list of files from the specified preference node. All non existent files will be discarded from the list.

Parameters:
prefs - the preference node in which to retrieve the groups file list.
See Also:
store(Preferences, boolean)

load

public void load(java.util.prefs.Preferences prefs,
                 boolean includeNonExistentFiles)
Loads the list of files from the specified preference node.

Parameters:
prefs - the preference node in which to retrieve the groups file list.
includeNonExistentFiles - true to load files that no longer exists, false to only load existings files.
See Also:
store(Preferences, boolean)


Copyright © 2006 - 2007 Andrew Pietsch