JHotDraw 7.6

org.jhotdraw.draw.io
Class TextInputFormat

java.lang.Object
  extended by org.jhotdraw.draw.io.TextInputFormat
All Implemented Interfaces:
InputFormat

public class TextInputFormat
extends java.lang.Object
implements InputFormat

An input format for importing text into a drawing.

This class uses the prototype design pattern. A TextHolderFigure figure is used as a prototype for creating a figure that holds the imported text.

For text that spans multiple lines, TextInputFormat can either add all the text to the same Figure, or it can create a new Figure for each line.


Design Patterns

Prototype
The text input format creates new text holder figures by cloning a prototype figure object and assigning an image to it, which was read from data input. That's the reason why Figure extends the Cloneable interface.
Prototype: TextHolderFigure; Client: TextInputFormat.


Version:
$Id: TextInputFormat.java 718 2010-11-21 17:49:53Z rawcoder $
Author:
Werner Randelshofer

Constructor Summary
TextInputFormat(TextHolderFigure prototype)
          Creates a new image output format for text, for a figure that can not.
TextInputFormat(TextHolderFigure prototype, java.lang.String formatName, java.lang.String description, java.lang.String fileExtension, boolean isMultiline)
          Creates a new image output format for the specified image format.
 
Method Summary
 java.util.LinkedList<Figure> createTextHolderFigures(java.io.InputStream in)
           
 java.lang.String getFileExtension()
           
 javax.swing.filechooser.FileFilter getFileFilter()
          Return a FileFilter that can be used to identify files which can be read with this input format.
 javax.swing.JComponent getInputFormatAccessory()
          Return a JFileChooser accessory that can be used to customize the input 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.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

TextInputFormat

public TextInputFormat(TextHolderFigure prototype)
Creates a new image output format for text, for a figure that can not. hold multiple lines of text.


TextInputFormat

public TextInputFormat(TextHolderFigure prototype,
                       java.lang.String formatName,
                       java.lang.String description,
                       java.lang.String fileExtension,
                       boolean isMultiline)
Creates a new image output 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 file filter.
isMultiline - Set this to true, if the TextHolderFigure can hold multiple lines of text. If this is true, multiple lines of text are added to the same figure. If this is false, a new Figure is created for each line of text.
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 read with this input format. Typically, each input format has its own recognizable file naming convention.

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

getFileExtension

public java.lang.String getFileExtension()

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

public void read(java.net.URI uri,
                 Drawing drawing)
          throws java.io.IOException
Description copied from interface: InputFormat
Reads 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:
read in interface InputFormat
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.IOException
Description copied from interface: InputFormat
Reads figures from an URI and adds them to the specified drawing.

Specified by:
read in interface InputFormat
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.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.
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

createTextHolderFigures

public java.util.LinkedList<Figure> createTextHolderFigures(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: InputFormat
Returns true, if this InputFormat can readFigures TransferData using the specified DataFlavor.

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

read

public void read(java.awt.datatransfer.Transferable t,
                 Drawing drawing,
                 boolean replace)
          throws java.awt.datatransfer.UnsupportedFlavorException,
                 java.io.IOException
Description copied from interface: InputFormat
Reads figures from the specified Transferable and adds them to the specified drawing.

Specified by:
read in interface InputFormat
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.UnsupportedFlavorException
java.io.IOException

Copyright 1996-2010 (c) by the authors and contributors of the JHotDraw project.
Some rights reserved.