xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r840735 [5/19] - in /websites/staging/xmlgraphics/trunk/content: ./ batik/ batik/dev/ batik/tools/ batik/using/ batik/using/scripting/ commons/ fop/ fop/0.95/ fop/1.0/ fop/1.1/ fop/trunk/
Date Tue, 04 Dec 2012 15:59:44 GMT
Modified: websites/staging/xmlgraphics/trunk/content/batik/using/swing.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/batik/using/swing.html (original)
+++ websites/staging/xmlgraphics/trunk/content/batik/using/swing.html Tue Dec  4 15:59:34 2012
@@ -171,115 +171,115 @@ $(document).ready(function () {
 <h2 id="creating-a-jsvgcanvas-wzxhzdk2wzxhzdk3">Creating a JSVGCanvas <a id="creatingJSVGCanvas"></a></h2>
 <p>The following example illustrates how to create a <code>JSVGCanvas</code> , which is a Swing component that follows the Swing design rule. This means that the component is not thread safe and all operations on the component or the document it is displaying must be performed as described in <a href="http://java.sun.com/docs/books/tutorial/uiswing/overview/threads.html">the Swing tutorial</a> . The <code>JSVGCanvas</code> is also a <a href="http://java.sun.com/products/javabeans/">JavaBean</a> , so it can be used in visual application builders.
 If you try this example, do not forget to set your <code>CLASSPATH</code> so that it contains the Batik classes and resources, as well as Xerces ( <code>lib/xerces_2_5_0.jar</code> ) and the XML APIs jars ( <code>lib/xml-apis.jar</code> and <code>lib/xml-apis-ext.jar</code> ).</p>
-<div class="codehilite"><pre><span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">awt</span><span class="o">.</span><span class="n">event</span><span class="o">.*</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">java</span><span class="o">.</span><span class="n">io</span><span class="o">.*</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">javax</span><span class="o">.</span><span class="n">swing</span><span class="o">.*</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">JSVGCanvas</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">gvt</span><span class="o">.</span><span class="n">GVTTreeRendererAdapter</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">gvt</span><span class="o">.</span><span class="n">GVTTreeRendererEvent</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">svg</span><span class="o">.</span><span class="n">SVGDocumentLoaderAdapter</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">svg</span><span class="o">.</span><span class="n">SVGDocumentLoaderEvent</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">svg</span><span class="o">.</span><span class="n">GVTTreeBuilderAdapter</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">apache</span><span class="o">.</span><span class="n">batik</span><span class="o">.</span><span class="n">swing</span><span class="o">.</span><span class="n">svg</span><span class="o">.</span><span class="n">GVTTreeBuilderEvent</span><span class="p">;</span>
-
-<span class="n">public</span> <span class="n">class</span> <span class="n">SVGApplication</span> <span class="p">{</span>
-
-    <span class="n">public</span> <span class="n">static</span> <span class="n">void</span> <span class="n">main</span><span class="p">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="p">)</span> <span class="p">{</span>
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="k">new</span> <span class="n">JFrame</span><span class="o">.</span>
-        <span class="n">JFrame</span> <span class="n">f</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFrame</span><span class="p">(</span><span class="s">&quot;Batik&quot;</span><span class="p">);</span>
-        <span class="n">SVGApplication</span> <span class="n">app</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGApplication</span><span class="p">(</span><span class="n">f</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Add</span> <span class="n">components</span> <span class="n">to</span> <span class="n">the</span> <span class="n">frame</span><span class="o">.</span>
-        <span class="n">f</span><span class="o">.</span><span class="n">getContentPane</span><span class="p">()</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">app</span><span class="o">.</span><span class="n">createComponents</span><span class="p">());</span>
-
-        <span class="sr">//</span> <span class="n">Display</span> <span class="n">the</span> <span class="n">frame</span><span class="o">.</span>
-        <span class="n">f</span><span class="o">.</span><span class="n">addWindowListener</span><span class="p">(</span><span class="k">new</span> <span class="n">WindowAdapter</span><span class="p">()</span> <span class="p">{</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">windowClosing</span><span class="p">(</span><span class="n">WindowEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">System</span><span class="o">.</span><span class="nb">exit</span><span class="p">(</span><span class="mi">0</span><span class="p">);</span>
-            <span class="p">}</span>
-        <span class="p">});</span>
-        <span class="n">f</span><span class="o">.</span><span class="n">setSize</span><span class="p">(</span><span class="mi">400</span><span class="p">,</span> <span class="mi">400</span><span class="p">);</span>
-        <span class="n">f</span><span class="o">.</span><span class="n">setVisible</span><span class="p">(</span><span class="n">true</span><span class="p">);</span>
-    <span class="p">}</span>
-
-    <span class="sr">//</span> <span class="n">The</span> <span class="n">frame</span><span class="o">.</span>
-    <span class="n">protected</span> <span class="n">JFrame</span> <span class="n">frame</span><span class="p">;</span>
-
-    <span class="sr">//</span> <span class="n">The</span> <span class="s">&quot;Load&quot;</span> <span class="n">button</span><span class="p">,</span> <span class="n">which</span> <span class="n">displays</span> <span class="n">up</span> <span class="n">a</span> <span class="n">file</span> <span class="n">chooser</span> <span class="n">upon</span> <span class="n">clicking</span><span class="o">.</span>
-    <span class="n">protected</span> <span class="n">JButton</span> <span class="n">button</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JButton</span><span class="p">(</span><span class="s">&quot;Load...&quot;</span><span class="p">);</span>
-
-    <span class="sr">//</span> <span class="n">The</span> <span class="n">status</span> <span class="n">label</span><span class="o">.</span>
-    <span class="n">protected</span> <span class="n">JLabel</span> <span class="n">label</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JLabel</span><span class="p">();</span>
-
-    <span class="sr">//</span> <span class="n">The</span> <span class="n">SVG</span> <span class="n">canvas</span><span class="o">.</span>
-    <span class="n">protected</span> <span class="n">JSVGCanvas</span> <span class="n">svgCanvas</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JSVGCanvas</span><span class="p">();</span>
-
-    <span class="n">public</span> <span class="n">SVGApplication</span><span class="p">(</span><span class="n">JFrame</span> <span class="n">f</span><span class="p">)</span> <span class="p">{</span>
-        <span class="n">frame</span> <span class="o">=</span> <span class="n">f</span><span class="p">;</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">JComponent</span> <span class="n">createComponents</span><span class="p">()</span> <span class="p">{</span>
-        <span class="sr">//</span> <span class="n">Create</span> <span class="n">a</span> <span class="n">panel</span> <span class="ow">and</span> <span class="n">add</span> <span class="n">the</span> <span class="n">button</span><span class="p">,</span> <span class="n">status</span> <span class="n">label</span> <span class="ow">and</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">canvas</span><span class="o">.</span>
-        <span class="n">final</span> <span class="n">JPanel</span> <span class="n">panel</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JPanel</span><span class="p">(</span><span class="k">new</span> <span class="n">BorderLayout</span><span class="p">());</span>
-
-        <span class="n">JPanel</span> <span class="n">p</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JPanel</span><span class="p">(</span><span class="k">new</span> <span class="n">FlowLayout</span><span class="p">(</span><span class="n">FlowLayout</span><span class="o">.</span><span class="n">LEFT</span><span class="p">));</span>
-        <span class="n">p</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">button</span><span class="p">);</span>
-        <span class="n">p</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="n">label</span><span class="p">);</span>
-
-        <span class="n">panel</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&quot;North&quot;</span><span class="p">,</span> <span class="n">p</span><span class="p">);</span>
-        <span class="n">panel</span><span class="o">.</span><span class="n">add</span><span class="p">(</span><span class="s">&quot;Center&quot;</span><span class="p">,</span> <span class="n">svgCanvas</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">button</span> <span class="n">action</span><span class="o">.</span>
-        <span class="n">button</span><span class="o">.</span><span class="n">addActionListener</span><span class="p">(</span><span class="k">new</span> <span class="n">ActionListener</span><span class="p">()</span> <span class="p">{</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">actionPerformed</span><span class="p">(</span><span class="n">ActionEvent</span> <span class="n">ae</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">JFileChooser</span> <span class="n">fc</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFileChooser</span><span class="p">(</span><span class="s">&quot;.&quot;</span><span class="p">);</span>
-                <span class="nb">int</span> <span class="n">choice</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">showOpenDialog</span><span class="p">(</span><span class="n">panel</span><span class="p">);</span>
-                <span class="k">if</span> <span class="p">(</span><span class="n">choice</span> <span class="o">==</span> <span class="n">JFileChooser</span><span class="o">.</span><span class="n">APPROVE_OPTION</span><span class="p">)</span> <span class="p">{</span>
-                    <span class="n">File</span> <span class="n">f</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="n">getSelectedFile</span><span class="p">();</span>
-                    <span class="n">try</span> <span class="p">{</span>
-                        <span class="n">svgCanvas</span><span class="o">.</span><span class="n">setURI</span><span class="p">(</span><span class="n">f</span><span class="o">.</span><span class="n">toURL</span><span class="p">()</span><span class="o">.</span><span class="n">toString</span><span class="p">());</span>
-                    <span class="p">}</span> <span class="n">catch</span> <span class="p">(</span><span class="n">IOException</span> <span class="n">ex</span><span class="p">)</span> <span class="p">{</span>
-                        <span class="n">ex</span><span class="o">.</span><span class="n">printStackTrace</span><span class="p">();</span>
-                    <span class="p">}</span>
-                <span class="p">}</span>
-            <span class="p">}</span>
-        <span class="p">});</span>
-
-        <span class="sr">//</span> <span class="n">Set</span> <span class="n">the</span> <span class="n">JSVGCanvas</span> <span class="n">listeners</span><span class="o">.</span>
-        <span class="n">svgCanvas</span><span class="o">.</span><span class="n">addSVGDocumentLoaderListener</span><span class="p">(</span><span class="k">new</span> <span class="n">SVGDocumentLoaderAdapter</span><span class="p">()</span> <span class="p">{</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">documentLoadingStarted</span><span class="p">(</span><span class="n">SVGDocumentLoaderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Document Loading...&quot;</span><span class="p">);</span>
-            <span class="p">}</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">documentLoadingCompleted</span><span class="p">(</span><span class="n">SVGDocumentLoaderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Document Loaded.&quot;</span><span class="p">);</span>
-            <span class="p">}</span>
-        <span class="p">});</span>
-
-        <span class="n">svgCanvas</span><span class="o">.</span><span class="n">addGVTTreeBuilderListener</span><span class="p">(</span><span class="k">new</span> <span class="n">GVTTreeBuilderAdapter</span><span class="p">()</span> <span class="p">{</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">gvtBuildStarted</span><span class="p">(</span><span class="n">GVTTreeBuilderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Build Started...&quot;</span><span class="p">);</span>
-            <span class="p">}</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">gvtBuildCompleted</span><span class="p">(</span><span class="n">GVTTreeBuilderEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Build Done.&quot;</span><span class="p">);</span>
-                <span class="n">frame</span><span class="o">.</span><span class="nb">pack</span><span class="p">();</span>
-            <span class="p">}</span>
-        <span class="p">});</span>
-
-        <span class="n">svgCanvas</span><span class="o">.</span><span class="n">addGVTTreeRendererListener</span><span class="p">(</span><span class="k">new</span> <span class="n">GVTTreeRendererAdapter</span><span class="p">()</span> <span class="p">{</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">gvtRenderingPrepare</span><span class="p">(</span><span class="n">GVTTreeRendererEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;Rendering Started...&quot;</span><span class="p">);</span>
-            <span class="p">}</span>
-            <span class="n">public</span> <span class="n">void</span> <span class="n">gvtRenderingCompleted</span><span class="p">(</span><span class="n">GVTTreeRendererEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                <span class="n">label</span><span class="o">.</span><span class="n">setText</span><span class="p">(</span><span class="s">&quot;&quot;</span><span class="p">);</span>
-            <span class="p">}</span>
-        <span class="p">});</span>
-
-        <span class="k">return</span> <span class="n">panel</span><span class="p">;</span>
-    <span class="p">}</span>
-<span class="p">}</span>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.awt.*</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.awt.event.*</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.io.*</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">javax.swing.*</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.JSVGCanvas</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.gvt.GVTTreeRendererAdapter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.gvt.GVTTreeRendererEvent</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.svg.SVGDocumentLoaderAdapter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.svg.SVGDocumentLoaderEvent</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.svg.GVTTreeBuilderAdapter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.svg.GVTTreeBuilderEvent</span><span class="o">;</span>
+
+<span class="kd">public</span> <span class="kd">class</span> <span class="nc">SVGApplication</span> <span class="o">{</span>
+
+    <span class="kd">public</span> <span class="kd">static</span> <span class="kt">void</span> <span class="nf">main</span><span class="o">(</span><span class="n">String</span><span class="o">[]</span> <span class="n">args</span><span class="o">)</span> <span class="o">{</span>
+        <span class="c1">// Create a new JFrame.</span>
+        <span class="n">JFrame</span> <span class="n">f</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFrame</span><span class="o">(</span><span class="s">&quot;Batik&quot;</span><span class="o">);</span>
+        <span class="n">SVGApplication</span> <span class="n">app</span> <span class="o">=</span> <span class="k">new</span> <span class="n">SVGApplication</span><span class="o">(</span><span class="n">f</span><span class="o">);</span>
+
+        <span class="c1">// Add components to the frame.</span>
+        <span class="n">f</span><span class="o">.</span><span class="na">getContentPane</span><span class="o">().</span><span class="na">add</span><span class="o">(</span><span class="n">app</span><span class="o">.</span><span class="na">createComponents</span><span class="o">());</span>
+
+        <span class="c1">// Display the frame.</span>
+        <span class="n">f</span><span class="o">.</span><span class="na">addWindowListener</span><span class="o">(</span><span class="k">new</span> <span class="n">WindowAdapter</span><span class="o">()</span> <span class="o">{</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">windowClosing</span><span class="o">(</span><span class="n">WindowEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">System</span><span class="o">.</span><span class="na">exit</span><span class="o">(</span><span class="mi">0</span><span class="o">);</span>
+            <span class="o">}</span>
+        <span class="o">});</span>
+        <span class="n">f</span><span class="o">.</span><span class="na">setSize</span><span class="o">(</span><span class="mi">400</span><span class="o">,</span> <span class="mi">400</span><span class="o">);</span>
+        <span class="n">f</span><span class="o">.</span><span class="na">setVisible</span><span class="o">(</span><span class="kc">true</span><span class="o">);</span>
+    <span class="o">}</span>
+
+    <span class="c1">// The frame.</span>
+    <span class="kd">protected</span> <span class="n">JFrame</span> <span class="n">frame</span><span class="o">;</span>
+
+    <span class="c1">// The &quot;Load&quot; button, which displays up a file chooser upon clicking.</span>
+    <span class="kd">protected</span> <span class="n">JButton</span> <span class="n">button</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JButton</span><span class="o">(</span><span class="s">&quot;Load...&quot;</span><span class="o">);</span>
+
+    <span class="c1">// The status label.</span>
+    <span class="kd">protected</span> <span class="n">JLabel</span> <span class="n">label</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JLabel</span><span class="o">();</span>
+
+    <span class="c1">// The SVG canvas.</span>
+    <span class="kd">protected</span> <span class="n">JSVGCanvas</span> <span class="n">svgCanvas</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JSVGCanvas</span><span class="o">();</span>
+
+    <span class="kd">public</span> <span class="nf">SVGApplication</span><span class="o">(</span><span class="n">JFrame</span> <span class="n">f</span><span class="o">)</span> <span class="o">{</span>
+        <span class="n">frame</span> <span class="o">=</span> <span class="n">f</span><span class="o">;</span>
+    <span class="o">}</span>
+
+    <span class="kd">public</span> <span class="n">JComponent</span> <span class="nf">createComponents</span><span class="o">()</span> <span class="o">{</span>
+        <span class="c1">// Create a panel and add the button, status label and the SVG canvas.</span>
+        <span class="kd">final</span> <span class="n">JPanel</span> <span class="n">panel</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JPanel</span><span class="o">(</span><span class="k">new</span> <span class="n">BorderLayout</span><span class="o">());</span>
+
+        <span class="n">JPanel</span> <span class="n">p</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JPanel</span><span class="o">(</span><span class="k">new</span> <span class="n">FlowLayout</span><span class="o">(</span><span class="n">FlowLayout</span><span class="o">.</span><span class="na">LEFT</span><span class="o">));</span>
+        <span class="n">p</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">button</span><span class="o">);</span>
+        <span class="n">p</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="n">label</span><span class="o">);</span>
+
+        <span class="n">panel</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">&quot;North&quot;</span><span class="o">,</span> <span class="n">p</span><span class="o">);</span>
+        <span class="n">panel</span><span class="o">.</span><span class="na">add</span><span class="o">(</span><span class="s">&quot;Center&quot;</span><span class="o">,</span> <span class="n">svgCanvas</span><span class="o">);</span>
+
+        <span class="c1">// Set the button action.</span>
+        <span class="n">button</span><span class="o">.</span><span class="na">addActionListener</span><span class="o">(</span><span class="k">new</span> <span class="n">ActionListener</span><span class="o">()</span> <span class="o">{</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">actionPerformed</span><span class="o">(</span><span class="n">ActionEvent</span> <span class="n">ae</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">JFileChooser</span> <span class="n">fc</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFileChooser</span><span class="o">(</span><span class="s">&quot;.&quot;</span><span class="o">);</span>
+                <span class="kt">int</span> <span class="n">choice</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="na">showOpenDialog</span><span class="o">(</span><span class="n">panel</span><span class="o">);</span>
+                <span class="k">if</span> <span class="o">(</span><span class="n">choice</span> <span class="o">==</span> <span class="n">JFileChooser</span><span class="o">.</span><span class="na">APPROVE_OPTION</span><span class="o">)</span> <span class="o">{</span>
+                    <span class="n">File</span> <span class="n">f</span> <span class="o">=</span> <span class="n">fc</span><span class="o">.</span><span class="na">getSelectedFile</span><span class="o">();</span>
+                    <span class="k">try</span> <span class="o">{</span>
+                        <span class="n">svgCanvas</span><span class="o">.</span><span class="na">setURI</span><span class="o">(</span><span class="n">f</span><span class="o">.</span><span class="na">toURL</span><span class="o">().</span><span class="na">toString</span><span class="o">());</span>
+                    <span class="o">}</span> <span class="k">catch</span> <span class="o">(</span><span class="n">IOException</span> <span class="n">ex</span><span class="o">)</span> <span class="o">{</span>
+                        <span class="n">ex</span><span class="o">.</span><span class="na">printStackTrace</span><span class="o">();</span>
+                    <span class="o">}</span>
+                <span class="o">}</span>
+            <span class="o">}</span>
+        <span class="o">});</span>
+
+        <span class="c1">// Set the JSVGCanvas listeners.</span>
+        <span class="n">svgCanvas</span><span class="o">.</span><span class="na">addSVGDocumentLoaderListener</span><span class="o">(</span><span class="k">new</span> <span class="n">SVGDocumentLoaderAdapter</span><span class="o">()</span> <span class="o">{</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">documentLoadingStarted</span><span class="o">(</span><span class="n">SVGDocumentLoaderEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">label</span><span class="o">.</span><span class="na">setText</span><span class="o">(</span><span class="s">&quot;Document Loading...&quot;</span><span class="o">);</span>
+            <span class="o">}</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">documentLoadingCompleted</span><span class="o">(</span><span class="n">SVGDocumentLoaderEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">label</span><span class="o">.</span><span class="na">setText</span><span class="o">(</span><span class="s">&quot;Document Loaded.&quot;</span><span class="o">);</span>
+            <span class="o">}</span>
+        <span class="o">});</span>
+
+        <span class="n">svgCanvas</span><span class="o">.</span><span class="na">addGVTTreeBuilderListener</span><span class="o">(</span><span class="k">new</span> <span class="n">GVTTreeBuilderAdapter</span><span class="o">()</span> <span class="o">{</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">gvtBuildStarted</span><span class="o">(</span><span class="n">GVTTreeBuilderEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">label</span><span class="o">.</span><span class="na">setText</span><span class="o">(</span><span class="s">&quot;Build Started...&quot;</span><span class="o">);</span>
+            <span class="o">}</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">gvtBuildCompleted</span><span class="o">(</span><span class="n">GVTTreeBuilderEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">label</span><span class="o">.</span><span class="na">setText</span><span class="o">(</span><span class="s">&quot;Build Done.&quot;</span><span class="o">);</span>
+                <span class="n">frame</span><span class="o">.</span><span class="na">pack</span><span class="o">();</span>
+            <span class="o">}</span>
+        <span class="o">});</span>
+
+        <span class="n">svgCanvas</span><span class="o">.</span><span class="na">addGVTTreeRendererListener</span><span class="o">(</span><span class="k">new</span> <span class="n">GVTTreeRendererAdapter</span><span class="o">()</span> <span class="o">{</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">gvtRenderingPrepare</span><span class="o">(</span><span class="n">GVTTreeRendererEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">label</span><span class="o">.</span><span class="na">setText</span><span class="o">(</span><span class="s">&quot;Rendering Started...&quot;</span><span class="o">);</span>
+            <span class="o">}</span>
+            <span class="kd">public</span> <span class="kt">void</span> <span class="nf">gvtRenderingCompleted</span><span class="o">(</span><span class="n">GVTTreeRendererEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                <span class="n">label</span><span class="o">.</span><span class="na">setText</span><span class="o">(</span><span class="s">&quot;&quot;</span><span class="o">);</span>
+            <span class="o">}</span>
+        <span class="o">});</span>
+
+        <span class="k">return</span> <span class="n">panel</span><span class="o">;</span>
+    <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
 
 
@@ -287,24 +287,23 @@ If you try this example, do not forget t
 
 <h1 id="handling-events-wzxhzdk4wzxhzdk5">Handling events <a id="eventhandling"></a></h1>
 <p>Each time you set a URI or an SVG DOM tree to be displayed in a <code>JSVGCanvas</code> (using the <code>setURI</code> or <code>setSVGDocument</code> method), the specified document is first parsed (in case of a URI), built, rendered and optionally updated. The proper way to be notified of these different phases is to implement a listener and attach it to the component. There are five types of listener:</p>
-<dl>
-<dt><code>SVGDocumentLoaderListener</code></dt>
-<dd>The <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderListener">SVGDocumentLoaderListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderEvent">SVGDocumentLoaderEvent</a> events. It describes the loading phase: contructing an SVG DOM tree using an SVG file.</dd>
-<dt><code>GVTTreeBuilderListener</code></dt>
-<dd>The <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListener">GVTTreeBuilderListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderEvent">GVTTreeBuilderEvent</a> events. It describes the building phase: contructing a GVT (Graphics Vector Toolkit) tree using an SVG DOM tree. The GVT tree will then be used to render the document.</dd>
-<dt><code>SVGLoadEventDispatcherListener</code></dt>
-<dd>The <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherListener">SVGLoadEventDispatcherListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherEvent">SVGLoadEventDispatcherEvent</a> events. It describes the DOM <code>SVGLoad</code> event dispatch phase.</dd>
-</dl>
+<p><code>SVGDocumentLoaderListener</code>
+:
+The <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderListener">SVGDocumentLoaderListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderEvent">SVGDocumentLoaderEvent</a> events. It describes the loading phase: contructing an SVG DOM tree using an SVG file.</p>
+<p><code>GVTTreeBuilderListener</code>
+:
+The <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListener">GVTTreeBuilderListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderEvent">GVTTreeBuilderEvent</a> events. It describes the building phase: contructing a GVT (Graphics Vector Toolkit) tree using an SVG DOM tree. The GVT tree will then be used to render the document.</p>
+<p><code>SVGLoadEventDispatcherListener</code>
+:
+The <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherListener">SVGLoadEventDispatcherListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherEvent">SVGLoadEventDispatcherEvent</a> events. It describes the DOM <code>SVGLoad</code> event dispatch phase.</p>
 <p>This event is triggered only in dynamic documents.</p>
-<dl>
-<dt><code>GVTTreeRendererListener</code></dt>
-<dd>The <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererListener.html">GVTTreeRendererListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererEvent.html">GVTTreeRendererEvent</a> events. It describes the rendering phase: constructing an image using a GVT tree.</dd>
-</dl>
+<p><code>GVTTreeRendererListener</code>
+:
+The <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererListener.html">GVTTreeRendererListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererEvent.html">GVTTreeRendererEvent</a> events. It describes the rendering phase: constructing an image using a GVT tree.</p>
 <p>In dynamic documents this event is fired only once for the initial rendering.</p>
-<dl>
-<dt><code>UpdateManagerListener</code></dt>
-<dd>The <a href="../javadoc/org/apache/batik/bridge/UpdateManagerListener">UpdateManagerListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/bridge/UpdateManagerEvent">UpdateManagerEvent</a> events. It describes the running phase: the update manager is started and then it can be suspended, resumed or stopped, and graphics updates can be tracked.</dd>
-</dl>
+<p><code>UpdateManagerListener</code>
+:
+The <a href="../javadoc/org/apache/batik/bridge/UpdateManagerListener">UpdateManagerListener</a> provides a set of methods that can be used to track <a href="../javadoc/org/apache/batik/bridge/UpdateManagerEvent">UpdateManagerEvent</a> events. It describes the running phase: the update manager is started and then it can be suspended, resumed or stopped, and graphics updates can be tracked.</p>
 <p>This event is triggered only in dynamic documents.</p>
 <p>These listeners give a complete description of the different steps of the five phases (including error states). Adapter classes are available to ease the creation of new listener implementation— <a href="../javadoc/org/apache/batik/swing/svg/SVGDocumentLoaderAdapter.html">SVGDocumentLoaderAdapter</a> , <a href="../javadoc/org/apache/batik/swing/svg/GVTTreeBuilderListenerAdapter.html">GVTTreeBuilderListenerAdapter</a> , <a href="../javadoc/org/apache/batik/swing/svg/SVGLoadEventDispatcherAdapter.html">SVGLoadEventDispatcherAdapter</a> , <a href="../javadoc/org/apache/batik/swing/gvt/GVTTreeRendererAdapter.html">GVTTreeRendererAdapter</a> and <a href="../javadoc/org/apache/batik/bridge/UpdateManagerAdapter.html">UpdateManagerAdapter</a> ,</p>
 <p>For static documents, you can assume that the JSVGCanvas has completed its job (parsing, building and rendering) when the <code>gvtRenderingCompleted</code> method call is called, following a <code>setURI</code> or a <code>setSVGDocument</code> method call.</p>



---------------------------------------------------------------------
To unsubscribe, e-mail: commits-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: commits-help@xmlgraphics.apache.org


Mime
View raw message