public class RecentFiles
extends java.lang.Object
Modifier and Type | Field and Description |
---|---|
private java.util.Queue<java.lang.String> |
filePaths |
private static java.lang.String |
HISTORY_LENGTH |
private static java.lang.String |
KEY |
private int |
maximum |
private static java.lang.String |
PATH_KEY |
private static java.lang.String |
PIECES_LENGTH_KEY |
private java.util.prefs.Preferences |
pref |
Constructor and Description |
---|
RecentFiles(java.lang.Class className,
int maximumFile)
Constructor.
|
Modifier and Type | Method and Description |
---|---|
void |
addFile(java.lang.String path)
Add a new file in recent file history.
|
private java.lang.String[] |
breakString(java.lang.String fullPath) |
void |
close()
This method save the present recent file history in the preference.
|
java.util.List<java.lang.String> |
getFiles()
This gives the file in descending order where order is according to the time it is added.
|
boolean |
isEmpty()
Check if file history is empty.
|
private java.util.Queue<java.lang.String> |
readHistoryFromPref() |
void |
removeAll()
Clear the previous recent file history.
|
void |
removeFile(java.lang.String path)
Remove a file from recent file history.
|
private void |
writeHistoryToPref(java.util.Queue<java.lang.String> filePaths) |
private static final java.lang.String KEY
private static final java.lang.String PATH_KEY
private static final java.lang.String PIECES_LENGTH_KEY
private static final java.lang.String HISTORY_LENGTH
private final java.util.prefs.Preferences pref
private java.util.Queue<java.lang.String> filePaths
private final int maximum
public RecentFiles(java.lang.Class className, int maximumFile)
className
- the class for which this Recentfiles object is created and it will be used
to create preference instance.maximumFile
- the number of recent files to remember.public void removeAll()
public boolean isEmpty()
public void addFile(java.lang.String path)
path
- path to the file. this path means File#getPath() method returned String.public void removeFile(java.lang.String path)
path
- path string to the file. this path means File#getPath() method returned String.public java.util.List<java.lang.String> getFiles()
public void close() throws java.io.IOException
java.io.IOException
- if saving in preference doesn't success.private java.lang.String[] breakString(java.lang.String fullPath)
private void writeHistoryToPref(java.util.Queue<java.lang.String> filePaths)
private java.util.Queue<java.lang.String> readHistoryFromPref()