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 Summary

    Fields inherited from class org.eclipse.nebula.cwt.svg.SvgContainer

    elements

    Fields inherited from class org.eclipse.nebula.cwt.svg.SvgGraphic

    description, fill, stroke, title, transform
  • Constructor Summary

    Constructors 
    Constructor Description
    SvgDocument()  
  • Method Summary

    Modifier and Type Method Description
    (package private) void add​(SvgElement element)  
    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.
    java.lang.String getDescription()
    Returns the value of the desc element that is a child of this svg element.
    SvgFragment getFragment()  
    SvgFragment getFragment​(java.lang.String id)
    Returns the SvgFragment element within this document that corresponds to the given id.
    SvgFragment[] getFragments()
    Returns an array of all the SvgFragment elements contained by this document.
    java.lang.String getTitle()
    Returns the value of the title element that is a child of this svg element.
    boolean hasFragment​(java.lang.String id)
    Returns true if this document contains an SvgFragment with the given id.
    boolean isEmpty()
    Returns true if this list contains no elements.
    static SvgDocument load​(java.io.InputStream in)
    Create a new SvgDocument from the contents of the given InputStream.
    static SvgDocument load​(java.lang.String src)
    Create a new SvgDocument from the contents of the given String.

    Methods inherited from class org.eclipse.nebula.cwt.svg.SvgContainer

    apply, getElements

    Methods inherited from class org.eclipse.nebula.cwt.svg.SvgGraphic

    getFill, getStroke, getTransform

    Methods inherited from class org.eclipse.nebula.cwt.svg.SvgElement

    getAncestry, getContainer, getElement, getId, getViewport, setContainer

    Methods inherited from class java.lang.Object

    clone, equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, wait
  • Constructor Details

  • Method Details

    • 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
    • add

      void add​(SvgElement element)
      Overrides:
      add in class SvgContainer
    • 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()
      Overrides:
      getFragment in class SvgElement
    • 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.