com.googlecode.sarasvati.visual
Class ProcessImageMapCreator

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

public class ProcessImageMapCreator
extends Object

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

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

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

      public String hoverForNode (VisualProcessNode node)
      {
        NodeToken token = node.getToken();
        if ( token == null )
        {
          return null;
        }
        return "Started: " + sdf.format( token.getCreateDate() ) +
               " Finished: " + (token.getCompleteDate() == null ? "Not yet finished" : sdf.format( token.getCompleteDate() ) ) ;
      }
    };

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

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

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

Author:
Paul Lorenz

Field Summary
protected  BufferedImage image
           
protected  String mapContents
           
 
Constructor Summary
ProcessImageMapCreator(GraphProcess process, ProcessToImageMap processToImageMap)
          Creates a new ProcessImageMapCreate using the given process and process to image map helper.
 
Method Summary
protected  void generateMapAndImage(GraphProcess process, ProcessToImageMap processToImageMap)
           
 BufferedImage getImage()
          Returns the generated process image.
 String getMapContents()
          Returns what should placed in a map tag.
 void writeImageToFile(String imageFormat, String imageFileName)
          Writes the generated process image to a file in the given format
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

mapContents

protected String mapContents

image

protected BufferedImage image
Constructor Detail

ProcessImageMapCreator

public ProcessImageMapCreator(GraphProcess process,
                              ProcessToImageMap processToImageMap)
Creates a new ProcessImageMapCreate using the given process and process to image map helper. Will immediately generate the map contents and image.

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

generateMapAndImage

protected void generateMapAndImage(GraphProcess process,
                                   ProcessToImageMap processToImageMap)

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 process image. If you just want to write it to a file, you can use writeImageToFile(String, String).

Returns:
The generated process image

writeImageToFile

public void writeImageToFile(String imageFormat,
                             String imageFileName)
                      throws IOException
Writes the generated process 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


Copyright © 2012. All Rights Reserved.