yext.svg.view
Class SVGModel

java.lang.Object
  extended by yext.svg.view.SVGModel
All Implemented Interfaces:
Cloneable

public class SVGModel
extends Object
implements Cloneable

This class encapsulates an SVG scene graph. It can be used to render the SVG representation on a graphics context. Performance of SVG rendering can be fine-tuned by configuring an internally used caching mechanism.


Field Summary
static RenderingHints.Key KEY_SVG_RENDERING
          Hint to request a specific rendering mode for SVG content.
static int SVG_BOUNDS_POLICY_COMBINED
          SVG bounds policy specifier.
static int SVG_BOUNDS_POLICY_GEOMETRY
          SVG bounds policy specifier.
static int SVG_BOUNDS_POLICY_VISIBLE
          SVG bounds policy specifier.
static Object VALUE_SVG_RENDERING_DEFAULT
          SVG rendering hint value -- let the implementation decide whether to use vectorization or rasterization depending on the current configuration of the caching mechanism.
static Object VALUE_SVG_RENDERING_FORCE_RASTERIZATION
          SVG rendering hint value -- force rasterization of vector graphics even if image caching is disabled or the resulting image size exceeds the maximumImageSize value.
static Object VALUE_SVG_RENDERING_FORCE_VECTORIZATION
          SVG rendering hint value -- force vector graphics rendering even if image caching is enabled.
 
Constructor Summary
SVGModel()
          Creates an empty svg model.
SVGModel(Reader r)
          Creates a new model that represents the SVG definition accessible via the specified Reader.
SVGModel(URL svgURL)
          Creates a new model that represents the given SVG resource.
 
Method Summary
static void clearImageCache()
          Clears the image cache.
 Object clone()
           
 void deserializeSVGContent(Reader r)
          Replaces the SVG definition represented by this SVGModel to the one accessible via the specified Reader.
static int getImageCacheSize()
          Returns the maximum number of images that will be cached.
static int getMaximumImageSize()
          Returns the maximum size of images that will be cached.
static double getMinimumRelativeImageSize()
          Returns the minimum relative image size for which precached image duplicates are reused.
 Rectangle2D getSvgBounds()
          Returns the bounds of the SVG model.
 int getSVGBoundsPolicy()
          Returns the policy on how to determine the bounds of this svg node.
 URL getSVGURL()
          Returns the URL of the SVG graphics that was parsed to construct the model.
static boolean isImageCacheEnabled()
          Returns whether or not image caching is enabled.
 boolean isInitialized()
          Returns whether or not the model has been properly initialized.
 void paint(Graphics2D gfx, double x, double y, double width, double height)
          Renders the svg model to the given graphics context.
 void serializeSVGContent(Writer w)
          Writes the SVG definition represented by this SVGModel to the specified Writer.
static void setImageCacheEnabled(boolean imageCacheEnabled)
          Enables or disables image caching.
static void setImageCacheSize(int imageCacheSize)
          Sets the maximum number of images that will be cached.
static void setMaximumImageSize(int maximumImageSize)
          Sets the maximum size of images that will be cached.
static void setMinimumRelativeImageSize(double minimumRelativeImageSize)
          Sets the minimum relative image size for which precached image duplicates are reused.
 void setSVGBoundsPolicy(int svgBoundsPolicy)
          Sets the policy on how to determine the bounds of this svg entity.
 void setSVGURL(URL svgURL)
          model.
 
Methods inherited from class java.lang.Object
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
 

Field Detail

KEY_SVG_RENDERING

public static final RenderingHints.Key KEY_SVG_RENDERING
Hint to request a specific rendering mode for SVG content.


VALUE_SVG_RENDERING_FORCE_VECTORIZATION

public static final Object VALUE_SVG_RENDERING_FORCE_VECTORIZATION
SVG rendering hint value -- force vector graphics rendering even if image caching is enabled.


VALUE_SVG_RENDERING_FORCE_RASTERIZATION

public static final Object VALUE_SVG_RENDERING_FORCE_RASTERIZATION
SVG rendering hint value -- force rasterization of vector graphics even if image caching is disabled or the resulting image size exceeds the maximumImageSize value.


VALUE_SVG_RENDERING_DEFAULT

public static final Object VALUE_SVG_RENDERING_DEFAULT
SVG rendering hint value -- let the implementation decide whether to use vectorization or rasterization depending on the current configuration of the caching mechanism.

See Also:
isImageCacheEnabled(), getImageCacheSize(), getMaximumImageSize(), getMinimumRelativeImageSize()

SVG_BOUNDS_POLICY_VISIBLE

public static final int SVG_BOUNDS_POLICY_VISIBLE
SVG bounds policy specifier. Returns the bounds of the area covered by this node. This policy takes rendering attributes like transparency or the width of a stroke into account.

See Also:
Constant Field Values

SVG_BOUNDS_POLICY_GEOMETRY

public static final int SVG_BOUNDS_POLICY_GEOMETRY
SVG bounds policy specifier. Returns the bounds of the area covered by this node, without taking any of its rendering attribute into account.

See Also:
Constant Field Values

SVG_BOUNDS_POLICY_COMBINED

public static final int SVG_BOUNDS_POLICY_COMBINED
SVG bounds policy specifier. Returns the union of the bounds returned by the bounds policies SVG_BOUNDS_POLICY_VISIBLE and SVG_BOUNDS_POLICY_GEOMETRY.

See Also:
Constant Field Values
Constructor Detail

SVGModel

public SVGModel()
Creates an empty svg model.


SVGModel

public SVGModel(URL svgURL)
Creates a new model that represents the given SVG resource.


SVGModel

public SVGModel(Reader r)
Creates a new model that represents the SVG definition accessible via the specified Reader.

Method Detail

getSvgBounds

public Rectangle2D getSvgBounds()
Returns the bounds of the SVG model.


paint

public void paint(Graphics2D gfx,
                  double x,
                  double y,
                  double width,
                  double height)
Renders the svg model to the given graphics context. The SVG model will be translated and scaled to fit in the given box.


setSVGURL

public void setSVGURL(URL svgURL)
model. When setting a new URL the model will automatically change. Sets the URL of the SVG graphics that will be parsed to construct the


getSVGURL

public URL getSVGURL()
Returns the URL of the SVG graphics that was parsed to construct the model.


deserializeSVGContent

public void deserializeSVGContent(Reader r)
                           throws IOException
Replaces the SVG definition represented by this SVGModel to the one accessible via the specified Reader.

Throws:
IOException

serializeSVGContent

public void serializeSVGContent(Writer w)
                         throws IOException
Writes the SVG definition represented by this SVGModel to the specified Writer.

Throws:
IOException

isInitialized

public boolean isInitialized()
Returns whether or not the model has been properly initialized.


getSVGBoundsPolicy

public int getSVGBoundsPolicy()
Returns the policy on how to determine the bounds of this svg node. By default policy SVG_BOUNDS_POLICY_VISIBLE is set.

Returns:
one of SVG_BOUNDS_POLICY_VISIBLE, SVG_BOUNDS_POLICY_GEOMETRY, or SVG_BOUNDS_POLICY_COMBINED.

setSVGBoundsPolicy

public void setSVGBoundsPolicy(int svgBoundsPolicy)
Sets the policy on how to determine the bounds of this svg entity. By default policy SVG_BOUNDS_POLICY_VISIBLE is set.

Parameters:
svgBoundsPolicy - one of SVG_BOUNDS_POLICY_VISIBLE, SVG_BOUNDS_POLICY_GEOMETRY, or SVG_BOUNDS_POLICY_COMBINED.

clone

public Object clone()
Overrides:
clone in class Object

clearImageCache

public static void clearImageCache()
Clears the image cache.


isImageCacheEnabled

public static boolean isImageCacheEnabled()
Returns whether or not image caching is enabled.

See Also:
setImageCacheEnabled(boolean)

setImageCacheEnabled

public static void setImageCacheEnabled(boolean imageCacheEnabled)
Enables or disables image caching. Image caching is a performance optimization that tries to minimize expensive vector graphics rendering to a cached intermediate image that will be displayed instead. To achieve nice rendering quality images are created and cached for multiple zoom levels. The maximum size of cached images and the number of cached images can be configured. By default image caching is enabled.


getImageCacheSize

public static int getImageCacheSize()
Returns the maximum number of images that will be cached.

See Also:
setImageCacheSize(int)

setImageCacheSize

public static void setImageCacheSize(int imageCacheSize)
Sets the maximum number of images that will be cached. By default the maximum number of cached images is set to 10.


getMaximumImageSize

public static int getMaximumImageSize()
Returns the maximum size of images that will be cached.

See Also:
setMaximumImageSize(int)

setMaximumImageSize

public static void setMaximumImageSize(int maximumImageSize)
Sets the maximum size of images that will be cached. Image size is measured in bytes necessary to store it. For an image with size W x H the image size is W * H * 4. The width and height of an image is calulated by multiplying the width and height of the SVG by the scale factor of the graphics context it is rendered on. By default the maximum image size is set to 100.000 bytes.


getMinimumRelativeImageSize

public static double getMinimumRelativeImageSize()
Returns the minimum relative image size for which precached image duplicates are reused.

Returns:
the minimum relative image size for which precached image duplicates are reused.

setMinimumRelativeImageSize

public static void setMinimumRelativeImageSize(double minimumRelativeImageSize)
Sets the minimum relative image size for which precached image duplicates are reused. I.e. if the image cache is queried for an intermediate image for a given SVG definition and image size, a cache miss is avoided if there is a cached image for the given SVG definition and query width/cached width >= minimumRelativeImageSize as well as query height/cached height >= minimumRelativeImageSize hold. By default the minimum relative image size is set to 0.9.


© Copyright 2000-2007,
yWorks GmbH.
All rights reserved.