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.

When reading SVG definitions from URLs, the following encodings are supported:

Depending on the charset support of the Java platform used, the following encodings may be supported, too:

 

Field Summary
static byte BROKEN_LINK_POLICY_IGNORE
          Policy that results in broken links in displayed SVG documents being ignored.
static byte BROKEN_LINK_POLICY_SHOW_PLACEHOLDER
          Policy that results in a placeholder displayed for broken links in displayed SVG documents.
static byte BROKEN_LINK_POLICY_THROW_EXCEPTION
          Policy that results in an exception being thrown if there is a broken link in the displayed SVG document.
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 the value returned by getMaximumImageSize().
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.
 boolean equalsSVGContent(SVGModel other)
          Determines whether or not the SVG definition represented by this SVGModel equals the SVG definition represented in the given model.
static byte getBrokenLinkPolicy()
          Returns the policy for handling broken links in displayed SVG documents.
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 pre-cached 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 setBrokenLinkPolicy(byte policy)
          Specifies the policy for handling broken links in displayed SVG documents.
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 pre-cached 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)
          Sets the URL of the SVG graphics that will be parsed to construct the model.
 void updateSVGContent(URL svgURL)
          Replaces the SVG definition represented by this SVGModel to the one referenced by the specified URL.
 
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 the value returned by getMaximumImageSize().


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

BROKEN_LINK_POLICY_THROW_EXCEPTION

public static final byte BROKEN_LINK_POLICY_THROW_EXCEPTION
Policy that results in an exception being thrown if there is a broken link in the displayed SVG document.

See Also:
setBrokenLinkPolicy(byte), Constant Field Values

BROKEN_LINK_POLICY_IGNORE

public static final byte BROKEN_LINK_POLICY_IGNORE
Policy that results in broken links in displayed SVG documents being ignored.

See Also:
setBrokenLinkPolicy(byte), Constant Field Values

BROKEN_LINK_POLICY_SHOW_PLACEHOLDER

public static final byte BROKEN_LINK_POLICY_SHOW_PLACEHOLDER
Policy that results in a placeholder displayed for broken links in displayed SVG documents.

See Also:
setBrokenLinkPolicy(byte), 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.

Returns:
the bounds of the SVG model or null if no visual bounds can be determined.

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.


updateSVGContent

public void updateSVGContent(URL svgURL)
                      throws IOException
Replaces the SVG definition represented by this SVGModel to the one referenced by the specified URL.

Throws:
IOException

setSVGURL

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


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

equalsSVGContent

public boolean equalsSVGContent(SVGModel other)
Determines whether or not the SVG definition represented by this SVGModel equals the SVG definition represented in the given model.

The SVG definition represented by this SVGModel is the textual data written by method serializeSVGContent(Writer).

Parameters:
other - the SVGModel whose SVG definition is compared to this model's SVG definition.
Returns:
true if the SVG definition of both models are equal.

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 calculated 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 pre-cached image duplicates are reused.

Returns:
the minimum relative image size for which pre-cached image duplicates are reused.

setMinimumRelativeImageSize

public static void setMinimumRelativeImageSize(double minimumRelativeImageSize)
Sets the minimum relative image size for which pre-cached 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.


getBrokenLinkPolicy

public static byte getBrokenLinkPolicy()
Returns the policy for handling broken links in displayed SVG documents. Defaults to BROKEN_LINK_POLICY_THROW_EXCEPTION.

Returns:
one of BROKEN_LINK_POLICY_THROW_EXCEPTION, BROKEN_LINK_POLICY_IGNORE, and BROKEN_LINK_POLICY_SHOW_PLACEHOLDER.

setBrokenLinkPolicy

public static void setBrokenLinkPolicy(byte policy)
Specifies the policy for handling broken links in displayed SVG documents. Defaults to BROKEN_LINK_POLICY_THROW_EXCEPTION.

Parameters:
policy - one of BROKEN_LINK_POLICY_THROW_EXCEPTION, BROKEN_LINK_POLICY_IGNORE, and BROKEN_LINK_POLICY_SHOW_PLACEHOLDER.
Throws:
IllegalArgumentException - if the specified policy does not equal one of the aforementioned constants.


© Copyright 2002-2015,
yWorks GmbH.
All rights reserved.