org.netbeans.api.visual 2.23.1

org.netbeans.api.visual.export
Class SceneExporter

java.lang.Object
  extended by org.netbeans.api.visual.export.SceneExporter

public final class SceneExporter
extends Object

This is a convenience class for exporting a Scene as an image file (jpeg, png, etc.). There is an additional utility is this class to retrieve a list of WidgetPolygonalCoordinates. This list holds widget-polygon tuples designed to be used to create HTML imagemaps. The following example code shows how this imagemap could be created.

ArrayList<WidgetPolygonalCoordinates> list = null ; try { list = SceneExporter.createImageMap(scene, imageFile, imageType, zoomType, visibleAreaOnly, selectedOnly, quality, horizontal, vertical, margin); } catch (Exception e) { //Something bad happened return; } html.append("<img src=\"scene.jpg\" usemap=\"#WidgetMap\"/>\n"); String[] mapSections = new String[list.size()]; int count = 0; for (WidgetPolygonalCoordinates wc: list) { Widget widget = wc.getWidget(); String name = "no name"; if (widget instanceof SimpleWidget) { name = ((SimpleWidget) widget).getUserObject().getLabel(); } else if (widget instanceof SimpleConnectionWidget) { name = ((SimpleConnectionWidget) widget).getUserObject().getLabel(); } String coordinateString = pointsToString(wc.getPolygon()); mapSections[count++] = "<area shape=\"polygon\" coords=\"" + coordinateString + "\" href=\"#" + name + "\">"; html.append("<li><a name=\"").append(name).append("\">"); html.append(name).append("</a><br>\n"); html.append(getRandomText(100)).append("</li>\n"); } html.append("\n<map name=\"WidgetMap\">\n"); for (String s : mapSections) { html.append(s).append("\n"); } html.append("</map>");


Nested Class Summary
static class SceneExporter.ImageType
          This enumeration holds the possible image formats that the SceneExporter can export to.
static class SceneExporter.ZoomType
          This enumeration holds the zooming capabilities that the SceneExporter can export according to.
 
Method Summary
static BufferedImage createImage(Scene scene, File file, SceneExporter.ImageType imageType, SceneExporter.ZoomType zoomType, boolean visibleAreaOnly, boolean selectedOnly, int quality, int width, int height)
          Takes the Scene and writes an image file according to the constraints defined by the caller.
static ArrayList<WidgetPolygonalCoordinates> createImageMap(Scene scene, File file, SceneExporter.ImageType imageType, SceneExporter.ZoomType zoomType, boolean visibleAreaOnly, boolean selectedOnly, int quality, int width, int height, int margin)
          Designed to create an HTML image map from an exported image.
 
Methods inherited from class java.lang.Object
clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Method Detail

createImageMap

public static ArrayList<WidgetPolygonalCoordinates> createImageMap(Scene scene,
                                                                   File file,
                                                                   SceneExporter.ImageType imageType,
                                                                   SceneExporter.ZoomType zoomType,
                                                                   boolean visibleAreaOnly,
                                                                   boolean selectedOnly,
                                                                   int quality,
                                                                   int width,
                                                                   int height,
                                                                   int margin)
                                                            throws IOException
Designed to create an HTML image map from an exported image. Each Layer in the Scene provided to the constructor is iterated over and a java.awt.Polygon is created surrounding each Widget contained in the layers. A WidgetPolygonalCoordinates is created to hold the Widget and Polygon.

Parameters:
scene - The Scene to be exported as an image. The Widgets will be collected from this scene and polygons create that wrap each widget. The coordinates of each polygon are stored in an instance of WidgetPolygonalCoordinates.
file - The file used to store the exported image. If null, the method immediately returns null.
SceneExporter.ImageType - The image type to be exported for the image map.
SceneExporter.ZoomType - Defines the strategy by which to set the exporting scale factor. Note that certain parameters are nullified by the choice of ZoomType. For instance, if ZoomType.CUSTOM_SIZE is not chosen, then the width and height parameters are not used.
visibleAreaOnly - Eliminates all zoom features. If true, the exported image will be a created from the visible area of the scene.
selectedOnly - Create an image including only the objects selected on the scene. Note that this feature requires that the scene is an instance of an ObjectScene since it is the implementation that allows for object selection.
quality - And integer value between 0-100. This is for JPG images only. Parameter is not used if an image type other than jpg is selected.
width - Directly sets the horizontal dimension of the exported image. This is only used when the zoomType is ZoomType.CUSTOM_SIZE
height - Directly sets the vertical dimension of the exported image. This is only used when the zoomType is ZoomType.CUSTOM_SIZE.
margin - The size of the clickable margin around each connection. This is meant for defining the sensitivity of the links around the connection objects. Note that the area around the node objects is not affected by this margin.
Returns:
ArrayList of WidgetPolygonalCoordinates objects which are simply used to hold a Widget and Polygon. From the calling class, the widget and coordinates can be used to create a link for the widget on an HTML image map.
Throws:
IOException - If for some reason the file cannot be written, an IOExeption will be thrown.

createImage

public static BufferedImage createImage(Scene scene,
                                        File file,
                                        SceneExporter.ImageType imageType,
                                        SceneExporter.ZoomType zoomType,
                                        boolean visibleAreaOnly,
                                        boolean selectedOnly,
                                        int quality,
                                        int width,
                                        int height)
                                 throws IOException
Takes the Scene and writes an image file according to the constraints defined by the caller. This returns a BufferedImage of the Scene even if the file can not be written.

Parameters:
scene - The Scene to be exported as an image.
file - The file used to store the exported image. If null, then it is assumed that the raw image is to be returned only and not written to a file.
SceneExporter.ImageType - The image type to be exported for the image map.
SceneExporter.ZoomType - Defines the strategy by which to set the exporting scale factor. Note that certain parameters are nullified by the choice of ZoomType. For instance, if ZoomType.CUSTOM_SIZE is not chosen, then the width and height parameters are not used.
visibleAreaOnly - Eliminates all zoom features. If true, the exported image will be a created from the visible area of the scene.
selectedOnly - Create an image including only the objects selected on the scene. Note that this feature requires that the scene is an instance of an ObjectScene since it is the implementation that allows for object selection.
quality - And integer value between 0-100. This is for JPG images only. Parameter is not used if an image type other than jpg is selected.
width - Directly sets the horizontal dimension of the exported image. This is only used when the zoomType is ZoomType.CUSTOM_SIZE
height - Directly sets the vertical dimension of the exported image. This is only used when the zoomType is ZoomType.CUSTOM_SIZE.
Returns:
image The raw image that was written to the file.
Throws:
IOException - If for some reason the file cannot be written, an IOExeption will be thrown.

org.netbeans.api.visual 2.23.1

Built on February 9 2011.  |  Portions Copyright 1997-2011 Sun Microsystems, Inc. All rights reserved.