|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||
java.lang.Objectjava.awt.event.WindowAdapter
net.sac.ui.FileManager
public class FileManager
FileManager simplifies the process of managing a users open files. FileManager takes care of prompting the user when necessary and provides support for autosaving. To use FileManager, the saved files must consist of a single serializable object (if there are multiple objects that make up a single file, you can either put them into a Collection or create a wrapper class for the objects). inputStreamEquals and fileContentsEquals methods courtesy of Joe Orost (snoopyjc at www.velocityreviews.com).
| Nested Class Summary | |
|---|---|
static class |
FileManager.FileState
|
| Constructor Summary | |
|---|---|
FileManager(javax.swing.JFrame parent)
Construct a new FileManager with the given parent frame. |
|
FileManager(javax.swing.JFrame parent,
boolean multiple)
Construct a new FileManager with the given parent frame. |
|
FileManager(javax.swing.JFrame parent,
boolean multiple,
java.lang.String defaultExtension,
java.lang.String description)
Construct a new FileManager with the given parent frame, setting up a file filter with the given extension and description. |
|
FileManager(javax.swing.JFrame parent,
java.lang.String defaultExtension,
java.lang.String description)
Construct a new FileManager with the given parent frame, and set up a file filter with the given extension and description. |
|
| Method Summary | |
|---|---|
void |
activateOnFileOpen(javax.swing.JMenuItem menuItem)
Add a JMenuItem to be managed by the FileManager; menu item will be enabled when files are open and disabled when no files are open. |
void |
addActiveFileChangeListener(ActiveFileChangeListener listener)
Add an ActiveFileChangeListener to this FileManager. |
void |
autoSave()
auto save any open files to their temporary file names. |
void |
closeDown()
Stop the autosaver if it's active and close all open files. |
java.lang.String |
executeClose()
Close the currently active file. |
boolean |
executeClose(java.lang.String key)
Close the file with given key. |
java.lang.String |
executeNew(java.lang.Object object)
Create a new file using the given object. |
boolean |
executeNew(java.lang.String key,
java.lang.Object object)
Create a new file using the given object and key. |
java.lang.String |
executeOpen()
Open a file chosen by user prompt. |
java.lang.String |
executeOpen(java.io.File file)
Open the given file. |
java.lang.String |
executeOpen(java.lang.String fileName)
|
boolean |
executeOpen(java.lang.String key,
java.io.File file)
Open the given file using the given key. |
boolean |
executeOpen(java.lang.String key,
java.lang.String fileName)
|
boolean |
executeRestore()
Attempt to restore any autosaved files that were previously lost due to an abnormal program termination. |
boolean |
executeSave()
Save the currently active file. |
boolean |
executeSave(java.lang.String key)
Save the file of given key. |
boolean |
executeSaveAs()
Save the currently active file, prompting for file name/location. |
static boolean |
executeSaveAs(javax.swing.JFrame parent,
java.lang.Object object)
Save the given Object, prompting for file name/location. |
static boolean |
executeSaveAs(javax.swing.JFrame parent,
java.lang.Object object,
java.lang.String dialogTitle)
Save the given Object, prompting for file name/location. |
boolean |
executeSaveAs(java.lang.String key)
Save the file with given key, prompting for file name/location. |
java.lang.String |
getFileName()
Get the filename associated with the active open file. |
java.lang.String |
getFileName(java.lang.String key)
Get the filename associated with the file of given key. |
java.lang.Object |
getObject()
Get the object associated with the active open file. |
java.lang.Object |
getObject(java.lang.String key)
Get the object associated with the file of given key. |
int |
getOpenFileCount()
Return a count of the number of currently open files. |
static java.lang.Object |
loadObject(java.io.File file)
Load an Object from the given file. |
static java.lang.Object |
loadObject(java.lang.String fileName)
|
static void |
saveObject(java.io.File file,
java.lang.Object object)
Save an Object to the given file. |
static void |
saveString(java.io.File file,
java.lang.Object object)
Save an Object's String value to the given file. |
void |
setActiveFile(java.lang.String key)
Set which open file is considered to be the active open file using the file's key value. |
void |
setAutosave(boolean autosave)
Turn the autosave feature on or off. |
void |
setAutosaveInterval(long autosaveInterval)
Set the frequency in milliseconds of the autosave feature. |
void |
windowClosed(java.awt.event.WindowEvent event)
|
void |
windowClosing(java.awt.event.WindowEvent event)
|
| Methods inherited from class java.awt.event.WindowAdapter |
|---|
windowActivated, windowDeactivated, windowDeiconified, windowGainedFocus, windowIconified, windowLostFocus, windowOpened, windowStateChanged |
| Methods inherited from class java.lang.Object |
|---|
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait |
| Methods inherited from interface java.awt.event.WindowListener |
|---|
windowActivated, windowDeactivated, windowDeiconified, windowIconified, windowOpened |
| Constructor Detail |
|---|
public FileManager(javax.swing.JFrame parent)
parent - Parent frame
public FileManager(javax.swing.JFrame parent,
java.lang.String defaultExtension,
java.lang.String description)
parent - parent framedefaultExtension - file extension for file filterdescription - description of file filter
public FileManager(javax.swing.JFrame parent,
boolean multiple)
parent - Parent framemultiple - Whether or not to allow multiple files to be open simultaneously
public FileManager(javax.swing.JFrame parent,
boolean multiple,
java.lang.String defaultExtension,
java.lang.String description)
parent - parent framemultiple - whether or not to allow multiple files to be open simultaneouslydefaultExtension - file extension for file filterdescription - description for file filter| Method Detail |
|---|
public void addActiveFileChangeListener(ActiveFileChangeListener listener)
listener - public void setAutosaveInterval(long autosaveInterval)
autosaveInterval - frequency (in milliseconds) of auto savepublic void setAutosave(boolean autosave)
autosave - true == on, false == offpublic int getOpenFileCount()
public void setActiveFile(java.lang.String key)
key - public java.lang.Object getObject()
public java.lang.Object getObject(java.lang.String key)
key - key associated with file
public java.lang.String getFileName()
public java.lang.String getFileName(java.lang.String key)
key - key of file
public boolean executeRestore()
throws java.io.IOException
java.io.IOException
public java.lang.String executeNew(java.lang.Object object)
throws java.io.IOException
object - object associated with new file
java.io.IOException
public boolean executeNew(java.lang.String key,
java.lang.Object object)
throws java.io.IOException
key - key to associate with new fileobject - object associated with new file
java.io.IOException
public java.lang.String executeOpen()
throws java.io.IOException
java.io.IOException
public java.lang.String executeOpen(java.lang.String fileName)
throws java.io.IOException
java.io.IOException
public boolean executeOpen(java.lang.String key,
java.lang.String fileName)
throws java.io.IOException
java.io.IOException
public java.lang.String executeOpen(java.io.File file)
throws java.io.IOException
file -
java.io.IOException
public boolean executeOpen(java.lang.String key,
java.io.File file)
throws java.io.IOException
key - file -
java.io.IOException
public boolean executeSave()
throws java.io.IOException
java.io.IOException
public boolean executeSave(java.lang.String key)
throws java.io.IOException
key - key of file to save
java.io.IOException
public static boolean executeSaveAs(javax.swing.JFrame parent,
java.lang.Object object,
java.lang.String dialogTitle)
throws java.io.IOException
parent - parent frameobject - object to save to filedialogTitle - title for file chooser dialog window
java.io.IOException
public static boolean executeSaveAs(javax.swing.JFrame parent,
java.lang.Object object)
throws java.io.IOException
parent - parent frameobject - object to save to file
java.io.IOException
public boolean executeSaveAs()
throws java.io.IOException
java.io.IOException
public boolean executeSaveAs(java.lang.String key)
throws java.io.IOException
key - key of file to save
java.io.IOException
public boolean executeClose(java.lang.String key)
throws java.io.IOException
key - key of file to close
java.io.IOException
public java.lang.String executeClose()
throws java.io.IOException
java.io.IOException
public static java.lang.Object loadObject(java.io.File file)
throws java.io.IOException
file -
java.io.IOException
public static void saveObject(java.io.File file,
java.lang.Object object)
throws java.io.IOException
file - object -
java.io.IOException
public static void saveString(java.io.File file,
java.lang.Object object)
throws java.io.IOException
file - object -
java.io.IOException
public static java.lang.Object loadObject(java.lang.String fileName)
throws java.io.IOException
java.io.IOExceptionpublic void autoSave()
autoSave in interface AutoSavablepublic void closeDown()
public void activateOnFileOpen(javax.swing.JMenuItem menuItem)
menuItem - menu item to be managedpublic void windowClosed(java.awt.event.WindowEvent event)
windowClosed in interface java.awt.event.WindowListenerwindowClosed in class java.awt.event.WindowAdapterpublic void windowClosing(java.awt.event.WindowEvent event)
windowClosing in interface java.awt.event.WindowListenerwindowClosing in class java.awt.event.WindowAdapter
|
||||||||||
| PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
| SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD | |||||||||