|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |
java.lang.Objectorg.faceless.graph2.tag.Embedder
org.faceless.graph2.tag.PNGEmbedder
public class PNGEmbedder
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.
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 |
---|
public PNGEmbedder()
Method Detail |
---|
public String getMIMEType()
Embedder
Embedder.getImageOutputStream()
getMIMEType
in class Embedder
public void convert() throws IOException
Embedder
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.
convert
in class Embedder
IOException
protected void createHTML(Map areamap, StringBuffer script, StringBuffer args, Writer out) throws IOException
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
.
areamap
- a Map containing zero or more [coords={[attr=value],...}] entriesscript
- 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
IOException
protected ImageOutput createImageOutput() throws IOException
IOException
protected void writeBitmap(ImageOutput out, OutputStream stream) throws IOException
getMIMEType()
, so subclasses that
return a different type of image to PNG must override both methods.
out
- the ImageOutput object (created by createImageOutput()
)stream
- the OutputStream to write the bitmap image to
IOException
protected static final String createPathString(PathIterator p)
p
- the PathIterator
protected String fixActionString(String action, String seriesname, String value)
seriesx
and seriesy
variables for any
"onNNN" or JavaScript "href" attributes.
action
- the action - from Embedder.ACTIONS
, one of "href", "title", "onmouseover" or similarseriesname
- the name of the series this action is on, or null
if no series appliesvalue
- the value of the attribute specified by action
value
parameterprotected void addSeriesToAreaMap(Area area, String key, Map imageareas, Series series, String seriesname, Map areamap)
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.
area
- the Area that a rollover should be created forkey
- 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 otherwiseseriesname
- if series!=null
, the name of the seriesareamap
- the Map to be populatedprotected void addSeriesToScript(Area area, String key, Map imageareas, Series series, String seriesname, StringBuffer out)
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)
area
- the Area of the rolloverkey
- 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
otherwiseseriesname
- if series!=null
, the name of the seriesout
- the StringBuffer that any JavaScript should be written toprotected StringBuffer finalizeScript(StringBuffer script)
addSeriesToScript()
. Called just before
the JavaScript is passed into createHTML()
.
script
- the JavaScript to be modified
|
||||||||||
PREV CLASS NEXT CLASS | FRAMES NO FRAMES | |||||||||
SUMMARY: NESTED | FIELD | CONSTR | METHOD | DETAIL: FIELD | CONSTR | METHOD |