Class SVGUniverse
- java.lang.Object
-
- com.kitfox.svg.SVGUniverse
-
- All Implemented Interfaces:
java.io.Serializable
public class SVGUniverse extends java.lang.Object implements java.io.SerializableMany SVG files can be loaded at one time. These files will quite likely need to reference one another. The SVG universe provides a container for all these files and the means for them to relate to each other.- See Also:
- Serialized Form
-
-
Field Summary
Fields Modifier and Type Field Description private java.beans.PropertyChangeSupportchangesprotected doublecurTimeCurrent time in this universe.private booleanimageDataInlineOnlystatic java.lang.StringINPUTSTREAM_SCHEME(package private) java.util.HashMap<java.net.URI,SVGDiagram>loadedDocsMaps document URIs to their loaded SVG diagrams.(package private) java.util.HashMap<java.lang.String,Font>loadedFonts(package private) java.util.HashMap<java.net.URL,java.lang.ref.SoftReference<java.awt.image.BufferedImage>>loadedImagesstatic longserialVersionUIDprivate booleanverbose
-
Constructor Summary
Constructors Constructor Description SVGUniverse()Creates a new instance of SVGUniverse
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description voidaddPropertyChangeListener(java.beans.PropertyChangeListener l)voidclear()Release all loaded SVG document from memoryprivate java.io.InputStreamcreateDocumentInputStream(java.io.InputStream is)Wraps input stream in a BufferedInputStream.SVGUniverseduplicate()Uses serialization to duplicate this universe.doublegetCurTime()Returns the current animation time in milliseconds.FontgetDefaultFont()SVGDiagramgetDiagram(java.net.URI xmlBase)SVGDiagramgetDiagram(java.net.URI xmlBase, boolean loadIfAbsent)Returns the diagram that has been loaded from this root.SVGElementgetElement(java.net.URI path)Returns the element of the document at the given URI.SVGElementgetElement(java.net.URI path, boolean loadIfAbsent)Looks up a href within our universe.SVGElementgetElement(java.net.URL path)FontgetFont(java.lang.String fontName)(package private) java.awt.image.BufferedImagegetImage(java.net.URL imageURL)java.util.ArrayList<java.net.URI>getLoadedDocumentURIs()Get list of uris of all loaded documents and subdocuments.java.net.URIgetStreamBuiltURI(java.lang.String name)Synthesize a URI for an SVGDiagram constructed from a stream.private org.xml.sax.XMLReadergetXMLReader()booleanisImageDataInlineOnly()booleanisVerbose()java.net.URIloadSVG(java.io.InputStream is, java.lang.String name)java.net.URIloadSVG(java.io.InputStream is, java.lang.String name, boolean forceLoad)java.net.URIloadSVG(java.io.Reader reader, java.lang.String name)java.net.URIloadSVG(java.io.Reader reader, java.lang.String name, boolean forceLoad)This routine allows you to create SVG documents from data streams that may not necessarily have a URL to load from.protected java.net.URIloadSVG(java.net.URI xmlBase, org.xml.sax.InputSource is)java.net.URIloadSVG(java.net.URL docRoot)java.net.URIloadSVG(java.net.URL docRoot, boolean forceLoad)Loads an SVG file and all the files it references from the URL provided.(package private) voidregisterFont(Font font)Called by the Font element to let the universe know that a font has been loaded and is available.(package private) java.net.URLregisterImage(java.net.URI imageURI)(package private) voidregisterImage(java.net.URL imageURL)voidremoveDocument(java.net.URI uri)Remove loaded document from cache.voidremovePropertyChangeListener(java.beans.PropertyChangeListener l)voidsetCurTime(double curTime)voidsetImageDataInlineOnly(boolean imageDataInlineOnly)voidsetVerbose(boolean verbose)voidupdateTime()Updates all time influenced style and presentation attributes in all SVG documents in this universe.
-
-
-
Field Detail
-
serialVersionUID
public static final long serialVersionUID
- See Also:
- Constant Field Values
-
changes
private transient java.beans.PropertyChangeSupport changes
-
loadedDocs
final java.util.HashMap<java.net.URI,SVGDiagram> loadedDocs
Maps document URIs to their loaded SVG diagrams. Note that URIs for documents loaded from URLs will reflect their URLs and URIs for documents initiated from streams will have the scheme svgSalamander.
-
loadedFonts
final java.util.HashMap<java.lang.String,Font> loadedFonts
-
loadedImages
final java.util.HashMap<java.net.URL,java.lang.ref.SoftReference<java.awt.image.BufferedImage>> loadedImages
-
INPUTSTREAM_SCHEME
public static final java.lang.String INPUTSTREAM_SCHEME
- See Also:
- Constant Field Values
-
curTime
protected double curTime
Current time in this universe. Used for resolving attributes that are influenced by track information. Time is in milliseconds. Time 0 coresponds to the time of 0 in each member diagram.
-
verbose
private boolean verbose
-
imageDataInlineOnly
private boolean imageDataInlineOnly
-
-
Method Detail
-
addPropertyChangeListener
public void addPropertyChangeListener(java.beans.PropertyChangeListener l)
-
removePropertyChangeListener
public void removePropertyChangeListener(java.beans.PropertyChangeListener l)
-
clear
public void clear()
Release all loaded SVG document from memory
-
getCurTime
public double getCurTime()
Returns the current animation time in milliseconds.
-
setCurTime
public void setCurTime(double curTime)
-
updateTime
public void updateTime() throws SVGExceptionUpdates all time influenced style and presentation attributes in all SVG documents in this universe.- Throws:
SVGException
-
registerFont
void registerFont(Font font)
Called by the Font element to let the universe know that a font has been loaded and is available.
-
getDefaultFont
public Font getDefaultFont()
-
getFont
public Font getFont(java.lang.String fontName)
-
registerImage
java.net.URL registerImage(java.net.URI imageURI)
-
registerImage
void registerImage(java.net.URL imageURL)
-
getImage
java.awt.image.BufferedImage getImage(java.net.URL imageURL)
-
getElement
public SVGElement getElement(java.net.URI path)
Returns the element of the document at the given URI. If the document is not already loaded, it will be.
-
getElement
public SVGElement getElement(java.net.URL path)
-
getElement
public SVGElement getElement(java.net.URI path, boolean loadIfAbsent)
Looks up a href within our universe. If the href refers to a document that is not loaded, it will be loaded. The URL #target will then be checked against the SVG diagram's index and the coresponding element returned. If there is no coresponding index, null is returned.
-
getDiagram
public SVGDiagram getDiagram(java.net.URI xmlBase)
-
getDiagram
public SVGDiagram getDiagram(java.net.URI xmlBase, boolean loadIfAbsent)
Returns the diagram that has been loaded from this root. If diagram is not already loaded, returns null.
-
createDocumentInputStream
private java.io.InputStream createDocumentInputStream(java.io.InputStream is) throws java.io.IOExceptionWraps input stream in a BufferedInputStream. If it is detected that this input stream is GZIPped, also wraps in a GZIPInputStream for inflation.- Parameters:
is- Raw input stream- Returns:
- Uncompressed stream of SVG data
- Throws:
java.io.IOException
-
loadSVG
public java.net.URI loadSVG(java.net.URL docRoot)
-
loadSVG
public java.net.URI loadSVG(java.net.URL docRoot, boolean forceLoad)Loads an SVG file and all the files it references from the URL provided. If a referenced file already exists in the SVG universe, it is not reloaded.- Parameters:
docRoot- - URL to the location where this SVG file can be found.forceLoad- - if true, ignore cached diagram and reload- Returns:
- - The URI that refers to the loaded document
-
loadSVG
public java.net.URI loadSVG(java.io.InputStream is, java.lang.String name) throws java.io.IOException- Throws:
java.io.IOException
-
loadSVG
public java.net.URI loadSVG(java.io.InputStream is, java.lang.String name, boolean forceLoad) throws java.io.IOException- Throws:
java.io.IOException
-
loadSVG
public java.net.URI loadSVG(java.io.Reader reader, java.lang.String name)
-
loadSVG
public java.net.URI loadSVG(java.io.Reader reader, java.lang.String name, boolean forceLoad)This routine allows you to create SVG documents from data streams that may not necessarily have a URL to load from. Since every SVG document must be identified by a unique URL, Salamander provides a method to fake this for streams by defining it's own protocol - svgSalamander - for SVG documents without a formal URL.- Parameters:
reader- - A stream containing a valid SVG documentname- -A unique name for this document. It will be used to construct a unique URI to refer to this document and perform resolution with relative URIs within this document.
For example, a name of "/myScene" will produce the URI svgSalamander:/myScene. "/maps/canada/toronto" will produce svgSalamander:/maps/canada/toronto. If this second document then contained the href "../uk/london", it would resolve by default to svgSalamander:/maps/uk/london. That is, SVG Salamander defines the URI scheme svgSalamander for it's own internal use and uses it for uniquely identfying documents loaded by stream.
If you need to link to documents outside of this scheme, you can either supply full hrefs (eg, href="url(http://www.kitfox.com/index.html)") or put the xml:base attribute in a tag to change the defaultbase URIs are resolved against
If a name does not start with the character '/', it will be automatically prefixed to it.
forceLoad- - if true, ignore cached diagram and reload- Returns:
- - The URI that refers to the loaded document
-
getStreamBuiltURI
public java.net.URI getStreamBuiltURI(java.lang.String name)
Synthesize a URI for an SVGDiagram constructed from a stream.- Parameters:
name- - Name given the document constructed from a stream.
-
getXMLReader
private org.xml.sax.XMLReader getXMLReader() throws org.xml.sax.SAXException, javax.xml.parsers.ParserConfigurationException- Throws:
org.xml.sax.SAXExceptionjavax.xml.parsers.ParserConfigurationException
-
loadSVG
protected java.net.URI loadSVG(java.net.URI xmlBase, org.xml.sax.InputSource is)
-
getLoadedDocumentURIs
public java.util.ArrayList<java.net.URI> getLoadedDocumentURIs()
Get list of uris of all loaded documents and subdocuments.- Returns:
-
removeDocument
public void removeDocument(java.net.URI uri)
Remove loaded document from cache.- Parameters:
uri-
-
isVerbose
public boolean isVerbose()
-
setVerbose
public void setVerbose(boolean verbose)
-
duplicate
public SVGUniverse duplicate() throws java.io.IOException, java.lang.ClassNotFoundException
Uses serialization to duplicate this universe.- Throws:
java.io.IOExceptionjava.lang.ClassNotFoundException
-
isImageDataInlineOnly
public boolean isImageDataInlineOnly()
- Returns:
- the imageDataInlineOnly
-
setImageDataInlineOnly
public void setImageDataInlineOnly(boolean imageDataInlineOnly)
- Parameters:
imageDataInlineOnly- the imageDataInlineOnly to set
-
-