com.jinsight.jetchart
Class ChartEncoder

java.lang.Object
  |
  +--com.jinsight.jetchart.ChartEncoder
All Implemented Interfaces:
java.util.EventListener, SVGListener

public class ChartEncoder
extends java.lang.Object
implements SVGListener

Charts created with JetChart can be encoded into a JPEG, PNG, GIF or SVG output stream. This class is a bridge to the api of the encoders available, and is also in charge of generating an offscreen Image object to encode charts. This class is a wrapper around four image encoders, hidding the details of an offscreen image generation to encode charts.


Constructor Summary
ChartEncoder(GenericGraph graph)
          Constructor of the ChartEncoder class.
 
Method Summary
 void addImageEncodingObserver(java.util.Observer obs)
          Adds an Observer object for receiving notifications about the number of bytes processed while a chart image is gif-encoded.
protected  void finalize()
           
 void gifEncode(java.io.File f, int scale)
          Starts gif-encoding a chart image, saving bytes into a file.
 void gifEncode(java.io.OutputStream out)
          Starts gif-encoding a chart image, sending encoded bytes to an output stream.
 void jpegEncode(java.io.File f, int quality)
          Starts jpeg-encoding a chart image, saving bytes into a file.
 void jpegEncode(java.io.OutputStream out, int quality)
          Starts jpeg-encoding a chart image, sending encoded bytes to an output stream.
 void lineProcessed(SVGEvent evt)
          ChartEncoder implements the interface SVGListener to be notified by the SVGGraphics class of each svg line processed.
 void pngEncode(java.io.File f, int compressionLevel)
          Starts png-encoding a chart image, saving bytes into a file.
 void pngEncode(java.io.OutputStream out, int compressionLevel)
          Starts png-encoding a chart image, sending encoded bytes to an output stream.
 void removeImageEncodingObserver(java.util.Observer obs)
          Removes an image encoding observer from receiving notifications about a gif- encoding process.
 void svgEncode(java.io.File f, boolean encodeAsImage, int quality)
          Starts svg-encoding a chart image, saving the resulting code into a file.
 void svgEncode(java.io.OutputStream out, boolean encodeAsImage, int quality)
          Starts svg-encoding a chart image, sending the resulting code to an output stream.
 
Methods inherited from class java.lang.Object
clone, equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

ChartEncoder

public ChartEncoder(GenericGraph graph)
Constructor of the ChartEncoder class.
Parameters:
graph - A GenericGraph object.
See Also:
GenericGraph
Method Detail

addImageEncodingObserver

public void addImageEncodingObserver(java.util.Observer obs)
Adds an Observer object for receiving notifications about the number of bytes processed while a chart image is gif-encoded. The Observer is used to show the progress of the gif-encoding process, by comparing the number of bytes already encoded against the full image size in bytes. The first time the Observer is notified it receives the total number of bytes. Subsequent notifications send the number of bytes already encoded.
Parameters:
obs - An object that implements the Observer interface.

removeImageEncodingObserver

public void removeImageEncodingObserver(java.util.Observer obs)
Removes an image encoding observer from receiving notifications about a gif- encoding process.
Parameters:
obs - An object that implements the Observer interface.
See Also:
addImageEncodingObserver(java.util.Observer)

gifEncode

public void gifEncode(java.io.File f,
                      int scale)
               throws java.io.IOException
Starts gif-encoding a chart image, saving bytes into a file. For example, servlets can generate chart images from clients requests by invoking this method to create a gif file.
Parameters:
f - A File object specifying the name and directory of the gif file.
scale - An integer that sets the gif image size. A number of 100 generates a full size image, while 50 generates an image having half the original size.
Throws:
java.io.IOException -  

gifEncode

public void gifEncode(java.io.OutputStream out)
               throws java.io.IOException
Starts gif-encoding a chart image, sending encoded bytes to an output stream. For example, servlets can generate chart images from clients requests by invoking this method to generate a stream of bytes and sending them back to the client over a binary output stream.
Parameters:
out - An OutputStream object.
Throws:
java.io.IOException -  

pngEncode

public void pngEncode(java.io.File f,
                      int compressionLevel)
               throws java.io.IOException
Starts png-encoding a chart image, saving bytes into a file. For example, servlets can generate chart images from clients requests by invoking this method to create a png file.
Parameters:
f - A File object specifying the name of the png file and its directory.
compressionLevel - An integer ranging from 1 to 9. The higher the number, the higher the compression level.
Throws:
java.io.IOException -  

pngEncode

public void pngEncode(java.io.OutputStream out,
                      int compressionLevel)
               throws java.io.IOException
Starts png-encoding a chart image, sending encoded bytes to an output stream. For example, servlets can generate chart images from clients requests by invoking this method to generate a stream of bytes and sending them back to the client over a binary output stream.
Parameters:
out - An OutputStream object.
compressionLevel - An integer ranging from 1 to 9. The higher the number, the higher the compression level.
Throws:
java.io.IOException -  

jpegEncode

public void jpegEncode(java.io.File f,
                       int quality)
                throws java.io.IOException
Starts jpeg-encoding a chart image, saving bytes into a file. For example, servlets can generate chart images from clients requests by invoking this method to create a jpeg file.
Parameters:
f - A File object specifying the name of the jpeg file and its directory.
quality - An integer ranging from 0 to 100. The larger the number, the better the image quality.
Throws:
java.io.IOException -  

jpegEncode

public void jpegEncode(java.io.OutputStream out,
                       int quality)
                throws java.io.IOException
Starts jpeg-encoding a chart image, sending encoded bytes to an output stream. For example, servlets can generate chart images from clients requests by invoking this method to generate a stream of bytes and sending them back to the client over a binary output stream.
Parameters:
out - An OutputStream object.
quality - An integer ranging from 0 to 100. The larger the number, the better the image quality.
Throws:
java.io.IOException -  

svgEncode

public void svgEncode(java.io.File f,
                      boolean encodeAsImage,
                      int quality)
               throws java.io.IOException
Starts svg-encoding a chart image, saving the resulting code into a file. The entire chart can be outputted as a sequence of geometrical svg elements or as a sequence of base64 encoded characters passed to the 'image' tag.

Additionally, the quality of the svg image can also be specified.

Parameters:
f - A File object specifying the name of the svg file and its directory.
encodeAsImage - A boolean value(true/false).
quality - An integer value.
See Also:
SVGEncoder.HIGH_QUALITY, SVGEncoder.LOW_QUALITY

svgEncode

public void svgEncode(java.io.OutputStream out,
                      boolean encodeAsImage,
                      int quality)
               throws java.io.IOException
Starts svg-encoding a chart image, sending the resulting code to an output stream. The entire chart can be outputted as a sequence of geometrical svg elements or as a sequence of base64 encoded characters passed to the 'image' tag.

Additionally, the quality of the svg code can also be specified.

Parameters:
out - An OutputStream object.
encodeAsImage - A boolean value(true/false).
quality - An integer value.
See Also:
SVGEncoder.HIGH_QUALITY, SVGEncoder.LOW_QUALITY

lineProcessed

public void lineProcessed(SVGEvent evt)
ChartEncoder implements the interface SVGListener to be notified by the SVGGraphics class of each svg line processed. The SVGEvent object brings to ChartEncoder the svg line before it is appended to the whole svg code, allowing for modifications to the original content.
Specified by:
lineProcessed in interface SVGListener
Parameters:
evt - An SVGEvent object.
See Also:
SVGListener, SVGEvent, SVGGraphics

finalize

protected void finalize()
                 throws java.lang.Throwable
Overrides:
finalize in class java.lang.Object