Package com.kitfox.svg
Class SVGElement
- java.lang.Object
-
- com.kitfox.svg.SVGElement
-
- All Implemented Interfaces:
java.io.Serializable
- Direct Known Subclasses:
AnimationElement
,ClipPath
,Desc
,FillElement
,Filter
,FilterEffects
,Font
,FontFace
,Hkern
,Metadata
,Stop
,Style
,Title
,TransformableElement
public abstract class SVGElement extends java.lang.Object implements java.io.Serializable
- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description protected java.util.ArrayList<SVGElement>
children
private static java.util.regex.Pattern
COMMAND_PATTERN
(package private) java.util.LinkedList<SVGElement>
contexts
protected java.lang.String
cssClass
CSS class.protected SVGDiagram
diagram
The diagram this element belongs to(package private) boolean
dirty
protected java.lang.String
id
protected static java.util.Set<java.lang.String>
ignorePresAttrib
A list of presentation attributes to not include in the presentation attribute set.protected java.util.HashMap<java.lang.String,StyleAttribute>
inlineStyles
Styles defined for this elemnt via the style attribute.protected SVGElement
parent
protected java.util.HashMap<java.lang.String,StyleAttribute>
presAttribs
Presentation attributes set for this element.static long
serialVersionUID
static java.lang.String
SVG_NS
protected TrackManager
trackManager
Link to the universe we reside inprivate static java.util.regex.Pattern
TRANSFORM_PATTERN
private static java.util.regex.Pattern
WORD_PATTERN
protected java.net.URI
xmlBase
This element may override the URI we resolve against with an xml:base attribute.
-
Constructor Summary
Constructors Constructor Description SVGElement()
Creates a new instance of SVGElementSVGElement(java.lang.String id, SVGElement parent)
SVGElement(java.lang.String id, java.lang.String cssClass, SVGElement parent)
-
Method Summary
All Methods Static Methods Instance Methods Abstract Methods Concrete Methods Modifier and Type Method Description void
addAttribute(java.lang.String name, int attribType, java.lang.String value)
protected void
build()
Called by internal processes to rebuild the geometry of this node from it's presentation attributes, style attributes and animated tracks.protected static java.awt.geom.GeneralPath
buildPath(java.lang.String text, int windingRule)
SVGElement
getChild(int i)
SVGElement
getChild(java.lang.String id)
java.util.List<SVGElement>
getChildren(java.util.List<SVGElement> retVec)
java.lang.String
getId()
java.util.Set<java.lang.String>
getInlineAttributes()
int
getNumChildren()
SVGElement
getParent()
protected SVGElement
getParentContext()
java.util.List<SVGElement>
getPath(java.util.List<SVGElement> retVec)
boolean
getPres(StyleAttribute attrib)
Copies the presentation attribute into the passed one.StyleAttribute
getPresAbsolute(java.lang.String styName)
java.util.Set<java.lang.String>
getPresentationAttributes()
SVGRoot
getRoot()
boolean
getStyle(StyleAttribute attrib)
boolean
getStyle(StyleAttribute attrib, boolean recursive)
boolean
getStyle(StyleAttribute attrib, boolean recursive, boolean evalAnimation)
Copies the current style into the passed style attribute.StyleAttribute
getStyleAbsolute(java.lang.String styName)
abstract java.lang.String
getTagName()
java.net.URI
getXMLBase()
boolean
hasAttribute(java.lang.String name, int attribType)
int
indexOfChild(SVGElement child)
Searches children for given element.double
lerp(double t0, double t1, double alpha)
void
loaderAddChild(SVGLoaderHelper helper, SVGElement child)
Called after the start element but before the end element to indicate each child tag that has been processedvoid
loaderAddText(SVGLoaderHelper helper, java.lang.String text)
Called during load process to add text scanned within a tagvoid
loaderEndElement(SVGLoaderHelper helper)
Called to indicate that this tag and the tags it contains have been completely processed, and that it should finish any load processes.void
loaderStartElement(SVGLoaderHelper helper, org.xml.sax.Attributes attrs, SVGElement parent)
Called during SAX load process to notify that this tag has begun the process of being loadedprotected static float
nextFloat(java.util.LinkedList<java.lang.String> l)
protected static PathCommand[]
parsePathList(java.lang.String list)
static java.awt.geom.AffineTransform
parseSingleTransform(java.lang.String val)
protected static java.awt.geom.AffineTransform
parseTransform(java.lang.String val)
protected SVGElement
popParentContext()
protected void
pushParentContext(SVGElement context)
Hack to allow nodes to temporarily change their parents.void
removeAttribute(java.lang.String name, int attribType)
void
removeChild(SVGElement child)
void
setAttribute(java.lang.String name, int attribType, java.lang.String value)
protected void
setDiagram(SVGDiagram diagram)
(package private) void
setParent(SVGElement parent)
void
swapChildren(int i, int j)
Swaps 2 elements in children.abstract boolean
updateTime(double curTime)
Updates all attributes in this diagram associated with a time event.
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
SVG_NS
public static final java.lang.String SVG_NS
- See Also:
- Constant Field Values
-
parent
protected SVGElement parent
-
children
protected final java.util.ArrayList<SVGElement> children
-
id
protected java.lang.String id
-
cssClass
protected java.lang.String cssClass
CSS class. Used for applying style sheet information.
-
inlineStyles
protected final java.util.HashMap<java.lang.String,StyleAttribute> inlineStyles
Styles defined for this elemnt via the style attribute.
-
presAttribs
protected final java.util.HashMap<java.lang.String,StyleAttribute> presAttribs
Presentation attributes set for this element. Ie, any attribute other than the style attribute.
-
ignorePresAttrib
protected static final java.util.Set<java.lang.String> ignorePresAttrib
A list of presentation attributes to not include in the presentation attribute set.
-
xmlBase
protected java.net.URI xmlBase
This element may override the URI we resolve against with an xml:base attribute. If so, a copy is placed here. Otherwise, we defer to our parent for the reolution base
-
diagram
protected SVGDiagram diagram
The diagram this element belongs to
-
trackManager
protected final TrackManager trackManager
Link to the universe we reside in
-
dirty
boolean dirty
-
contexts
java.util.LinkedList<SVGElement> contexts
-
TRANSFORM_PATTERN
private static final java.util.regex.Pattern TRANSFORM_PATTERN
-
WORD_PATTERN
private static final java.util.regex.Pattern WORD_PATTERN
-
COMMAND_PATTERN
private static final java.util.regex.Pattern COMMAND_PATTERN
-
-
Constructor Detail
-
SVGElement
public SVGElement()
Creates a new instance of SVGElement
-
SVGElement
public SVGElement(java.lang.String id, SVGElement parent)
-
SVGElement
public SVGElement(java.lang.String id, java.lang.String cssClass, SVGElement parent)
-
-
Method Detail
-
getTagName
public abstract java.lang.String getTagName()
-
getParent
public SVGElement getParent()
-
setParent
void setParent(SVGElement parent)
-
getPath
public java.util.List<SVGElement> getPath(java.util.List<SVGElement> retVec)
- Parameters:
retVec
-- Returns:
- an ordered list of nodes from the root of the tree to this node
-
getChildren
public java.util.List<SVGElement> getChildren(java.util.List<SVGElement> retVec)
- Parameters:
retVec
- - A list to add all children to. If null, a new list is created and children of this group are added.- Returns:
- The list containing the children of this group
-
getChild
public SVGElement getChild(java.lang.String id)
- Parameters:
id
- - Id of svg element to return- Returns:
- the child of the given id, or null if no such child exists.
-
indexOfChild
public int indexOfChild(SVGElement child)
Searches children for given element. If found, returns index of child. Otherwise returns -1.- Parameters:
child
-- Returns:
- index of child
-
swapChildren
public void swapChildren(int i, int j) throws SVGException
Swaps 2 elements in children.- Parameters:
i
- index of first childj
- index of second child- Throws:
SVGException
-
loaderStartElement
public void loaderStartElement(SVGLoaderHelper helper, org.xml.sax.Attributes attrs, SVGElement parent) throws org.xml.sax.SAXException
Called during SAX load process to notify that this tag has begun the process of being loaded- Parameters:
attrs
- - Attributes of this taghelper
- - An object passed to all SVG elements involved in this build process to aid in sharing information.parent
-- Throws:
org.xml.sax.SAXException
-
removeAttribute
public void removeAttribute(java.lang.String name, int attribType)
-
addAttribute
public void addAttribute(java.lang.String name, int attribType, java.lang.String value) throws SVGElementException
- Throws:
SVGElementException
-
hasAttribute
public boolean hasAttribute(java.lang.String name, int attribType) throws SVGElementException
- Throws:
SVGElementException
-
getInlineAttributes
public java.util.Set<java.lang.String> getInlineAttributes()
- Returns:
- a set of Strings that corespond to CSS attributes on this element
-
getPresentationAttributes
public java.util.Set<java.lang.String> getPresentationAttributes()
- Returns:
- a set of Strings that corespond to XML attributes on this element
-
loaderAddChild
public void loaderAddChild(SVGLoaderHelper helper, SVGElement child) throws SVGElementException
Called after the start element but before the end element to indicate each child tag that has been processed- Parameters:
helper
-child
-- Throws:
SVGElementException
-
setDiagram
protected void setDiagram(SVGDiagram diagram)
-
removeChild
public void removeChild(SVGElement child) throws SVGElementException
- Throws:
SVGElementException
-
loaderAddText
public void loaderAddText(SVGLoaderHelper helper, java.lang.String text)
Called during load process to add text scanned within a tag- Parameters:
helper
-text
-
-
loaderEndElement
public void loaderEndElement(SVGLoaderHelper helper) throws SVGParseException
Called to indicate that this tag and the tags it contains have been completely processed, and that it should finish any load processes.- Parameters:
helper
-- Throws:
SVGParseException
-
build
protected void build() throws SVGException
Called by internal processes to rebuild the geometry of this node from it's presentation attributes, style attributes and animated tracks.- Throws:
SVGException
-
getXMLBase
public java.net.URI getXMLBase()
-
getId
public java.lang.String getId()
- Returns:
- the id assigned to this node. Null if no id explicitly set.
-
pushParentContext
protected void pushParentContext(SVGElement context)
Hack to allow nodes to temporarily change their parents. The Use tag will need this so it can alter the attributes that a particular node uses.- Parameters:
context
-
-
popParentContext
protected SVGElement popParentContext()
-
getParentContext
protected SVGElement getParentContext()
-
getRoot
public SVGRoot getRoot()
-
getStyle
public boolean getStyle(StyleAttribute attrib) throws SVGException
- Throws:
SVGException
-
setAttribute
public void setAttribute(java.lang.String name, int attribType, java.lang.String value) throws SVGElementException
- Throws:
SVGElementException
-
getStyle
public boolean getStyle(StyleAttribute attrib, boolean recursive) throws SVGException
- Throws:
SVGException
-
getStyle
public boolean getStyle(StyleAttribute attrib, boolean recursive, boolean evalAnimation) throws SVGException
Copies the current style into the passed style attribute. Checks for inline styles first, then internal and extranal style sheets, and finally checks for presentation attributes. Recursively checks parents.- Parameters:
attrib
- - Attribute to write style data to. Must have it's name set to the name of the style being queried.recursive
- - If true and this object does not contain the named style attribute, checks attributes of parents back to root until one found.evalAnimation
-- Returns:
- Throws:
SVGException
-
getStyleAbsolute
public StyleAttribute getStyleAbsolute(java.lang.String styName)
- Parameters:
styName
-- Returns:
- the raw style value of this attribute. Does not take the presentation value or animation into consideration. Used by animations to determine the base to animate from.
-
getPres
public boolean getPres(StyleAttribute attrib) throws SVGException
Copies the presentation attribute into the passed one.- Parameters:
attrib
-- Returns:
- - True if attribute was read successfully
- Throws:
SVGException
-
getPresAbsolute
public StyleAttribute getPresAbsolute(java.lang.String styName)
- Parameters:
styName
-- Returns:
- the raw presentation value of this attribute. Ignores any modifications applied by style attributes or animation. Used by animations to determine the starting point to animate from
-
parseTransform
protected static java.awt.geom.AffineTransform parseTransform(java.lang.String val) throws SVGException
- Throws:
SVGException
-
parseSingleTransform
public static java.awt.geom.AffineTransform parseSingleTransform(java.lang.String val) throws SVGException
- Throws:
SVGException
-
nextFloat
protected static float nextFloat(java.util.LinkedList<java.lang.String> l)
-
parsePathList
protected static PathCommand[] parsePathList(java.lang.String list)
-
buildPath
protected static java.awt.geom.GeneralPath buildPath(java.lang.String text, int windingRule)
-
updateTime
public abstract boolean updateTime(double curTime) throws SVGException
Updates all attributes in this diagram associated with a time event. Ie, all attributes with track information.- Parameters:
curTime
-- Returns:
- - true if this node has changed state as a result of the time update
- Throws:
SVGException
-
getNumChildren
public int getNumChildren()
-
getChild
public SVGElement getChild(int i)
-
lerp
public double lerp(double t0, double t1, double alpha)
-
-