Date: 2005-03-02T06:37:03 Editor: StevenHuey Wiki: XML Graphics - Batik Wiki Page: BatikRenderingSummary URL: http://wiki.apache.org/xmlgraphics-batik/BatikRenderingSummary
no comment New Page: = 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. [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] 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. 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. 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. 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. The installSVGDocument() method: 1. Gets rid of any resources from the previous document (if any) 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 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) 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] 5. Initializes event handling for mouse and keyboard events 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. 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 ([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]) 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 [http://xml.apache.org/batik/javadoc/org/apache/batik/swing/gvt/GVTTreeRenderer.html GVTTreeRenderer] and starts the rendering thread 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. --------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]