public class DOMStorableInputOutputFormat extends java.lang.Object implements OutputFormat, InputFormat
This class is here to support quick-and-dirty implementations of drawings that can be read and written from/to output streams. For example, in student projects.
This class should no be used as a means to implement long-term storage of drawings, since it does not support structural changes that might occur in a drawing application over time.
Constructor and Description |
---|
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.
|
Modifier and Type | Method and Description |
---|---|
java.awt.datatransfer.Transferable |
createTransferable(Drawing drawing,
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 stored
with this output 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) |
void |
read(java.io.File file,
Drawing drawing,
boolean replace) |
void |
read(java.io.InputStream in,
Drawing drawing,
boolean replace)
Reads figures from a file and adds them to the specified drawing.
|
void |
read(java.awt.datatransfer.Transferable t,
Drawing drawing,
boolean replace)
Reads figures from the specified Transferable and adds them to the
specified drawing.
|
void |
read(java.net.URI uri,
Drawing drawing)
Reads figures from an URI and replaces the children of the drawing
with them.
|
void |
read(java.net.URI uri,
Drawing drawing,
boolean replace)
Reads figures from an URI 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.
|
void |
write(java.io.File file,
Drawing drawing) |
void |
write(java.io.OutputStream out,
Drawing drawing)
Writes a Drawing into an output stream.
|
void |
write(java.net.URI uri,
Drawing drawing)
Writes a Drawing into an URI.
|
public DOMStorableInputOutputFormat(DOMFactory factory)
public DOMStorableInputOutputFormat(DOMFactory factory, java.lang.String description, java.lang.String fileExtension, java.lang.String mimeType)
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.public javax.swing.filechooser.FileFilter getFileFilter()
OutputFormat
getFileFilter
in interface InputFormat
getFileFilter
in interface OutputFormat
public javax.swing.JComponent getOutputFormatAccessory()
OutputFormat
getOutputFormatAccessory
in interface OutputFormat
public javax.swing.JComponent getInputFormatAccessory()
InputFormat
getInputFormatAccessory
in interface InputFormat
protected void read(java.net.URL url, java.io.InputStream in, Drawing drawing, java.util.LinkedList<Figure> figures) throws java.io.IOException
java.io.IOException
public java.lang.String getFileExtension()
OutputFormat
getFileExtension
in interface OutputFormat
public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
InputFormat
isDataFlavorSupported
in interface InputFormat
flavor
- A DataFlavor.public void write(java.net.URI uri, Drawing drawing) throws java.io.IOException
OutputFormat
write
in interface OutputFormat
uri
- The uri.drawing
- The drawing.java.io.IOException
public void write(java.io.File file, Drawing drawing) throws java.io.IOException
java.io.IOException
public void write(java.io.OutputStream out, Drawing drawing) throws java.io.IOException
OutputFormat
write
in interface OutputFormat
out
- The output stream.drawing
- The drawing.java.io.IOException
public void read(java.net.URI uri, Drawing drawing) throws java.io.IOException
InputFormat
This is a convenience method for calling read(URI,Drawing,true).
read
in interface InputFormat
uri
- The URI.drawing
- The drawing.java.io.IOException
public void read(java.net.URI uri, Drawing drawing, boolean replace) throws java.io.IOException
InputFormat
read
in interface InputFormat
uri
- The URI.drawing
- The drawing.replace
- Set this to true, if the contents of the file replaces the
contents of the drawing (for example, when loading a drawing from a file).
Set this to false, to add the contents of the file to the drawing (for
example, when the file has been dropped into the drawing view).java.io.IOException
public void read(java.io.File file, Drawing drawing) throws java.io.IOException
java.io.IOException
public void read(java.io.File file, Drawing drawing, boolean replace) throws java.io.IOException
java.io.IOException
public void read(java.io.InputStream in, Drawing drawing, boolean replace) throws java.io.IOException
InputFormat
read
in interface InputFormat
in
- The input stream.drawing
- The drawing.replace
- Set this to true, if the contents of the stream replaces the
contents of the drawing (for example, when loading a drawing from a stream).
Set this to false, to add the contents of the file to the drawing (for
example, when the stream has been dropped into the drawing view).java.io.IOException
public void read(java.awt.datatransfer.Transferable t, Drawing drawing, boolean replace) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOException
InputFormat
read
in interface InputFormat
t
- The Transferable.drawing
- The drawing.replace
- Set this to true, if the contents of the transferable
replaces the contents of the drawing (for example, when loading a drawing
from a transferable). Set this to false, to add the contents of the
transferable to the drawing (for example, when the transferable has been
dropped or pasted into the drawing view).java.awt.datatransfer.UnsupportedFlavorException
java.io.IOException
public java.awt.datatransfer.Transferable createTransferable(Drawing drawing, java.util.List<Figure> figures, double scaleFactor) throws java.io.IOException
OutputFormat
createTransferable
in interface OutputFormat
drawing
- The drawing.figures
- A list of figures of the drawing.scaleFactor
- The factor to be used, when the Transferable creates
an image with a fixed size from the figures.java.io.IOException