org.jhotdraw.draw.io
Class DOMStorableInputOutputFormat
- java.lang.Object
-
- org.jhotdraw.draw.io.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.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 Summary
Constructors 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.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description java.awt.datatransfer.TransferablecreateTransferable(Drawing drawing, java.util.List<Figure> figures, double scaleFactor)Creates a Transferable for the specified list of Figures.java.lang.StringgetFileExtension()Returns the file extension for the output format.javax.swing.filechooser.FileFiltergetFileFilter()Return a FileFilter that can be used to identify files which can be stored with this output format.javax.swing.JComponentgetInputFormatAccessory()Return a JFileChooser accessory that can be used to customize the input format.javax.swing.JComponentgetOutputFormatAccessory()Return a JFileChooser accessory that can be used to customize the output format.booleanisDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)Returns true, if this InputFormat can readFigures TransferData using the specified DataFlavor.voidread(java.io.File file, Drawing drawing)voidread(java.io.File file, Drawing drawing, boolean replace)voidread(java.io.InputStream in, Drawing drawing, boolean replace)Reads figures from a file and adds them to the specified drawing.voidread(java.awt.datatransfer.Transferable t, Drawing drawing, boolean replace)Reads figures from the specified Transferable and adds them to the specified drawing.voidread(java.net.URI uri, Drawing drawing)Reads figures from an URI and replaces the children of the drawing with them.voidread(java.net.URI uri, Drawing drawing, boolean replace)Reads figures from an URI and adds them to the specified drawing.voidwrite(java.io.File file, Drawing drawing)voidwrite(java.io.OutputStream out, Drawing drawing)Writes a Drawing into an output stream.voidwrite(java.net.URI uri, Drawing drawing)Writes a Drawing into an URI.
-
-
-
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:OutputFormatReturn a FileFilter that can be used to identify files which can be stored with this output format. Typically, each output format has its own recognizable file extension.- Specified by:
getFileFilterin interfaceInputFormat- Specified by:
getFileFilterin interfaceOutputFormat- Returns:
- FileFilter to be used with a javax.swing.JFileChooser
-
getOutputFormatAccessory
public javax.swing.JComponent getOutputFormatAccessory()
Description copied from interface:OutputFormatReturn a JFileChooser accessory that can be used to customize the output format.- Specified by:
getOutputFormatAccessoryin interfaceOutputFormat- 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:InputFormatReturn a JFileChooser accessory that can be used to customize the input format.- Specified by:
getInputFormatAccessoryin interfaceInputFormat- Returns:
- A JFileChooser accessory to be used with a javax.swing.JFileChooser Returns null, if no accessory is provided for this format.
-
getFileExtension
public java.lang.String getFileExtension()
Description copied from interface:OutputFormatReturns 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:
getFileExtensionin interfaceOutputFormat
-
isDataFlavorSupported
public boolean isDataFlavorSupported(java.awt.datatransfer.DataFlavor flavor)
Description copied from interface:InputFormatReturns true, if this InputFormat can readFigures TransferData using the specified DataFlavor.- Specified by:
isDataFlavorSupportedin interfaceInputFormat- Parameters:
flavor- A DataFlavor.
-
write
public void write(java.net.URI uri, Drawing drawing) throws java.io.IOExceptionDescription copied from interface:OutputFormatWrites a Drawing into an URI.- Specified by:
writein interfaceOutputFormat- Parameters:
uri- The uri.drawing- The drawing.- Throws:
java.io.IOException
-
write
public void write(java.io.File file, Drawing drawing) throws java.io.IOException- Throws:
java.io.IOException
-
write
public void write(java.io.OutputStream out, Drawing drawing) throws java.io.IOExceptionDescription copied from interface:OutputFormatWrites a Drawing into an output stream.- Specified by:
writein interfaceOutputFormat- Parameters:
out- The output stream.drawing- The drawing.- Throws:
java.io.IOException
-
read
public void read(java.net.URI uri, Drawing drawing) throws java.io.IOExceptionDescription copied from interface:InputFormatReads figures from an URI and replaces the children of the drawing with them.This is a convenience method for calling read(URI,Drawing,true).
- Specified by:
readin interfaceInputFormat- Parameters:
uri- The URI.drawing- The drawing.- Throws:
java.io.IOException
-
read
public void read(java.net.URI uri, Drawing drawing, boolean replace) throws java.io.IOExceptionDescription copied from interface:InputFormatReads figures from an URI and adds them to the specified drawing.- Specified by:
readin interfaceInputFormat- Parameters:
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).- Throws:
java.io.IOException
-
read
public void read(java.io.File file, Drawing drawing) throws java.io.IOException- Throws:
java.io.IOException
-
read
public void read(java.io.File file, Drawing drawing, boolean replace) throws java.io.IOException- Throws:
java.io.IOException
-
read
public void read(java.io.InputStream in, Drawing drawing, boolean replace) throws java.io.IOExceptionDescription copied from interface:InputFormatReads figures from a file and adds them to the specified drawing.- Specified by:
readin interfaceInputFormat- Parameters:
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).- Throws:
java.io.IOException
-
read
public void read(java.awt.datatransfer.Transferable t, Drawing drawing, boolean replace) throws java.awt.datatransfer.UnsupportedFlavorException, java.io.IOExceptionDescription copied from interface:InputFormatReads figures from the specified Transferable and adds them to the specified drawing.- Specified by:
readin interfaceInputFormat- Parameters:
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).- Throws:
java.awt.datatransfer.UnsupportedFlavorExceptionjava.io.IOException
-
createTransferable
public java.awt.datatransfer.Transferable createTransferable(Drawing drawing, java.util.List<Figure> figures, double scaleFactor) throws java.io.IOException
Description copied from interface:OutputFormatCreates a Transferable for the specified list of Figures.- Specified by:
createTransferablein interfaceOutputFormat- Parameters:
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.- Returns:
- The Transferable.
- Throws:
java.io.IOException
-
-
DataMelt 3.0 © DataMelt by jWork.ORG