dsto.dfc.swing.persistence
Class FileDocument

java.lang.Object
  extended by dsto.dfc.util.BasicPropertyEventSource
      extended by dsto.dfc.swing.persistence.AbstractDocument
          extended by dsto.dfc.swing.persistence.FileDocument
All Implemented Interfaces:
Document, Copyable, Disposable, JavaBean, PropertyEventSource, PropertyChangeListener, Serializable, Cloneable, EventListener, ChangeListener

public abstract class FileDocument
extends AbstractDocument

A base class for documents that are file-based. The default implementations of readModel(java.lang.Object) and writeModel(java.lang.Object, java.lang.Object) use the Deserializer and Serializer classes, but these may be overridden to provide other serialization mechanisms.

Version:
$Revision$
Author:
Matthew Phillips
See Also:
Serialized Form

Field Summary
protected  File file
           
protected  SerializedFormat format
           
 
Fields inherited from class dsto.dfc.swing.persistence.AbstractDocument
changed
 
Constructor Summary
FileDocument()
           
 
Method Summary
protected abstract  Object createModelInstance()
          Return a new model instance.
protected  void customizeChooser(String mode, JFileChooser chooser)
          Customize a file chooser before it is displayed.
protected  void customizeFileFilter(ExtensionFileFilter filter)
          Customize the default file filter used in file choosers.
protected abstract  String getDefaultExtension()
          The default extension to apply to files with no explicit extension.
 File getFile()
           
protected  Object getLocation()
           
 String getName()
          Returns the file name without extension if one is set.
abstract  String getType()
          The type of document eg "Spreadsheet".
 Object newModel()
          Create a new, empty model and set it as the document's model.
protected  Object readModel(Object location)
          Read a model using Deserializer.
protected  Object selectLocation(String mode)
          Prompt the user for a location (probably in a persistent storage system) to save the model in.
 void setFile(File newValue)
           
protected  void setLocation(Object newValue)
          The abstract location in persistent storage where the document is to be saved.
protected  void writeModel(Object location, Object theModel)
          Write a model using Serializer.
 
Methods inherited from class dsto.dfc.swing.persistence.AbstractDocument
basicSetModel, checkSaveChanges, dispose, getClient, getModel, handleOpenError, handleSaveError, isChanged, isLocationSelected, modelPropertyChanged, modelStateChanged, open, propertyChange, registerModelListener, save, saveAs, setChanged, setModel, stateChanged, unregisterModelListener, write
 
Methods inherited from class dsto.dfc.util.BasicPropertyEventSource
addPropertyChangeListener, clone, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, firePropertyChange, getPropertyChangeSource, removePropertyChangeListener, setPropertyChangeSource
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 
Methods inherited from interface dsto.dfc.util.PropertyEventSource
addPropertyChangeListener, removePropertyChangeListener
 

Field Detail

file

protected File file

format

protected SerializedFormat format
Constructor Detail

FileDocument

public FileDocument()
Method Detail

createModelInstance

protected abstract Object createModelInstance()
Description copied from class: AbstractDocument
Return a new model instance.

Specified by:
createModelInstance in class AbstractDocument

getDefaultExtension

protected abstract String getDefaultExtension()
The default extension to apply to files with no explicit extension.


getType

public abstract String getType()
Description copied from interface: Document
The type of document eg "Spreadsheet".

Specified by:
getType in interface Document
Specified by:
getType in class AbstractDocument

getFile

public File getFile()

setFile

public void setFile(File newValue)

customizeChooser

protected void customizeChooser(String mode,
                                JFileChooser chooser)
Customize a file chooser before it is displayed. May be overridden.


customizeFileFilter

protected void customizeFileFilter(ExtensionFileFilter filter)
Customize the default file filter used in file choosers.


setLocation

protected void setLocation(Object newValue)
Description copied from class: AbstractDocument
The abstract location in persistent storage where the document is to be saved.

Specified by:
setLocation in class AbstractDocument

getLocation

protected Object getLocation()
Specified by:
getLocation in class AbstractDocument

selectLocation

protected Object selectLocation(String mode)
Description copied from class: AbstractDocument
Prompt the user for a location (probably in a persistent storage system) to save the model in. This location will be passed to AbstractDocument.readModel(java.lang.Object), AbstractDocument.writeModel(java.lang.Object, java.lang.Object) and AbstractDocument.setLocation(java.lang.Object).

Specified by:
selectLocation in class AbstractDocument
Parameters:
mode - The mode the selection is being made in: either "Open" or "Save".
Returns:
A 'location' object, pointing to the selected storage location. Null indicates no location was selected.

readModel

protected Object readModel(Object location)
                    throws IOException
Read a model using Deserializer. May be overridden to enable alternative deserialization mechanism.

Specified by:
readModel in class AbstractDocument
Parameters:
location - The location the persistent store to read from.
Returns:
The new model read from the store. Returning null indicates that the operation usually open ()) should be cancelled.
Throws:
IOException - if an error occurred while reading the model.
See Also:
AbstractDocument.selectLocation(java.lang.String)

writeModel

protected void writeModel(Object location,
                          Object theModel)
                   throws IOException
Write a model using Serializer. May be overridden to enable alternative serialization mechanism.

Specified by:
writeModel in class AbstractDocument
Parameters:
location - The location the persistent store to write to.
theModel - The model to write.
Throws:
IOException - if an error occurred while writing the model.
See Also:
AbstractDocument.selectLocation(java.lang.String)

newModel

public Object newModel()
Description copied from interface: Document
Create a new, empty model and set it as the document's model.

Specified by:
newModel in interface Document
Overrides:
newModel in class AbstractDocument
Returns:
The new model.

getName

public String getName()
Returns the file name without extension if one is set.



Copyright © 2008 Commonwealth of Australia