Search this API

y.io
Class ImageOutputHandler

java.lang.Object
  extended by y.io.IOHandler
      extended by y.io.ImageOutputHandler
Direct Known Subclasses:
GIFIOHandler, ImageIoOutputHandler, JPGIOHandler

public abstract class ImageOutputHandler
extends IOHandler

Abstract base class for IOHandlers that produce image based output formats. The encoding process is done in two steps. First the graph will be renderer to an image. Rendering upon an image is done by calling method Graph2DView.paintVisibleContent(Graphics2D) on the current view of the Graph2D. Configuring the view influences size, viewport, background, etc. of the rendered image. In the second step the image is taken and encoded to the output format.

 

Constructor Summary
protected ImageOutputHandler()
           
protected ImageOutputHandler(boolean antialias)
           
 
Method Summary
 boolean canRead()
          Returns false, since this class can't read a graph.
 Graph2DView createDefaultGraph2DView(Graph2D graph)
          Creates the default view used as image producer in case there is no current view associated with the graph2D.
protected  GraphicsContext createGraphicsContext(Graph2DView view, java.awt.Graphics2D g2d)
          Factory method that creates the GraphicsContext that will be used for the graphics object during the rendering of the image.
protected abstract  java.awt.image.BufferedImage createImage(int width, int height)
          Creates the buffered image on which the graph will be rendered.
protected abstract  void encode(java.awt.image.BufferedImage image, java.io.OutputStream out)
          Encodes the given image to the given output stream.
 double getBorder()
          Gets the width for the view insets when using createDefaultGraph2DView(y.view.Graph2D).
 boolean isAntialiasingEnabled()
          Getter for property antialias.
 boolean isSelectionPaintingEnabled()
          Determines whether or not the selection state of graph elements should be taken into account when writing the image produced by this image output handler.
 void read(Graph2D graph, java.io.InputStream in)
          Unsupported method.
 void setAntialiasingEnabled(boolean antialias)
          Setter for property antialias.
 void setBorder(double border)
          Sets the width for the view insets when using createDefaultGraph2DView(y.view.Graph2D).
 void setSelectionPaintingEnabled(boolean enabled)
          Specifies whether or not the selection state of graph elements should be taken into account when writing the image produced by this image output handler.
 void write(Graph2D graph, java.io.OutputStream out)
          Writes the contents of the given graph to the image based format encoded by this class.
 void write(Graph2DView view, java.io.OutputStream out)
          Writes the contents of the given Graph2dView to the image based format encoded by this class.
 
Methods inherited from class y.io.IOHandler
canWrite, canWriteSubset, createObjectInputStream, createObjectOutputStream, getFileFormatString, getFileNameExtension, hide, read, read, shouldSerialize, shouldSerialize, write, writeSubset, writeSubset
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ImageOutputHandler

protected ImageOutputHandler()

ImageOutputHandler

protected ImageOutputHandler(boolean antialias)
Method Detail

isSelectionPaintingEnabled

public boolean isSelectionPaintingEnabled()
Determines whether or not the selection state of graph elements should be taken into account when writing the image produced by this image output handler.

By default, this setting is true.

Returns:
true if the selection state of graph elements is taken into account; false otherwise.
See Also:
setSelectionPaintingEnabled(boolean)

setSelectionPaintingEnabled

public void setSelectionPaintingEnabled(boolean enabled)
Specifies whether or not the selection state of graph elements should be taken into account when writing the image produced by this image output handler.

By default, this setting is true.

Parameters:
enabled - if true the selection state of graph elements is taken into account otherwise it is ignored.
See Also:
isSelectionPaintingEnabled()

canRead

public boolean canRead()
Returns false, since this class can't read a graph.

Overrides:
canRead in class IOHandler

read

public void read(Graph2D graph,
                 java.io.InputStream in)
Unsupported method.

Specified by:
read in class IOHandler

write

public void write(Graph2D graph,
                  java.io.OutputStream out)
           throws java.io.IOException
Writes the contents of the given graph to the image based format encoded by this class. Calls write(y.view.Graph2DView,java.io.OutputStream).

Specified by:
write in class IOHandler
Parameters:
graph - the graph to be encoded.
out - The OutputStream being written to.
Throws:
java.io.IOException

write

public void write(Graph2DView view,
                  java.io.OutputStream out)
           throws java.io.IOException
Writes the contents of the given Graph2dView to the image based format encoded by this class.

Parameters:
view - the view whose contents should be encoded.
out - The OutputStream being written to.
Throws:
java.lang.IllegalArgumentException - if view.getCanvasSize().width * view.getCanvasSize().height > Integer.MAX_VALUE.
java.io.IOException - if an error occurs during writing.

createGraphicsContext

protected GraphicsContext createGraphicsContext(Graph2DView view,
                                                java.awt.Graphics2D g2d)
Factory method that creates the GraphicsContext that will be used for the graphics object during the rendering of the image. This implementation sets the GraphicsContext.isExportPainting() property to true.

Parameters:
view - the view that will be used for the painting.
g2d - the graphics object to use for the painting
Returns:
the context to register with the graphics object or null.

createImage

protected abstract java.awt.image.BufferedImage createImage(int width,
                                                            int height)
Creates the buffered image on which the graph will be rendered.


createDefaultGraph2DView

public Graph2DView createDefaultGraph2DView(Graph2D graph)
Creates the default view used as image producer in case there is no current view associated with the graph2D. The default view renders the graph in its original size using a white background color.

The returned view will be automatically registered as one of the graph's views. After the returned view is not needed anymore it is advisable to remove it from the list of registered view of the given graph.

See Also:
Graph2D.removeView(y.view.View)

encode

protected abstract void encode(java.awt.image.BufferedImage image,
                               java.io.OutputStream out)
                        throws java.io.IOException
Encodes the given image to the given output stream.

Throws:
java.io.IOException - if an error occurs during writing.

isAntialiasingEnabled

public boolean isAntialiasingEnabled()
Getter for property antialias.

Returns:
Value of property antialias.

setAntialiasingEnabled

public void setAntialiasingEnabled(boolean antialias)
Setter for property antialias.

Parameters:
antialias - New value of property antialias.

getBorder

public double getBorder()
Gets the width for the view insets when using createDefaultGraph2DView(y.view.Graph2D).

Default value is 10.

Returns:
the default insets width
See Also:
setBorder(double)

setBorder

public void setBorder(double border)
Sets the width for the view insets when using createDefaultGraph2DView(y.view.Graph2D).

Default value is 10.

Parameters:
border -
See Also:
getBorder()

© Copyright 2000-2021,
yWorks GmbH.
All rights reserved.