JHotDraw 6.0b1

org.jhotdraw.util
Class StandardStorageFormat

java.lang.Object
  extended by org.jhotdraw.util.StandardStorageFormat
All Implemented Interfaces:
StorageFormat
Direct Known Subclasses:
SerializationStorageFormat, SVGStorageFormat

public class StandardStorageFormat
extends java.lang.Object
implements StorageFormat

A StandardStorageFormat is an internal file format to store and restore Drawings. It uses its own descriptive syntax ands write classes and attributes as plain text in a text file. The StandardStorageFormat has the file extension "draw" (e.g. my_picasso.draw).


Constructor Summary
StandardStorageFormat()
          Create a StandardStorageFormat for storing and restoring Drawings.
 
Method Summary
protected  java.lang.String adjustFileName(java.lang.String testFileName)
          Adjust a file name to have the correct file extension.
 java.lang.String createFileDescription()
          Factory method to create a file description for the file type when displaying the associated FileFilter.
protected  java.lang.String createFileExtension()
          Factory method to create the file extension recognized by the FileFilter for this StandardStorageFormat.
protected  javax.swing.filechooser.FileFilter createFileFilter()
          Factory method to create a FileFilter that accepts file with the appropriate file exention used by a javax.swing.JFileChooser.
 boolean equals(java.lang.Object compareObject)
          Test, whether two StorageFormats are the same.
 java.lang.String getFileDescription()
          Return the file description for the file type of the storage format
 java.lang.String getFileExtension()
          Return the file extension for the storage format
 javax.swing.filechooser.FileFilter getFileFilter()
          Return the FileFilter used to identify Drawing files with the correct file extension for this StorageFormat.
protected  boolean hasCorrectFileExtension(java.lang.String testFileName)
          Test whether the file name has the correct file extension
 boolean isRestoreFormat()
          Every format has to identify itself as able to store and/or restore from the format it represents.
 boolean isStoreFormat()
          Every format has to identify itself as able to store and/or restore from the format it represents.
 Drawing restore(java.lang.String fileName)
          Restore a Drawing from a file with a given name.
 void setFileDescription(java.lang.String newFileDescription)
          Set the file description for the file type of the storage format
 void setFileExtension(java.lang.String newFileExtension)
          Set the file extension for the storage format
 void setFileFilter(javax.swing.filechooser.FileFilter newFileFilter)
          Set the FileFilter used to identify Drawing files with the correct file extension for this StorageFormat.
 java.lang.String store(java.lang.String fileName, Drawing saveDrawing)
          Store a Drawing under a given name.
 
Methods inherited from class java.lang.Object
clone, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

StandardStorageFormat

public StandardStorageFormat()
Create a StandardStorageFormat for storing and restoring Drawings.

Method Detail

createFileExtension

protected java.lang.String createFileExtension()
Factory method to create the file extension recognized by the FileFilter for this StandardStorageFormat. The StandardStorageFormat has the file extension "draw" (e.g. my_picasso.draw).

Returns:
new file extension

setFileExtension

public void setFileExtension(java.lang.String newFileExtension)
Set the file extension for the storage format

Parameters:
newFileExtension - extension

getFileExtension

public java.lang.String getFileExtension()
Return the file extension for the storage format

Returns:
file extension

createFileDescription

public java.lang.String createFileDescription()
Factory method to create a file description for the file type when displaying the associated FileFilter.

Returns:
new file description

setFileDescription

public void setFileDescription(java.lang.String newFileDescription)
Set the file description for the file type of the storage format

Parameters:
newFileDescription - description of the file type

getFileDescription

public java.lang.String getFileDescription()
Return the file description for the file type of the storage format

Returns:
description of the file type

createFileFilter

protected javax.swing.filechooser.FileFilter createFileFilter()
Factory method to create a FileFilter that accepts file with the appropriate file exention used by a javax.swing.JFileChooser. Subclasses can override this method to provide their own file filters.

Returns:
FileFilter for this StorageFormat

setFileFilter

public void setFileFilter(javax.swing.filechooser.FileFilter newFileFilter)
Set the FileFilter used to identify Drawing files with the correct file extension for this StorageFormat.

Parameters:
newFileFilter - FileFilter for this StorageFormat

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Return the FileFilter used to identify Drawing files with the correct file extension for this StorageFormat.

Specified by:
getFileFilter in interface StorageFormat
Returns:
FileFilter for this StorageFormat

isRestoreFormat

public boolean isRestoreFormat()
Description copied from interface: StorageFormat
Every format has to identify itself as able to store and/or restore from the format it represents. If the storage format can load from the format, it should return true in this method.

Specified by:
isRestoreFormat in interface StorageFormat
Returns:
boolean true if the format can load
See Also:
StorageFormat.isRestoreFormat()

isStoreFormat

public boolean isStoreFormat()
Description copied from interface: StorageFormat
Every format has to identify itself as able to store and/or restore from the format it represents. If the storage format can save to the format, it should return true in this method.

Specified by:
isStoreFormat in interface StorageFormat
Returns:
boolean true if the format can save
See Also:
StorageFormat.isStoreFormat()

store

public java.lang.String store(java.lang.String fileName,
                              Drawing saveDrawing)
                       throws java.io.IOException
Store a Drawing under a given name. If the file name does not have the correct file extension, then the file extension is added.

Specified by:
store in interface StorageFormat
Parameters:
fileName - file name of the Drawing under which it should be stored
saveDrawing - drawing to be saved
Returns:
file name with correct file extension
Throws:
java.io.IOException

restore

public Drawing restore(java.lang.String fileName)
                throws java.io.IOException
Restore a Drawing from a file with a given name.

Specified by:
restore in interface StorageFormat
Parameters:
fileName - of the file in which the Drawing has been saved
Returns:
restored Drawing
Throws:
java.io.IOException

equals

public boolean equals(java.lang.Object compareObject)
Test, whether two StorageFormats are the same. They are the same if they both support the same file extension.

Overrides:
equals in class java.lang.Object
Returns:
true, if both StorageFormats have the same file extension, false otherwise

adjustFileName

protected java.lang.String adjustFileName(java.lang.String testFileName)
Adjust a file name to have the correct file extension.

Parameters:
testFileName - file name to be tested for a correct file extension
Returns:
testFileName + file extension if necessary

hasCorrectFileExtension

protected boolean hasCorrectFileExtension(java.lang.String testFileName)
Test whether the file name has the correct file extension

Returns:
true, if the file has the correct extension, false otherwise

JHotDraw 6.0b1