org.jhotdraw.samples.svg.io
Class ImageMapOutputFormat

java.lang.Object
  extended by org.jhotdraw.samples.svg.io.ImageMapOutputFormat
All Implemented Interfaces:
OutputFormat

public class ImageMapOutputFormat
extends java.lang.Object
implements OutputFormat

ImageMapOutputFormat exports a SVG drawing as an HTML 4.01 MAP element. For more information see: http://www.w3.org/TR/html401/struct/objects.html#h-13.6.2

Version:
$Id: ImageMapOutputFormat.java 613 2010-01-12 10:23:31Z rawcoder $
Author:
Werner Randelshofer

Field Summary
private  java.awt.Rectangle bounds
          Image dimension.
private static boolean DEBUG
           
private  java.awt.geom.AffineTransform drawingTransform
          The affine transformation for the output.
private  boolean isIncludeNohref
          Set this to true, if AREA elements with nohref="true" shall e included in the image map.
 
Constructor Summary
ImageMapOutputFormat()
          Creates a new instance.
 
Method Summary
 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 getOutputFormatAccessory()
          Return a JFileChooser accessory that can be used to customize the output format.
 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.
 void write(java.io.OutputStream out, Drawing drawing, java.awt.geom.AffineTransform drawingTransform, java.awt.Dimension imageSize)
          Writes the drawing to the specified output stream.
 void write(java.io.OutputStream out, java.util.List<Figure> figures)
          All other write methods delegate their work to here.
 void write(java.io.OutputStream out, java.util.List<Figure> figures, java.awt.geom.AffineTransform drawingTransform, java.awt.Dimension imageSize)
          Writes the figures to the specified output stream.
private  boolean writeCircleAttributes(IXMLElement elem, SVGFigure f, java.awt.geom.Ellipse2D.Double ellipse)
          Writes the shape, coords, href, nohref Attribute for the specified figure and ellipse.
protected  void writeElement(IXMLElement parent, Figure f)
           
private  void writeEllipseElement(IXMLElement parent, SVGEllipseFigure f)
           
private  void writeGElement(IXMLElement parent, SVGGroupFigure f)
           
private  void writeHrefAttribute(IXMLElement elem, SVGFigure f)
           
private  void writeImageElement(IXMLElement parent, SVGImageFigure f)
           
private  void writeLineElement(IXMLElement parent, SVGPathFigure f)
           
private  void writePathElement(IXMLElement parent, SVGPathFigure f)
           
private  boolean writePolyAttributes(IXMLElement elem, SVGFigure f, java.awt.Shape shape)
          Writes the shape, coords, href, nohref Attribute for the specified figure and shape.
private  void writePolygonElement(IXMLElement parent, SVGPathFigure f)
           
private  void writePolylineElement(IXMLElement parent, SVGPathFigure f)
           
private  boolean writeRectAttributes(IXMLElement elem, SVGFigure f, java.awt.geom.Rectangle2D.Double rect)
          Writes the shape, coords, href, nohref Attribute for the specified figure and rectangle.
private  void writeRectElement(IXMLElement parent, SVGRectFigure f)
           
private  void writeTextAreaElement(IXMLElement parent, SVGTextAreaFigure f)
           
private  void writeTextElement(IXMLElement parent, SVGTextFigure f)
           
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

drawingTransform

private java.awt.geom.AffineTransform drawingTransform
The affine transformation for the output. This is used to create scaled image maps.


DEBUG

private static boolean DEBUG

isIncludeNohref

private boolean isIncludeNohref
Set this to true, if AREA elements with nohref="true" shall e included in the image map.


bounds

private java.awt.Rectangle bounds
Image dimension. We only include AREA elements which are within the image dimension.

Constructor Detail

ImageMapOutputFormat

public ImageMapOutputFormat()
Creates a new instance.

Method Detail

getFileFilter

public javax.swing.filechooser.FileFilter getFileFilter()
Description copied from interface: OutputFormat
Return 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:
getFileFilter in interface OutputFormat
Returns:
FileFilter to be used with a javax.swing.JFileChooser

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

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.

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

write

public void write(java.io.OutputStream out,
                  Drawing drawing,
                  java.awt.geom.AffineTransform drawingTransform,
                  java.awt.Dimension imageSize)
           throws java.io.IOException
Writes the drawing to the specified output stream. This method applies the specified drawingTransform to the drawing, and draws it on an image of the specified getChildCount.

Throws:
java.io.IOException

write

public void write(java.io.OutputStream out,
                  java.util.List<Figure> figures,
                  java.awt.geom.AffineTransform drawingTransform,
                  java.awt.Dimension imageSize)
           throws java.io.IOException
Writes the figures to the specified output stream. This method applies the specified drawingTransform to the drawing, and draws it on an image of the specified getChildCount. All other write methods delegate their work to here.

Throws:
java.io.IOException

write

public void write(java.io.OutputStream out,
                  java.util.List<Figure> figures)
           throws java.io.IOException
All other write methods delegate their work to here.

Throws:
java.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: OutputFormat
Creates a Transferable for the specified list of Figures.

Specified by:
createTransferable in interface OutputFormat
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

writeElement

protected void writeElement(IXMLElement parent,
                            Figure f)
                     throws java.io.IOException
Throws:
java.io.IOException

writeCircleAttributes

private boolean writeCircleAttributes(IXMLElement elem,
                                      SVGFigure f,
                                      java.awt.geom.Ellipse2D.Double ellipse)
Writes the shape, coords, href, nohref Attribute for the specified figure and ellipse.

Returns:
Returns true, if the circle is inside of the image bounds.

writeRectAttributes

private boolean writeRectAttributes(IXMLElement elem,
                                    SVGFigure f,
                                    java.awt.geom.Rectangle2D.Double rect)
Writes the shape, coords, href, nohref Attribute for the specified figure and rectangle.

Returns:
Returns true, if the rect is inside of the image bounds.

writeHrefAttribute

private void writeHrefAttribute(IXMLElement elem,
                                SVGFigure f)

writePolyAttributes

private boolean writePolyAttributes(IXMLElement elem,
                                    SVGFigure f,
                                    java.awt.Shape shape)
Writes the shape, coords, href, nohref Attribute for the specified figure and shape.

Returns:
Returns true, if the polygon is inside of the image bounds.

writePathElement

private void writePathElement(IXMLElement parent,
                              SVGPathFigure f)
                       throws java.io.IOException
Throws:
java.io.IOException

writePolygonElement

private void writePolygonElement(IXMLElement parent,
                                 SVGPathFigure f)
                          throws java.io.IOException
Throws:
java.io.IOException

writePolylineElement

private void writePolylineElement(IXMLElement parent,
                                  SVGPathFigure f)
                           throws java.io.IOException
Throws:
java.io.IOException

writeLineElement

private void writeLineElement(IXMLElement parent,
                              SVGPathFigure f)
                       throws java.io.IOException
Throws:
java.io.IOException

writeRectElement

private void writeRectElement(IXMLElement parent,
                              SVGRectFigure f)
                       throws java.io.IOException
Throws:
java.io.IOException

writeTextElement

private void writeTextElement(IXMLElement parent,
                              SVGTextFigure f)
                       throws java.io.IOException
Throws:
java.io.IOException

writeTextAreaElement

private void writeTextAreaElement(IXMLElement parent,
                                  SVGTextAreaFigure f)
                           throws java.io.IOException
Throws:
java.io.IOException

writeEllipseElement

private void writeEllipseElement(IXMLElement parent,
                                 SVGEllipseFigure f)
                          throws java.io.IOException
Throws:
java.io.IOException

writeGElement

private void writeGElement(IXMLElement parent,
                           SVGGroupFigure f)
                    throws java.io.IOException
Throws:
java.io.IOException

writeImageElement

private void writeImageElement(IXMLElement parent,
                               SVGImageFigure f)