com.googlecode.sarasvati.visual
Class GraphImageMapCreator

java.lang.Object
  extended by com.googlecode.sarasvati.visual.GraphImageMapCreator

public class GraphImageMapCreator
extends Object

Class which generates HTML image maps for graphs. This uses SarasvatiGraphScene internally, which can be used directly if more control is required.

Note: If using SarasvatiGraphScene, be sure to call GraphSceneImpl.setupForExportOnHeadless() before calling GraphSceneImpl.export(StringBuilder, Function, Function).
Example usage in a JSP:

  <%
    GraphToImageMapAdapter helper = new GraphToImageMapAdapter ()
    {
      public String hrefForNode (Node node)
      {
         return "javascript:alert( 'You have selected " + node.getName() + "' );";
       }

       public String hoverForNode (Node node)
       {
         return "Name: " + node.getName() + ",  Type: " + node.getType() +
                ",  Guard: " + node.getGuard() + ",  Is start: " + node.isStart() +
                ",  Is join: " + node.isJoin();
       }
    };

    String basePath = config.getServletContext().getRealPath( "/" );
    GraphImageMapCreator imageMapCreator = new GraphImageMapCreator( graph, helper );
    imageMapCreator.writeImageToFile( "gif", basepath + "/test-graph.gif" );
  %>

  <map name="graphMap">
    <%=imageMapCreator.getMapContents()%>
  </map>

  <div style="margin-left:10px; padding-top:10px">
    <image style="border:2px black solid" src="<%=request.getContextPath() + "/test-graph.gif"%>" usemap="#graphMap"/>
  </div>
  

Author:
Paul Lorenz

Constructor Summary
GraphImageMapCreator(Graph graph, GraphToImageMap graphToImageMap)
          Creates a new GraphImageMapCreate using the given graph and graph to image map helper.
 
Method Summary
 BufferedImage getImage()
          Returns the generated graph image.
 String getMapContents()
          Returns what should placed in a map tag.
 void writeImageToFile(String imageFormat, String imageFileName)
          Writes the generate graph image to a file in the given format
 
Methods inherited from class java.lang.Object
equals, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Constructor Detail

GraphImageMapCreator

public GraphImageMapCreator(Graph graph,
                            GraphToImageMap graphToImageMap)
Creates a new GraphImageMapCreate using the given graph and graph to image map helper. Will immediately generate the map contents and image.

Parameters:
graph - The graph to create an image map and image from.
graphToImageMap - Controls how the image and image map are constructed.
Method Detail

getMapContents

public String getMapContents()
Returns what should placed in a map tag.

Returns:
The contents of the image map, i.e. what should be placed between the map start and end tags

getImage

public BufferedImage getImage()
Returns the generated graph image. If you just want to write it to a file, you can use writeImageToFile(String, String).

Returns:
The generated graph image

writeImageToFile

public void writeImageToFile(String imageFormat,
                             String imageFileName)
                      throws IOException
Writes the generate graph image to a file in the given format

Parameters:
imageFormat - The informal name of the format to write the file in, as understood by ImageIO.
imageFileName - The name of the file to write the image to
Throws:
IOException - If an error occurs writing the image to disc