Class SvgDocument


  • public class SvgDocument
    extends SvgContainer

    The SvgDocument is the base for all svg graphics. It is used to load an svg document from an inputstream or directly from a String.

    An svg document may contain one or more svg fragments, each of which can be accessed individually.

    See also: http://www.w3.org/TR/SVG

    • Field Detail

      • fragmentMap

        private java.util.Map<java.lang.String,​SvgFragment> fragmentMap
    • Constructor Detail

      • SvgDocument

        SvgDocument()
    • Method Detail

      • load

        public static SvgDocument load​(java.io.InputStream in)
        Create a new SvgDocument from the contents of the given InputStream.
        Parameters:
        in - an InputStream containing the svg source.
        Returns:
        a newly created SvgDocument
      • load

        public static SvgDocument load​(java.lang.String src)
        Create a new SvgDocument from the contents of the given String.
        Parameters:
        src - an String containing the svg source.
        Returns:
        a newly created SvgDocument
      • apply

        public void apply​(org.eclipse.swt.graphics.GC gc,
                          org.eclipse.swt.graphics.Rectangle bounds)
        Apply this svg document to the given graphics context, scaled to fit within the given bounds. This method will recursive call the apply methods of all contained svg elements, thereby painting the entire document to the given graphics context.
        Parameters:
        gc - the graphics context
        bounds - the bounds to which this document will be scaled
      • getDescription

        public java.lang.String getDescription()
        Description copied from class: SvgGraphic
        Returns the value of the desc element that is a child of this svg element. If there is no desc element that is a direct decendent of this element, null is returned.
        Overrides:
        getDescription in class SvgGraphic
        Returns:
        the desc of this svg element
      • getFragment

        public SvgFragment getFragment​(java.lang.String id)
        Returns the SvgFragment element within this document that corresponds to the given id.
        Parameters:
        id -
        Returns:
        an SvgFragment with the given id, or null if one does not exist
      • getFragments

        public SvgFragment[] getFragments()
        Returns an array of all the SvgFragment elements contained by this document. This is a new array - modification to it will not affect the underlying collection.
        Returns:
        an array of SvgFragments
      • getTitle

        public java.lang.String getTitle()
        Description copied from class: SvgGraphic
        Returns the value of the title element that is a child of this svg element. If there is no title element that is a direct decendent of this element, null is returned.
        Overrides:
        getTitle in class SvgGraphic
        Returns:
        the title of this svg element
      • hasFragment

        public boolean hasFragment​(java.lang.String id)
        Returns true if this document contains an SvgFragment with the given id.
        Parameters:
        id - the id of the fragment
        Returns:
        true if the fragment exists, false otherwise
      • isEmpty

        public boolean isEmpty()
        Description copied from class: SvgContainer
        Returns true if this list contains no elements.
        Overrides:
        isEmpty in class SvgContainer
        Returns:
        true if this list contains no elements.