public class FileSaver extends Object implements IFileSaver, EventListener
Modifier and Type | Field and Description |
---|---|
String |
defaultExtension
This is the default extension for the file name.
|
protected String |
defaultFileName |
boolean |
dontAppendLineFeed
This applies for saving text.
|
Exception |
exception
This is set to any exception that may have occured during loading/saving.
|
File |
fileModel
This is the file model to use.
|
boolean |
hasChanged
This says whether the current file has been changed.
|
boolean |
ignoreParentObject
Set this true to always ignore the parent Object and have all new Objects appear in
their own window.
|
String |
lastSaved
This is the last file that was saved.
|
Vector |
masks
This is a list of masks to be sent to the FileChooser.
|
String |
openTitle
This is the title of the file open box.
|
String |
persistentHistoryKey
This is assigned to the persistentHistoryKey of the FileChooser created.
|
boolean |
reportIOErrors
If this is true then any IO errors encountered during doSave() or doOpen()
is reported.
|
String |
saveTitle
This is the title of the file save box.
|
TextCodec |
textCodec
You can set this to a textCodec to use for reading and writing text data using this FileSaver.
|
Constructor and Description |
---|
FileSaver() |
FileSaver(String defaultFileName) |
FileSaver(String defaultFileName,
String actualFileName) |
Modifier and Type | Method and Description |
---|---|
boolean |
checkExit(Form f,
Object dataToSave,
int retCode)
A Form can call this when the user has requested to close the Form.
|
boolean |
checkSave(Object data,
Object parent)
If hasChanged is true, this will attempt to save the current object by prompting
the user to confirm saving changes.
|
protected boolean |
closeAndReturn(String fileName,
Object parent,
OutputStream s,
boolean success) |
void |
doOpen(Object toOpen,
String fileName,
Object parent)
This attempts an open operation on the data - and you should override this
as necessary.
|
void |
doSave(Object toSave,
String fileName,
Object parent)
This attempts a save operation on the data - and you should override this
as necessary.
|
protected String |
errorString(String file,
boolean forInput) |
protected boolean |
exec(File fileModel,
FileChooserParameters fcp) |
Exception |
getException() |
protected FileChooserParameters |
getFileChooser(String type,
String initial,
File model) |
boolean |
getHasChanged() |
String |
getInitialFile() |
protected InputStream |
getInputStream(String fileName,
Object parent)
This creates a Stream to read from to the source file name.
|
String |
getLastSaved() |
protected OutputStream |
getOutputStream(String fileName,
Object parent)
This creates a Stream to write to the destination file name.
|
PropertyList |
getProperties()
Get the PropertyList object associated with this object.
|
File |
getSavedFile()
This returns the last saved or opened File.
|
boolean |
newData(Object oldData,
String newFileName,
Object parent)
This tells the FileSaver that new data is about to be created and
that the old data should be saved if it has been changed. newFileName
can be null to say that the new data is as yet unnamed.
|
void |
newData(String newFileName)
This sets hasChanged to false and lastSaved to newFileName.
|
void |
onEvent(Event ev) |
String |
open(Object parent)
This brings up a FileChooser box to let the user select a file to open.
|
boolean |
open(Object oldData,
Object newData,
Object parent)
This attempts to open a file, after saving the old file if necessary.
|
String |
open(String oldData,
Object parent)
This opens and reads the file as a string.
|
String |
openText(String fileName,
Object parent) |
protected void |
report(IOException e,
Object parent,
String message) |
protected void |
report(IOException e,
Object parent,
String fileName,
boolean forInput) |
boolean |
save(boolean saveAs,
Object data,
Object parent)
This attempts to save the file.
|
String |
save(Object parent)
This returns a String which is the file name of the destination to save to.
|
String |
saveAs(Object parent)
This brings up the FileChooser
box and lets the user select a file to save to.
|
void |
setDefaultFileType(String extension,
String description)
This will sets the default file type and adds the mask to the list of masks.
|
void |
setHasChanged(boolean hasChanged) |
void |
setLastSaved(String lastSaved) |
boolean |
tryOpen(Object data,
String file,
Object parent) |
String |
tryOpen(String file,
Object parent)
This checks if the specified file is readable.
|
public File fileModel
public String lastSaved
protected String defaultFileName
public String defaultExtension
public String saveTitle
public String openTitle
public Vector masks
public Exception exception
public String persistentHistoryKey
public boolean ignoreParentObject
public TextCodec textCodec
public boolean dontAppendLineFeed
public boolean hasChanged
public boolean reportIOErrors
public FileSaver()
public FileSaver(String defaultFileName)
public void setDefaultFileType(String extension, String description)
public String save(Object parent)
public String getInitialFile()
protected FileChooserParameters getFileChooser(String type, String initial, File model)
protected boolean exec(File fileModel, FileChooserParameters fcp)
public String saveAs(Object parent)
public String tryOpen(String file, Object parent)
public String open(Object parent)
public void newData(String newFileName)
newData
in interface IFileSaver
public boolean checkSave(Object data, Object parent)
This method return true if:
protected void report(IOException e, Object parent, String message) throws IOException
IOException
protected void report(IOException e, Object parent, String fileName, boolean forInput) throws IOException
IOException
protected OutputStream getOutputStream(String fileName, Object parent) throws IOException
fileName
- The file name to write to.parent
- The parent Object (may be null).IOException
- if no Stream to the file could be created. If reportIOErrors is true, then
the exception will be displayed in a standard exception dialog.protected InputStream getInputStream(String fileName, Object parent) throws IOException
fileName
- The file name to read from.parent
- The parent Object (may be null).IOException
- if no Stream to the file could be created. If reportIOErrors is true, then
the exception will be displayed in a standard exception dialog.protected boolean closeAndReturn(String fileName, Object parent, OutputStream s, boolean success) throws IOException
IOException
public void doSave(Object toSave, String fileName, Object parent) throws IOException
IOException
public void doOpen(Object toOpen, String fileName, Object parent) throws IOException
IOException
public boolean open(Object oldData, Object newData, Object parent) throws IOException
IOException
public String openText(String fileName, Object parent) throws IOException
IOException
public String open(String oldData, Object parent) throws IOException
oldData
- Data to check for saving first (may be null).parent
- The parent Object (may be null).IOException
public boolean save(boolean saveAs, Object data, Object parent)
public boolean newData(Object oldData, String newFileName, Object parent)
newData
in interface IFileSaver
public void onEvent(Event ev)
public boolean checkExit(Form f, Object dataToSave, int retCode)
checkExit
in interface IFileSaver
f
- The Form checking for exit.retCode
- The return code the Form should exit with.public File getSavedFile()
public String getLastSaved()
public boolean getHasChanged()
public Exception getException()
getException
in interface IFileSaver
public void setHasChanged(boolean hasChanged)
setHasChanged
in interface IFileSaver
public void setLastSaved(String lastSaved)
setLastSaved
in interface IFileSaver
public PropertyList getProperties()
HasProperties
getProperties
in interface HasProperties