JHotDraw 7.0.9

org.jhotdraw.draw
Class DOMStorableInputOutputFormat

java.lang.Object
  extended by org.jhotdraw.draw.DOMStorableInputOutputFormat
All Implemented Interfaces:
InputFormat, OutputFormat

public class DOMStorableInputOutputFormat
extends java.lang.Object
implements OutputFormat, InputFormat

An OutputFormat that can write Drawings with DOMStorable Figure's.

Version:
1.0 December 26, 2006 Created.
Author:
Werner Randelshofer

Constructor Summary
DOMStorableInputOutputFormat(DOMFactory factory)
          Creates a new instance with format name "Drawing", file extension "xml" and mime type "image/x-jhotdraw".
DOMStorableInputOutputFormat(DOMFactory factory, java.lang.String description, java.lang.String fileExtension, java.lang.String mimeType)
          Creates a new instance using the specified parameters.
 
Method Summary
 java.awt.datatransfer.Transferable createTransferable(java.util.List<Figure> figures, double scaleFactor)
          Creates a Transferable for the specified list of Figures.
 java.lang.String getFileExtension()
          Returns the file extension for the output format.
 javax.swing.filechooser.FileFilter getFileFilter()
          Return a FileFilter that can be used to identify files which can be restored with this Storage Format.
 javax.swing.JComponent getInputFormatAccessory()
          Return a JFileChooser accessory that can be used to customize the input format.
 javax.swing.JComponent getOutputFormatAccessory()
          Return a JFileChooser accessory that can be used to customize the output format.
 boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
          Returns true, if this InputFormat can readFigures TransferData using the specified DataFlavor.
 void read(java.io.File file, Drawing drawing)
          Reads figures from a file and adds them to the specified drawing.
 void read(java.io.InputStream in, Drawing drawing)
          Reads figures from a file and adds them to the specified drawing.
protected  void read(java.net.URL url, java.io.InputStream in, Drawing drawing, java.util.LinkedList<Figure> figures)
          Reads a list of figures into the specified drawing.
 java.util.List<Figure> readFigures(java.awt.datatransfer.Transferable t)
          Reads figures from the specified Transferable.
 void write(java.io.File file, Drawing drawing)
          Writes a Drawing into a file.
 void write(java.io.OutputStream out, Drawing drawing)
          Writes a Drawing into an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

DOMStorableInputOutputFormat

public DOMStorableInputOutputFormat(DOMFactory factory)
Creates a new instance with format name "Drawing", file extension "xml" and mime type "image/x-jhotdraw".


DOMStorableInputOutputFormat

public DOMStorableInputOutputFormat(DOMFactory factory,
                                    java.lang.String description,
                                    java.lang.String fileExtension,
                                    java.lang.String mimeType)
Creates a new instance using the specified parameters.

Parameters:
factory - The factory for creating Figures from XML elements.
description - The format description to be used for the file filter.
fileExtension - The file extension to be used for file filter.
mimeType - The Mime Type is used for clipboard access.
Method Detail

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Description copied from interface: InputFormat
Return a FileFilter that can be used to identify files which can be restored with this Storage Format. Typically, each input format has its own recognizable file naming convention.

Specified by:
getFileFilter in interface InputFormat
Specified by:
getFileFilter in interface OutputFormat
Returns:
FileFilter to be used with a javax.swing.JFileChooser

getOutputFormatAccessory

public javax.swing.JComponent getOutputFormatAccessory()
Description copied from interface: OutputFormat
Return a JFileChooser accessory that can be used to customize the output format.

Specified by:
getOutputFormatAccessory in interface OutputFormat
Returns:
A JFileChooser accessory to be used with a javax.swing.JFileChooser Returns null, if no accessory is provided for this format.

getInputFormatAccessory

public javax.swing.JComponent getInputFormatAccessory()
Description copied from interface: InputFormat
Return a JFileChooser accessory that can be used to customize the input format.

Specified by:
getInputFormatAccessory in interface InputFormat
Returns:
A JFileChooser accessory to be used with a javax.swing.JFileChooser Returns null, if no accessory is provided for this format.

read

protected void read(java.net.URL url,
                    java.io.InputStream in,
                    Drawing drawing,
                    java.util.LinkedList<Figure> figures)
             throws java.io.IOException
Reads a list of figures into the specified drawing. This method expects that there is a child element named "figures" in the element that represents the drawing.

Throws:
java.io.IOException

getFileExtension

public java.lang.String getFileExtension()
Description copied from interface: OutputFormat
Returns the file extension for the output format. The file extension should be appended to a file name when storing a Drawing with the specified file format.

Specified by:
getFileExtension in interface OutputFormat

write

public void write(java.io.File file,
                  Drawing drawing)
           throws java.io.IOException
Description copied from interface: OutputFormat
Writes a Drawing into a file.

Specified by:
write in interface OutputFormat
Parameters:
file - The file.
drawing - The drawing.
Throws:
java.io.IOException

write

public void write(java.io.OutputStream out,
                  Drawing drawing)
           throws java.io.IOException
Description copied from interface: OutputFormat
Writes a Drawing into an output stream.

Specified by:
write in interface OutputFormat
Parameters:
out - The output stream.
drawing - The drawing.
Throws:
java.io.IOException

read

public void read(java.io.File file,
                 Drawing drawing)
          throws java.io.IOException
Description copied from interface: InputFormat
Reads figures from a file and adds them to the specified drawing.

Specified by:
read in interface InputFormat
Parameters:
file - The file.
drawing - The drawing.
Throws:
java.io.IOException

read

public void read(java.io.InputStream in,
                 Drawing drawing)
          throws java.io.IOException
Description copied from interface: InputFormat
Reads figures from a file and adds them to the specified drawing.

Specified by:
read in interface InputFormat
Parameters:
in - The input stream.
drawing - The drawing.
Throws:
java.io.IOException

isDataFlavorSupported

public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Description copied from interface: InputFormat
Returns true, if this InputFormat can readFigures TransferData using the specified DataFlavor.

Specified by:
isDataFlavorSupported in interface InputFormat
Parameters:
flavor - A DataFlavor.

readFigures

public java.util.List<Figure> readFigures(java.awt.datatransfer.Transferable t)
                                   throws java.awt.datatransfer.UnsupportedFlavorException,
                                          java.io.IOException
Description copied from interface: InputFormat
Reads figures from the specified Transferable.

Specified by:
readFigures in interface InputFormat
Parameters:
t - The Transferable.
Returns:
The figures that were readFigures from the Transferable.
Throws:
java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException

createTransferable

public java.awt.datatransfer.Transferable createTransferable(java.util.List<Figure> figures,
                                                             double scaleFactor)
                                                      throws java.io.IOException
Description copied from interface: OutputFormat
Creates a Transferable for the specified list of Figures.

Specified by:
createTransferable in interface OutputFormat
Parameters:
figures - The figures.
scaleFactor - The factor to be used, when the Transferable creates an image with a fixed size from the figures.
Returns:
The Transferable.
Throws:
java.io.IOException

Copyright 1996-2007 (c) JHotDraw.org.
Some rights reserved.