Class SVGVectorImage

  • All Implemented Interfaces:
    VectorImage

    public class SVGVectorImage
    extends AbstractVectorImage
    A vector image whose content is loaded from an SVG source file. Most SVG 1.1 files should be compatible; scripting and animation are not supported since the VectorImage class represents a static image rather than a dynamic, interactive object.

    This class requires that the SVG_IMAGE_SUPPORT core component be installed, as that plug-in contains support code necessary to render the SVG content. If that library is not installed, but the SVGVectorImage constructor is called from the event dispatch thread (EDT), then the user will be given the opportunity to immediately download and install the missing component. If the user chooses not to, or if the constructor is called from a thread other than the EDT, then a MissingCoreComponentException exception will be thrown from the constructor.

    Since:
    3.0
    Author:
    Chris Jennings
    • Constructor Detail

      • SVGVectorImage

        public SVGVectorImage​(java.io.File file)
                       throws java.io.IOException
        Creates a vector image from SVG content stored in a file.
        Parameters:
        file - the file to load content from
        Throws:
        java.io.IOException - if an I/O error occurs while loading the content
        java.lang.IllegalArgumentException - if the vector content is invalid
        CoreComponents.MissingCoreComponentException - if the SVG support library is not installed and the user chooses not to install it
      • SVGVectorImage

        public SVGVectorImage​(java.net.URL location)
                       throws java.io.IOException
        Creates a vector image from SVG content stored at a URL.
        Parameters:
        location - the URL to load content from
        Throws:
        java.io.IOException - if an I/O error occurs while loading the content
        java.lang.IllegalArgumentException - if the vector content is invalid
        CoreComponents.MissingCoreComponentException - if the SVG support library is not installed and the user chooses not to install it
    • Method Detail

      • render

        protected void render​(java.awt.Graphics2D g)
        Description copied from class: AbstractVectorImage
        Renders the vector image into the specified graphics context. The upper left corner of the image should be at (-tx, -ty) and cover an area with width AbstractVectorImage.iw and height AbstractVectorImage.ih. Any changes to the state of the graphics context (stroke, paint, clip, etc.) must be restored before the method returns.
        Specified by:
        render in class AbstractVectorImage
        Parameters:
        g - the graphics context to render the image into
      • finalize

        @Deprecated
        protected void finalize()
                         throws java.lang.Throwable
        Deprecated.
        Overrides:
        finalize in class java.lang.Object
        Throws:
        java.lang.Throwable
      • isSupported

        public static boolean isSupported()
        Returns true if the SVG core library is installed. Note that it is not required to call this before attempting to create an SVG image. If possible, the SVG core will be loaded on demand (see the class description for details).
        Returns:
        true if SVG image file support is available