org.faceless.graph2.tag
Class PNGEmbedder

java.lang.Object
  extended by org.faceless.graph2.tag.Embedder
      extended by org.faceless.graph2.tag.PNGEmbedder

public class PNGEmbedder
extends Embedder

An Embedder that creates a bitmap image of the specified graph, and returns it as a PNG to the browser. This class handles rollovers on the data (for piegraph and barseries) or series (for lineseries) tags.

For customers wishing to return their own type of bitmap to the browser, or wishing to handle rollovers in a different way, extending this class is a good place to start. Typically the methods that would need overriding are getMIMEType() and writeBitmap() if a format other thatn PNG is to be returned, createHTML() if the JavaScript and image map are to be created differently, and maybe fixActionString() and addSeriesToScript() if the JavaScript is to be completely redone.

Since:
2.4

Field Summary
 
Fields inherited from class org.faceless.graph2.tag.Embedder
ACTIONS
 
Constructor Summary
PNGEmbedder()
           
 
Method Summary
protected  void addSeriesToAreaMap(Area area, String key, Map imageareas, Series series, String seriesname, Map areamap)
          For the given Area and key, add any events for this key to the areamap.
protected  void addSeriesToScript(Area area, String key, Map imageareas, Series series, String seriesname, StringBuffer out)
          Add any JavaScript necessary for this area to the script StringBuffer.
 void convert()
          Convert the object returned by Embedder.getGraph() to an appropriate binary form, write it to Embedder.getImageOutputStream() and write the HTML required to embed it to Embedder.getPageWriter(), referencing the image at Embedder.getImagePath().
protected  void createHTML(Map areamap, StringBuffer script, StringBuffer args, Writer out)
          Write the required HTML to the specified writer.
protected  ImageOutput createImageOutput()
          Create the ImageOutput object from the Graph object
protected static String createPathString(PathIterator p)
          Given a PathIterator which contains only the initial MOVETO and subsequent LINETO segments, return a String equivalent suitable for use in the "coords" attribute of an <area> tag.
protected  StringBuffer finalizeScript(StringBuffer script)
          Modify the JavaScript created by addSeriesToScript().
protected  String fixActionString(String action, String seriesname, String value)
          Fix the "action" string for the specified attribute.
 String getMIMEType()
          Get the MIME type for the image that will be written by this Embedder to Embedder.getImageOutputStream()
protected  void writeBitmap(ImageOutput out, OutputStream stream)
          Write the ImageOutput object to the specified OutputStream.
 
Methods inherited from class org.faceless.graph2.tag.Embedder
getAction, getActionKeys, getAttribute, getAttributes, getFont, getFonts, getForeignXML, getGraph, getHeight, getId, getImageOutputStream, getImagePath, getPageResources, getPageWriter, getPaint, getWidth
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

PNGEmbedder

public PNGEmbedder()
Method Detail

getMIMEType

public String getMIMEType()
Description copied from class: Embedder
Get the MIME type for the image that will be written by this Embedder to Embedder.getImageOutputStream()

Specified by:
getMIMEType in class Embedder

convert

public void convert()
             throws IOException
Description copied from class: Embedder
Convert the object returned by Embedder.getGraph() to an appropriate binary form, write it to Embedder.getImageOutputStream() and write the HTML required to embed it to Embedder.getPageWriter(), referencing the image at Embedder.getImagePath(). At it's very minimum it could look something like this:
  ImageOutput output = new ImageOutput();
  getGraph().draw(output);
  output.writePNG(getImageOutputStream(), 0);
  getPageWriter().write("<img src='"+getImagePath()+"' />");
 
which is suitable for embedding an image with no mouse interaction.

Specified by:
convert in class Embedder
Throws:
IOException

createHTML

protected void createHTML(Map areamap,
                          StringBuffer script,
                          StringBuffer args,
                          Writer out)
                   throws IOException
Write the required HTML to the specified writer. This method is called at the end of convert() - it assembles the areamap into a <map> tag, puts the script into a <script> block, appends the appropriate <img> tag with the specified image and writes the result to out.

Parameters:
areamap - a Map containing zero or more [coords={[attr=value],...}] entries
script - the JavaScript to place in the HTML between <script> tags, if any.
args - the arguments to the img tag, eg "width='123' height='123' title='mygraph'"
out - the Writer to write to
Throws:
IOException

createImageOutput

protected ImageOutput createImageOutput()
                                 throws IOException
Create the ImageOutput object from the Graph object

Throws:
IOException

writeBitmap

protected void writeBitmap(ImageOutput out,
                           OutputStream stream)
                    throws IOException
Write the ImageOutput object to the specified OutputStream. The MIME-type of the image should match getMIMEType(), so subclasses that return a different type of image to PNG must override both methods.

Parameters:
out - the ImageOutput object (created by createImageOutput())
stream - the OutputStream to write the bitmap image to
Throws:
IOException

createPathString

protected static final String createPathString(PathIterator p)
Given a PathIterator which contains only the initial MOVETO and subsequent LINETO segments, return a String equivalent suitable for use in the "coords" attribute of an <area> tag.

Parameters:
p - the PathIterator
Returns:
a String version of the PathIterator, eg "1,1, 1,2, 2,2, 2,1"

fixActionString

protected String fixActionString(String action,
                                 String seriesname,
                                 String value)
Fix the "action" string for the specified attribute. Typically this will involve at least escaping the quotes - the default implementation also substitutes values for the seriesx and seriesy variables for any "onNNN" or JavaScript "href" attributes.

Parameters:
action - the action - from Embedder.ACTIONS, one of "href", "title", "onmouseover" or similar
seriesname - the name of the series this action is on, or null if no series applies
value - the value of the attribute specified by action
Returns:
the modified value parameter

addSeriesToAreaMap

protected void addSeriesToAreaMap(Area area,
                                  String key,
                                  Map imageareas,
                                  Series series,
                                  String seriesname,
                                  Map areamap)
For the given Area and key, add any events for this key to the areamap. At the end of this method areamap may have one or more additional entries of the form [coords,actions] where coords is a co-ordinates string suitable for the "coords" attribute in an <area> tag and actions is a Map of [attr,value] entries, where attr is one of Embedder.ACTIONS -"href", "title", "onmouseover" and so on.

Parameters:
area - the Area that a rollover should be created for
key - the item the area maps to, eg "graph.series.MySeries" or "graph.marker.MyMarker"
imageareas - the output of ImageOutput.getAreas()
series - the series if this map relates to one, or null otherwise
seriesname - if series!=null, the name of the series
areamap - the Map to be populated

addSeriesToScript

protected void addSeriesToScript(Area area,
                                 String key,
                                 Map imageareas,
                                 Series series,
                                 String seriesname,
                                 StringBuffer out)
Add any JavaScript necessary for this area to the script StringBuffer. The StringBuffer can be assembled here for each rollover area, and then any one-off changes to finalize it made in finalizeScript(java.lang.StringBuffer)

Parameters:
area - the Area of the rollover
key - the item the area maps to, eg "graph.series.MySeries" or "graph.marker.MyMarker"
imageareas - the output of ImageOutput.getAreas()
series - the series if this map relates to one, or null otherwise
seriesname - if series!=null, the name of the series
out - the StringBuffer that any JavaScript should be written to

finalizeScript

protected StringBuffer finalizeScript(StringBuffer script)
Modify the JavaScript created by addSeriesToScript(). Called just before the JavaScript is passed into createHTML().

Parameters:
script - the JavaScript to be modified
Returns:
the modified JavaScript


Copyright © 2001-2011 Big Faceless Organization