Package org.eclipse.nebula.cwt.svg
Class SvgDocument
- java.lang.Object
-
- org.eclipse.nebula.cwt.svg.SvgElement
-
- org.eclipse.nebula.cwt.svg.SvgGraphic
-
- org.eclipse.nebula.cwt.svg.SvgContainer
-
- org.eclipse.nebula.cwt.svg.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 Modifier and Type Field Description private java.util.Map<java.lang.String,SvgFragment>
fragmentMap
-
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
All Methods Static Methods Instance Methods Concrete Methods 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 thedesc
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 thetitle
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 givenInputStream
.static SvgDocument
load(java.lang.String src)
Create a new SvgDocument from the contents of the givenString
.-
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
-
-
-
-
Field Detail
-
fragmentMap
private java.util.Map<java.lang.String,SvgFragment> fragmentMap
-
-
Method Detail
-
load
public static SvgDocument load(java.io.InputStream in)
Create a new SvgDocument from the contents of the givenInputStream
.- Parameters:
in
- anInputStream
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 givenString
.- Parameters:
src
- anString
containing the svg source.- Returns:
- a newly created SvgDocument
-
add
void add(SvgElement element)
- Overrides:
add
in classSvgContainer
-
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 contextbounds
- the bounds to which this document will be scaled
-
getDescription
public java.lang.String getDescription()
Description copied from class:SvgGraphic
Returns the value of thedesc
element that is a child of this svg element. If there is nodesc
element that is a direct decendent of this element, null is returned.- Overrides:
getDescription
in classSvgGraphic
- Returns:
- the
desc
of this svg element
-
getFragment
public SvgFragment getFragment()
- Overrides:
getFragment
in classSvgElement
-
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 thetitle
element that is a child of this svg element. If there is notitle
element that is a direct decendent of this element, null is returned.- Overrides:
getTitle
in classSvgGraphic
- 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 classSvgContainer
- Returns:
- true if this list contains no elements.
-
-