Class ImageInputFormat
- java.lang.Object
-
- org.jhotdraw.draw.io.ImageInputFormat
-
- All Implemented Interfaces:
- InputFormat
public class ImageInputFormat extends java.lang.Object implements InputFormat
An input format for importing drawings using one of the image formats supported by javax.imageio.This class uses the prototype design pattern. A ImageHolderFigure figure is used as a prototype for creating a figure that holds the imported image.
If the drawing is replaced using the loaded image, the size of the drawing is set to match the size of the image using the attributes
AttributeKeys.CANVAS_WIDTHandAttributeKeys.CANVAS_HEIGHT.
Design PatternsPrototype
The image input format creates new image holder figures by cloning a prototype figure object and assigning an image to it, which was read from data input. That's the reason whyFigureextends theCloneableinterface.
Prototype:ImageHolderFigure; Client:ImageInputFormat.
-
-
Constructor Summary
Constructors Constructor and Description ImageInputFormat(ImageHolderFigure prototype)Creates a new image input format for all formats supported byjavax.imageio.ImageIO.ImageInputFormat(ImageHolderFigure prototype, java.lang.String formatName, java.lang.String description, java.lang.String[] fileExtensions, java.lang.String[] mimeTypes)Creates a new image input format for the specified image format.ImageInputFormat(ImageHolderFigure prototype, java.lang.String formatName, java.lang.String description, java.lang.String fileExtension, java.lang.String mimeType)Creates a new image input format for the specified image format.
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method and Description ImageHolderFigurecreateImageHolder(java.io.InputStream in)java.lang.String[]getFileExtensions()javax.swing.filechooser.FileFiltergetFileFilter()Return a FileFilter that can be used to identify files which can be read with this input format.javax.swing.JComponentgetInputFormatAccessory()Return a JFileChooser accessory that can be used to customize the input 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.
-
-
-
Constructor Detail
-
ImageInputFormat
public ImageInputFormat(ImageHolderFigure prototype)
Creates a new image input format for all formats supported byjavax.imageio.ImageIO.
-
ImageInputFormat
public ImageInputFormat(ImageHolderFigure prototype, java.lang.String formatName, java.lang.String description, java.lang.String fileExtension, java.lang.String mimeType)
Creates a new image input format for the specified image format.- Parameters:
formatName- The format name for the javax.imageio.ImageIO object.description- The format description to be used for the file filter.fileExtension- The file extension to be used for the file filter.mimeType- The mime type used for filtering data flavors from Transferable objects.
-
ImageInputFormat
public ImageInputFormat(ImageHolderFigure prototype, java.lang.String formatName, java.lang.String description, java.lang.String[] fileExtensions, java.lang.String[] mimeTypes)
Creates a new image input format for the specified image format.- Parameters:
formatName- The format name for the javax.imageio.ImageIO object.description- The format description to be used for the file filter.fileExtensions- The file extensions to be used for the file filter.mimeTypes- The mime typse used for filtering data flavors from Transferable objects.
-
-
Method Detail
-
getFileFilter
public javax.swing.filechooser.FileFilter getFileFilter()
Description copied from interface:InputFormatReturn a FileFilter that can be used to identify files which can be read with this input format. Typically, each input format has its own recognizable file naming convention.- Specified by:
getFileFilterin interfaceInputFormat- Returns:
- FileFilter to be used with a javax.swing.JFileChooser
-
getFileExtensions
public java.lang.String[] getFileExtensions()
-
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.
-
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, boolean replace) throws java.io.IOException- 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.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
-
createImageHolder
public ImageHolderFigure createImageHolder(java.io.InputStream in) throws java.io.IOException
- Throws:
java.io.IOException
-
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.
-
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
-
-
DataMelt 3.0 © DataMelt by jWork.ORG