Differences between revisions 1 and 2
Revision 1 as of 2005-03-02 14:37:03
Size: 5925
Editor: StevenHuey
Comment:
Revision 2 as of 2009-09-20 23:47:36
Size: 5993
Editor: localhost
Comment: converted to 1.6 markup
Deletions are marked like this. Additions are marked like this.
Line 5: Line 5:
[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/JSVGCanvas.html JSVGCanvas] : [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html JSVGComponent] : [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/JGVTComponent.html JGVTComponent] : [http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.html JComponent] [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/JSVGCanvas.html|JSVGCanvas]] : [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html|JSVGComponent]] : [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/JGVTComponent.html|JGVTComponent]] : [[http://java.sun.com/j2se/1.4.2/docs/api/javax/swing/JComponent.html|JComponent]]
Line 7: Line 7:
After creating a [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/JSVGCanvas.html JSVGCanvas] instance the setURI() method is called with a URI of the SVG document to load. If the URI is valid the loadSVGDocument() method of the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html JSVGComponent] class is called with the URI. After creating a [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/JSVGCanvas.html|JSVGCanvas]] instance the setURI() method is called with a URI of the SVG document to load. If the URI is valid the loadSVGDocument() method of the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html|JSVGComponent]] class is called with the URI.
Line 9: Line 9:
In the loadSVGDocument() method all document processing for the current document is stopped, and then a [http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/DocumentLoader.html DocumentLoader] and [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGDocumentLoader.html SVGDocumentLoader] are created. The [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGDocumentLoader.html SVGDocumentLoader] handles the firing of document loading events and the [http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/DocumentLoader.html DocumentLoader] uses a [http://xml.apache.org/batik/javadoc/org/apache/batik/dom/svg/SAXSVGDocumentFactory.html SAXSVGDocumentFactory] to create a [http://xml.apache.org/batik/javadoc/org/w3c/dom/svg/SVGDocument.html SVGDocument] instance. The [http://xml.apache.org/batik/javadoc/org/apache/batik/dom/svg/SAXSVGDocumentFactory.html SAXSVGDocumentFactory] in turn relies on a [http://xml.apache.org/batik/javadoc/org/apache/batik/dom/util/SAXDocumentFactory.html SAXDocumentFactory] to parse the SVG data referenced by the given URI. In the loadSVGDocument() method all document processing for the current document is stopped, and then a [[http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/DocumentLoader.html|DocumentLoader]] and [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGDocumentLoader.html|SVGDocumentLoader]] are created. The [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGDocumentLoader.html|SVGDocumentLoader]] handles the firing of document loading events and the [[http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/DocumentLoader.html|DocumentLoader]] uses a [[http://xml.apache.org/batik/javadoc/org/apache/batik/dom/svg/SAXSVGDocumentFactory.html|SAXSVGDocumentFactory]] to create a [[http://xml.apache.org/batik/javadoc/org/w3c/dom/svg/SVGDocument.html|SVGDocument]] instance. The [[http://xml.apache.org/batik/javadoc/org/apache/batik/dom/svg/SAXSVGDocumentFactory.html|SAXSVGDocumentFactory]] in turn relies on a [[http://xml.apache.org/batik/javadoc/org/apache/batik/dom/util/SAXDocumentFactory.html|SAXDocumentFactory]] to parse the SVG data referenced by the given URI.
Line 11: Line 11:
The [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/JSVGCanvas.html JSVGCanvas] relies on the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderListener.html SVGDocumentLoaderListener], [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListener.html GVTTreeBuilderListener], and [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherListener.html SVGLoadEventDispatcherListener] listeners that are added in the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html JSVGComponent] constructor in order to know what is going on with the loading, building, and rendering of the [http://xml.apache.org/batik/javadoc/org/w3c/dom/svg/SVGDocument.html SVGDocument]. The listeners are implemented in the JGVTComponent.Listener and JSVGComponent.SVGListener classes. The [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/JSVGCanvas.html|JSVGCanvas]] relies on the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderListener.html|SVGDocumentLoaderListener]], [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListener.html|GVTTreeBuilderListener]], and [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherListener.html|SVGLoadEventDispatcherListener]] listeners that are added in the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html|JSVGComponent]] constructor in order to know what is going on with the loading, building, and rendering of the [[http://xml.apache.org/batik/javadoc/org/w3c/dom/svg/SVGDocument.html|SVGDocument]]. The listeners are implemented in the JGVTComponent.Listener and JSVGComponent.SVGListener classes.
Line 13: Line 13:
When the document has finished being loaded and parsed the setSVGDocument() method of the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html JSVGComponent] class is called, which then calls the installSVGDocument() method in the same class. When the document has finished being loaded and parsed the setSVGDocument() method of the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html|JSVGComponent]] class is called, which then calls the installSVGDocument() method in the same class.
Line 19: Line 19:
2. Create a new [http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/BridgeContext.html BridgeContext] to associate the SVG DOM and the GVT tree 2. Create a new [[http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/BridgeContext.html|BridgeContext]] to associate the SVG DOM and the GVT tree
Line 21: Line 21:
3. Configures the component and [http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/BridgeContext.html BridgeContext] instance based on the document state (ALWAYS_STATIC, ALWAYS_DYNAMIC, ALWAYS_INTERACTIVE, AUTODETECT) 3. Configures the component and [[http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/BridgeContext.html|BridgeContext]] instance based on the document state (ALWAYS_STATIC, ALWAYS_DYNAMIC, ALWAYS_INTERACTIVE, AUTODETECT)
Line 23: Line 23:
4. Creates a [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/GVTTreeBuilder.html GVTTreeBuilder] with the [http://xml.apache.org/batik/javadoc/org/w3c/dom/svg/SVGDocument.html SVGDocument] and [http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/BridgeContext.html BridgeContext] 4. Creates a [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/GVTTreeBuilder.html|GVTTreeBuilder]] with the [[http://xml.apache.org/batik/javadoc/org/w3c/dom/svg/SVGDocument.html|SVGDocument]] and [[http://xml.apache.org/batik/javadoc/org/apache/batik/bridge/BridgeContext.html|BridgeContext]]
Line 27: Line 27:
When the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/GVTTreeBuilder.html GVTTreeBuilder] is done building the GVT tree the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html JSVGComponent] performs some additional configuration so that dynamic documents work correctly, and then calls the scheduleGVTRendering() method of the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/JGVTComponent.html JGVTComponent] class. When the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/GVTTreeBuilder.html|GVTTreeBuilder]] is done building the GVT tree the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/svg/JSVGComponent.html|JSVGComponent]] performs some additional configuration so that dynamic documents work correctly, and then calls the scheduleGVTRendering() method of the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/JGVTComponent.html|JGVTComponent]] class.
Line 33: Line 33:
2. Creates either a static or dynamic image rendered based on the document state ([http://xml.apache.org/batik/javadoc/org/apache/batik/gvt/renderer/StaticRenderer.html StaticRenderer] or [http://xml.apache.org/batik/javadoc/org/apache/batik/gvt/renderer/DynamicRenderer.html DynamicRenderer]) 2. Creates either a static or dynamic image rendered based on the document state ([[http://xml.apache.org/batik/javadoc/org/apache/batik/gvt/renderer/StaticRenderer.html|StaticRenderer]] or [[http://xml.apache.org/batik/javadoc/org/apache/batik/gvt/renderer/DynamicRenderer.html|DynamicRenderer]])
Line 39: Line 39:
5. Creates a [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/GVTTreeRenderer.html GVTTreeRenderer] and starts the rendering thread 5. Creates a [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/GVTTreeRenderer.html|GVTTreeRenderer]] and starts the rendering thread
Line 41: Line 41:
The [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/GVTTreeRenderer.html GVTTreeRenderer] fires GVT tree rendering events and calls the repaint() method of the renderer. Once repainting is complete, the [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/JGVTComponent.html JGVTComponent] is notified of the fact by a GVT tree rendering event, and in response repaints the component using the updated image that was rendered offscreen by the renderer. The [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/GVTTreeRenderer.html|GVTTreeRenderer]] fires GVT tree rendering events and calls the repaint() method of the renderer. Once repainting is complete, the [[http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/JGVTComponent.html|JGVTComponent]] is notified of the fact by a GVT tree rendering event, and in response repaints the component using the updated image that was rendered offscreen by the renderer.

A Summary of Using the JSVGCanvas Class to Display a SVG Document

First of all it's important to note the class inheritance hierarchy being used here since several methods called from the JSVGCanvas class are actually implemented by some of the classes it inherits from.

JSVGCanvas : JSVGComponent : JGVTComponent : JComponent

After creating a JSVGCanvas instance the setURI() method is called with a URI of the SVG document to load. If the URI is valid the loadSVGDocument() method of the JSVGComponent class is called with the URI.

In the loadSVGDocument() method all document processing for the current document is stopped, and then a DocumentLoader and SVGDocumentLoader are created. The SVGDocumentLoader handles the firing of document loading events and the DocumentLoader uses a SAXSVGDocumentFactory to create a SVGDocument instance. The SAXSVGDocumentFactory in turn relies on a SAXDocumentFactory to parse the SVG data referenced by the given URI.

The JSVGCanvas relies on the SVGDocumentLoaderListener, GVTTreeBuilderListener, and SVGLoadEventDispatcherListener listeners that are added in the JSVGComponent constructor in order to know what is going on with the loading, building, and rendering of the SVGDocument. The listeners are implemented in the JGVTComponent.Listener and JSVGComponent.SVGListener classes.

When the document has finished being loaded and parsed the setSVGDocument() method of the JSVGComponent class is called, which then calls the installSVGDocument() method in the same class.

The installSVGDocument() method:

1. Gets rid of any resources from the previous document (if any)

2. Create a new BridgeContext to associate the SVG DOM and the GVT tree

3. Configures the component and BridgeContext instance based on the document state (ALWAYS_STATIC, ALWAYS_DYNAMIC, ALWAYS_INTERACTIVE, AUTODETECT)

4. Creates a GVTTreeBuilder with the SVGDocument and BridgeContext

5. Initializes event handling for mouse and keyboard events

When the GVTTreeBuilder is done building the GVT tree the JSVGComponent performs some additional configuration so that dynamic documents work correctly, and then calls the scheduleGVTRendering() method of the JGVTComponent class.

The scheduleGVTRendering() method calls the renderGVTTree() method of the same class and:

1. Sets the size of the visible rect to be the size of the component

2. Creates either a static or dynamic image rendered based on the document state (StaticRenderer or DynamicRenderer)

3. Finds the inverse of the rendering transform, which is set to the identity matrix

4. Creates a shape by transforming the rectangle found in step 1 with the matrix from step 3

5. Creates a GVTTreeRenderer and starts the rendering thread

The GVTTreeRenderer fires GVT tree rendering events and calls the repaint() method of the renderer. Once repainting is complete, the JGVTComponent is notified of the fact by a GVT tree rendering event, and in response repaints the component using the updated image that was rendered offscreen by the renderer.

BatikRenderingSummary (last edited 2009-09-20 23:47:36 by localhost)