xmlgraphics-commits mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From build...@apache.org
Subject svn commit: r840735 [3/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/scripting/java.html
==============================================================================
--- websites/staging/xmlgraphics/trunk/content/batik/using/scripting/java.html (original)
+++ websites/staging/xmlgraphics/trunk/content/batik/using/scripting/java.html Tue Dec  4 15:59:34 2012
@@ -171,136 +171,136 @@ $(document).ready(function () {
 <h2 id="how-to-manipulate-a-document-in-a-jsvgcanvas-wzxhzdk6wzxhzdk7">How to manipulate a document in a JSVGCanvas <a id="Swing"></a></h2>
 <p>The follow code template demonstrates how to manipulate an SVG document displayed in a <a href="../../javadoc/org/apache/batik/swing/JSVGCanvas.html">JSVGCanvas</a> directly from a Java program.
 You don’t have to worry about graphics updates; after each event listener invocation the canvas is updated if needed.</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="n">event</span><span class="o">.</span><span class="n">WindowAdapter</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="n">WindowEvent</span><span class="p">;</span>
+<div class="codehilite"><pre><span class="kn">import</span> <span class="nn">java.awt.event.WindowAdapter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">java.awt.event.WindowEvent</span><span class="o">;</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="n">JFrame</span><span class="p">;</span>
+<span class="kn">import</span> <span class="nn">javax.swing.JFrame</span><span class="o">;</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">svg</span><span class="o">.</span><span class="n">SVGLoadEventDispatcherAdapter</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">SVGLoadEventDispatcherEvent</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">script</span><span class="o">.</span><span class="n">Window</span><span class="p">;</span>
-
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Document</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">Element</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">events</span><span class="o">.</span><span class="n">Event</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">events</span><span class="o">.</span><span class="n">EventListener</span><span class="p">;</span>
-<span class="nb">import</span> <span class="n">org</span><span class="o">.</span><span class="n">w3c</span><span class="o">.</span><span class="n">dom</span><span class="o">.</span><span class="n">events</span><span class="o">.</span><span class="n">EventTarget</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="k">new</span> <span class="n">SVGApplication</span><span class="p">();</span>
-    <span class="p">}</span>
-
-    <span class="n">JFrame</span> <span class="n">frame</span><span class="p">;</span>
-    <span class="n">JSVGCanvas</span> <span class="n">canvas</span><span class="p">;</span>
-    <span class="n">Document</span> <span class="n">document</span><span class="p">;</span>
-    <span class="n">Window</span> <span class="n">window</span><span class="p">;</span>
-
-    <span class="n">public</span> <span class="n">SVGApplication</span><span class="p">()</span> <span class="p">{</span>
-        <span class="n">frame</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFrame</span><span class="p">();</span>
-        <span class="n">canvas</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JSVGCanvas</span><span class="p">();</span>
-        <span class="sr">//</span> <span class="n">Forces</span> <span class="n">the</span> <span class="n">canvas</span> <span class="n">to</span> <span class="n">always</span> <span class="n">be</span> <span class="n">dynamic</span> <span class="n">even</span> <span class="k">if</span> <span class="n">the</span> <span class="n">current</span>
-        <span class="sr">//</span> <span class="n">document</span> <span class="n">does</span> <span class="ow">not</span> <span class="n">contain</span> <span class="n">scripting</span> <span class="ow">or</span> <span class="n">animation</span><span class="o">.</span>
-        <span class="n">canvas</span><span class="o">.</span><span class="n">setDocumentState</span><span class="p">(</span><span class="n">JSVGCanvas</span><span class="o">.</span><span class="n">ALWAYS_DYNAMIC</span><span class="p">);</span>
-        <span class="n">canvas</span><span class="o">.</span><span class="n">addSVGLoadEventDispatcherListener</span>
-            <span class="p">(</span><span class="k">new</span> <span class="n">SVGLoadEventDispatcherAdapter</span><span class="p">()</span> <span class="p">{</span>
-                    <span class="n">public</span> <span class="n">void</span> <span class="n">svgLoadEventDispatchStarted</span>
-                        <span class="p">(</span><span class="n">SVGLoadEventDispatcherEvent</span> <span class="n">e</span><span class="p">)</span> <span class="p">{</span>
-                        <span class="sr">//</span> <span class="n">At</span> <span class="n">this</span> <span class="nb">time</span> <span class="n">the</span> <span class="n">document</span> <span class="n">is</span> <span class="n">available</span><span class="o">...</span>
-                        <span class="n">document</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">getSVGDocument</span><span class="p">();</span>
-                        <span class="sr">//</span> <span class="o">...</span><span class="ow">and</span> <span class="n">the</span> <span class="n">window</span> <span class="n">object</span> <span class="n">too</span><span class="o">.</span>
-                        <span class="n">window</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="n">getUpdateManager</span><span class="p">()</span><span class="o">.</span>
-                            <span class="n">getScriptingEnvironment</span><span class="p">()</span><span class="o">.</span><span class="n">createWindow</span><span class="p">();</span>
-                        <span class="sr">//</span> <span class="n">Registers</span> <span class="n">the</span> <span class="n">listeners</span> <span class="n">on</span> <span class="n">the</span> <span class="n">document</span>
-                        <span class="sr">//</span> <span class="n">just</span> <span class="n">before</span> <span class="n">the</span> <span class="n">SVGLoad</span> <span class="n">event</span> <span class="n">is</span>
-                        <span class="sr">//</span> <span class="n">dispatched</span><span class="o">.</span>
-                        <span class="n">registerListeners</span><span class="p">();</span>
-                        <span class="sr">//</span> <span class="n">It</span> <span class="n">is</span> <span class="nb">time</span> <span class="n">to</span> <span class="nb">pack</span> <span class="n">the</span> <span class="n">frame</span><span class="o">.</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">frame</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">windowOpened</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="sr">//</span> <span class="n">The</span> <span class="n">canvas</span> <span class="n">is</span> <span class="n">ready</span> <span class="n">to</span> <span class="n">load</span> <span class="n">the</span> <span class="n">base</span> <span class="n">document</span>
-                    <span class="sr">//</span> <span class="n">now</span><span class="p">,</span> <span class="n">from</span> <span class="n">the</span> <span class="n">AWT</span> <span class="n">thread</span><span class="o">.</span>
-                    <span class="n">canvas</span><span class="o">.</span><span class="n">setURI</span><span class="p">(</span><span class="s">&quot;doc.svg&quot;</span><span class="p">);</span>
-                <span class="p">}</span>
-            <span class="p">});</span>
-
-        <span class="n">frame</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">canvas</span><span class="p">);</span>
-        <span class="n">frame</span><span class="o">.</span><span class="n">setSize</span><span class="p">(</span><span class="mi">800</span><span class="p">,</span> <span class="mi">600</span><span class="p">);</span>
-        <span class="n">frame</span><span class="o">.</span><span class="n">show</span><span class="p">();</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">void</span> <span class="n">registerListeners</span><span class="p">()</span> <span class="p">{</span>
-        <span class="sr">//</span> <span class="n">Gets</span> <span class="n">an</span> <span class="n">element</span> <span class="n">from</span> <span class="n">the</span> <span class="n">loaded</span> <span class="n">document</span><span class="o">.</span>
-        <span class="n">Element</span> <span class="n">elt</span> <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="n">getElementById</span><span class="p">(</span><span class="s">&quot;elt-id&quot;</span><span class="p">);</span>
-        <span class="n">EventTarget</span> <span class="n">t</span> <span class="o">=</span> <span class="p">(</span><span class="n">EventTarget</span><span class="p">)</span><span class="n">elt</span><span class="p">;</span>
-
-        <span class="sr">//</span> <span class="n">Adds</span> <span class="n">a</span> <span class="s">&#39;onload&#39;</span> <span class="n">listener</span>
-        <span class="n">t</span><span class="o">.</span><span class="n">addEventListener</span><span class="p">(</span><span class="s">&quot;SVGLoad&quot;</span><span class="p">,</span> <span class="k">new</span> <span class="n">OnLoadAction</span><span class="p">(),</span> <span class="n">false</span><span class="p">);</span>
-
-        <span class="sr">//</span> <span class="n">Adds</span> <span class="n">a</span> <span class="s">&#39;onclick&#39;</span> <span class="n">listener</span>
-        <span class="n">t</span><span class="o">.</span><span class="n">addEventListener</span><span class="p">(</span><span class="s">&quot;click&quot;</span><span class="p">,</span> <span class="k">new</span> <span class="n">OnClickAction</span><span class="p">(),</span> <span class="n">false</span><span class="p">);</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">class</span> <span class="n">OnLoadAction</span> <span class="n">implements</span> <span class="n">EventListener</span> <span class="p">{</span>
-        <span class="n">public</span> <span class="n">void</span> <span class="n">handleEvent</span><span class="p">(</span><span class="n">Event</span> <span class="n">evt</span><span class="p">)</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Perform</span> <span class="n">some</span> <span class="n">actions</span> <span class="n">here</span><span class="o">...</span>
-
-            <span class="sr">//</span> <span class="o">...</span><span class="k">for</span> <span class="n">example</span> <span class="n">start</span> <span class="n">an</span> <span class="n">animation</span> <span class="n">loop:</span>
-            <span class="n">window</span><span class="o">.</span><span class="n">setInterval</span><span class="p">(</span><span class="k">new</span> <span class="n">Animation</span><span class="p">(),</span> <span class="mi">50</span><span class="p">);</span>
-        <span class="p">}</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">class</span> <span class="n">OnClickAction</span> <span class="n">implements</span> <span class="n">EventListener</span> <span class="p">{</span>
-        <span class="n">public</span> <span class="n">void</span> <span class="n">handleEvent</span><span class="p">(</span><span class="n">Event</span> <span class="n">evt</span><span class="p">)</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Perform</span> <span class="n">some</span> <span class="n">actions</span> <span class="n">here</span><span class="o">...</span>
-
-            <span class="sr">//</span> <span class="o">...</span><span class="k">for</span> <span class="n">example</span> <span class="n">schedule</span> <span class="n">an</span> <span class="n">action</span> <span class="k">for</span> <span class="n">later:</span>
-            <span class="n">window</span><span class="o">.</span><span class="n">setTimeout</span><span class="p">(</span><span class="k">new</span> <span class="n">DelayedTask</span><span class="p">(),</span> <span class="mi">500</span><span class="p">);</span>
-        <span class="p">}</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">class</span> <span class="n">Animation</span> <span class="n">implements</span> <span class="n">Runnable</span> <span class="p">{</span>
-        <span class="n">public</span> <span class="n">void</span> <span class="n">run</span><span class="p">()</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Insert</span> <span class="n">animation</span> <span class="n">code</span> <span class="n">here</span><span class="o">...</span>
-        <span class="p">}</span>
-    <span class="p">}</span>
-
-    <span class="n">public</span> <span class="n">class</span> <span class="n">DelayedTask</span> <span class="n">implements</span> <span class="n">Runnable</span> <span class="p">{</span>
-        <span class="n">public</span> <span class="n">void</span> <span class="n">run</span><span class="p">()</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Perform</span> <span class="n">some</span> <span class="n">actions</span> <span class="n">here</span><span class="o">...</span>
-
-            <span class="sr">//</span> <span class="o">...</span><span class="k">for</span> <span class="n">example</span> <span class="n">displays</span> <span class="n">an</span> <span class="n">alert</span> <span class="n">dialog:</span>
-            <span class="n">window</span><span class="o">.</span><span class="n">alert</span><span class="p">(</span><span class="s">&quot;Delayed Action invoked!&quot;</span><span class="p">);</span>
-        <span class="p">}</span>
-    <span class="p">}</span>
-<span class="p">}</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.svg.SVGLoadEventDispatcherAdapter</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.swing.svg.SVGLoadEventDispatcherEvent</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.apache.batik.script.Window</span><span class="o">;</span>
+
+<span class="kn">import</span> <span class="nn">org.w3c.dom.Document</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.w3c.dom.Element</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.w3c.dom.events.Event</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.w3c.dom.events.EventListener</span><span class="o">;</span>
+<span class="kn">import</span> <span class="nn">org.w3c.dom.events.EventTarget</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="k">new</span> <span class="nf">SVGApplication</span><span class="o">();</span>
+    <span class="o">}</span>
+
+    <span class="n">JFrame</span> <span class="n">frame</span><span class="o">;</span>
+    <span class="n">JSVGCanvas</span> <span class="n">canvas</span><span class="o">;</span>
+    <span class="n">Document</span> <span class="n">document</span><span class="o">;</span>
+    <span class="n">Window</span> <span class="n">window</span><span class="o">;</span>
+
+    <span class="kd">public</span> <span class="nf">SVGApplication</span><span class="o">()</span> <span class="o">{</span>
+        <span class="n">frame</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JFrame</span><span class="o">();</span>
+        <span class="n">canvas</span> <span class="o">=</span> <span class="k">new</span> <span class="n">JSVGCanvas</span><span class="o">();</span>
+        <span class="c1">// Forces the canvas to always be dynamic even if the current</span>
+        <span class="c1">// document does not contain scripting or animation.</span>
+        <span class="n">canvas</span><span class="o">.</span><span class="na">setDocumentState</span><span class="o">(</span><span class="n">JSVGCanvas</span><span class="o">.</span><span class="na">ALWAYS_DYNAMIC</span><span class="o">);</span>
+        <span class="n">canvas</span><span class="o">.</span><span class="na">addSVGLoadEventDispatcherListener</span>
+            <span class="o">(</span><span class="k">new</span> <span class="n">SVGLoadEventDispatcherAdapter</span><span class="o">()</span> <span class="o">{</span>
+                    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">svgLoadEventDispatchStarted</span>
+                        <span class="o">(</span><span class="n">SVGLoadEventDispatcherEvent</span> <span class="n">e</span><span class="o">)</span> <span class="o">{</span>
+                        <span class="c1">// At this time the document is available...</span>
+                        <span class="n">document</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="na">getSVGDocument</span><span class="o">();</span>
+                        <span class="c1">// ...and the window object too.</span>
+                        <span class="n">window</span> <span class="o">=</span> <span class="n">canvas</span><span class="o">.</span><span class="na">getUpdateManager</span><span class="o">().</span>
+                            <span class="n">getScriptingEnvironment</span><span class="o">().</span><span class="na">createWindow</span><span class="o">();</span>
+                        <span class="c1">// Registers the listeners on the document</span>
+                        <span class="c1">// just before the SVGLoad event is</span>
+                        <span class="c1">// dispatched.</span>
+                        <span class="n">registerListeners</span><span class="o">();</span>
+                        <span class="c1">// It is time to pack the frame.</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">frame</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">windowOpened</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="c1">// The canvas is ready to load the base document</span>
+                    <span class="c1">// now, from the AWT thread.</span>
+                    <span class="n">canvas</span><span class="o">.</span><span class="na">setURI</span><span class="o">(</span><span class="s">&quot;doc.svg&quot;</span><span class="o">);</span>
+                <span class="o">}</span>
+            <span class="o">});</span>
+
+        <span class="n">frame</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">canvas</span><span class="o">);</span>
+        <span class="n">frame</span><span class="o">.</span><span class="na">setSize</span><span class="o">(</span><span class="mi">800</span><span class="o">,</span> <span class="mi">600</span><span class="o">);</span>
+        <span class="n">frame</span><span class="o">.</span><span class="na">show</span><span class="o">();</span>
+    <span class="o">}</span>
+
+    <span class="kd">public</span> <span class="kt">void</span> <span class="nf">registerListeners</span><span class="o">()</span> <span class="o">{</span>
+        <span class="c1">// Gets an element from the loaded document.</span>
+        <span class="n">Element</span> <span class="n">elt</span> <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="na">getElementById</span><span class="o">(</span><span class="s">&quot;elt-id&quot;</span><span class="o">);</span>
+        <span class="n">EventTarget</span> <span class="n">t</span> <span class="o">=</span> <span class="o">(</span><span class="n">EventTarget</span><span class="o">)</span><span class="n">elt</span><span class="o">;</span>
+
+        <span class="c1">// Adds a &#39;onload&#39; listener</span>
+        <span class="n">t</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s">&quot;SVGLoad&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">OnLoadAction</span><span class="o">(),</span> <span class="kc">false</span><span class="o">);</span>
+
+        <span class="c1">// Adds a &#39;onclick&#39; listener</span>
+        <span class="n">t</span><span class="o">.</span><span class="na">addEventListener</span><span class="o">(</span><span class="s">&quot;click&quot;</span><span class="o">,</span> <span class="k">new</span> <span class="n">OnClickAction</span><span class="o">(),</span> <span class="kc">false</span><span class="o">);</span>
+    <span class="o">}</span>
+
+    <span class="kd">public</span> <span class="kd">class</span> <span class="nc">OnLoadAction</span> <span class="kd">implements</span> <span class="n">EventListener</span> <span class="o">{</span>
+        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">handleEvent</span><span class="o">(</span><span class="n">Event</span> <span class="n">evt</span><span class="o">)</span> <span class="o">{</span>
+            <span class="c1">// Perform some actions here...</span>
+
+            <span class="c1">// ...for example start an animation loop:</span>
+            <span class="n">window</span><span class="o">.</span><span class="na">setInterval</span><span class="o">(</span><span class="k">new</span> <span class="n">Animation</span><span class="o">(),</span> <span class="mi">50</span><span class="o">);</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+
+    <span class="kd">public</span> <span class="kd">class</span> <span class="nc">OnClickAction</span> <span class="kd">implements</span> <span class="n">EventListener</span> <span class="o">{</span>
+        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">handleEvent</span><span class="o">(</span><span class="n">Event</span> <span class="n">evt</span><span class="o">)</span> <span class="o">{</span>
+            <span class="c1">// Perform some actions here...</span>
+
+            <span class="c1">// ...for example schedule an action for later:</span>
+            <span class="n">window</span><span class="o">.</span><span class="na">setTimeout</span><span class="o">(</span><span class="k">new</span> <span class="n">DelayedTask</span><span class="o">(),</span> <span class="mi">500</span><span class="o">);</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+
+    <span class="kd">public</span> <span class="kd">class</span> <span class="nc">Animation</span> <span class="kd">implements</span> <span class="n">Runnable</span> <span class="o">{</span>
+        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">run</span><span class="o">()</span> <span class="o">{</span>
+            <span class="c1">// Insert animation code here...</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+
+    <span class="kd">public</span> <span class="kd">class</span> <span class="nc">DelayedTask</span> <span class="kd">implements</span> <span class="n">Runnable</span> <span class="o">{</span>
+        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">run</span><span class="o">()</span> <span class="o">{</span>
+            <span class="c1">// Perform some actions here...</span>
+
+            <span class="c1">// ...for example displays an alert dialog:</span>
+            <span class="n">window</span><span class="o">.</span><span class="na">alert</span><span class="o">(</span><span class="s">&quot;Delayed Action invoked!&quot;</span><span class="o">);</span>
+        <span class="o">}</span>
+    <span class="o">}</span>
+<span class="o">}</span>
 </pre></div>
 
 
 <h2 id="writing-thread-safe-code-wzxhzdk8wzxhzdk9">Writing thread-safe code <a id="Threads"></a></h2>
 <p>The DOM listeners registered on the SVG document are called from the canvas update thread. To avoid race conditions, do not manipulate the DOM tree from another thread.</p>
 <p>The way to switch from an external thread to the canvas update thread is to use the following code:</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Returns</span> <span class="n">immediately</span>
-<span class="n">canvas</span><span class="o">.</span><span class="n">getUpdateManager</span><span class="p">()</span><span class="o">.</span><span class="n">getUpdateRunnableQueue</span><span class="p">()</span><span class="o">.</span>
-    <span class="n">invokeLater</span><span class="p">(</span><span class="k">new</span> <span class="n">Runnable</span><span class="p">()</span> <span class="p">{</span>
-        <span class="n">public</span> <span class="n">void</span> <span class="n">run</span><span class="p">()</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Insert</span> <span class="n">some</span> <span class="n">actions</span> <span class="n">on</span> <span class="n">the</span> <span class="n">DOM</span> <span class="n">here</span>
-        <span class="p">}</span>
-    <span class="p">});</span>
-<span class="ow">or</span><span class="p">:</span>
-<span class="sr">//</span> <span class="n">Waits</span> <span class="k">until</span> <span class="n">the</span> <span class="n">Runnable</span> <span class="n">is</span> <span class="n">invoked</span>
-<span class="n">canvas</span><span class="o">.</span><span class="n">getUpdateManager</span><span class="p">()</span><span class="o">.</span><span class="n">getUpdateRunnableQueue</span><span class="p">()</span><span class="o">.</span>
-    <span class="n">invokeAndWait</span><span class="p">(</span><span class="k">new</span> <span class="n">Runnable</span><span class="p">()</span> <span class="p">{</span>
-        <span class="n">public</span> <span class="n">void</span> <span class="n">run</span><span class="p">()</span> <span class="p">{</span>
-            <span class="sr">//</span> <span class="n">Insert</span> <span class="n">some</span> <span class="n">actions</span> <span class="n">on</span> <span class="n">the</span> <span class="n">DOM</span> <span class="n">here</span>
-        <span class="p">}</span>
-    <span class="p">});</span>
+<div class="codehilite"><pre><span class="c1">// Returns immediately</span>
+<span class="n">canvas</span><span class="o">.</span><span class="na">getUpdateManager</span><span class="o">().</span><span class="na">getUpdateRunnableQueue</span><span class="o">().</span>
+    <span class="n">invokeLater</span><span class="o">(</span><span class="k">new</span> <span class="n">Runnable</span><span class="o">()</span> <span class="o">{</span>
+        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">run</span><span class="o">()</span> <span class="o">{</span>
+            <span class="c1">// Insert some actions on the DOM here</span>
+        <span class="o">}</span>
+    <span class="o">});</span>
+<span class="nl">or:</span>
+<span class="c1">// Waits until the Runnable is invoked</span>
+<span class="n">canvas</span><span class="o">.</span><span class="na">getUpdateManager</span><span class="o">().</span><span class="na">getUpdateRunnableQueue</span><span class="o">().</span>
+    <span class="n">invokeAndWait</span><span class="o">(</span><span class="k">new</span> <span class="n">Runnable</span><span class="o">()</span> <span class="o">{</span>
+        <span class="kd">public</span> <span class="kt">void</span> <span class="nf">run</span><span class="o">()</span> <span class="o">{</span>
+            <span class="c1">// Insert some actions on the DOM here</span>
+        <span class="o">}</span>
+    <span class="o">});</span>
 </pre></div>
 
 
@@ -308,33 +308,33 @@ You don’t have to worry about graph
 It is very dangerous to call <code>invokeAndWait</code> from the Swing event thread. This is the only thread that can be used to interact with Swing components. In some cases DOM calls may need to query the canvas for information (such as actual Swing component size, etc). If this happens you will get a thread deadlock. You should only make invokeAndWait calls from “third party” threads.</p>
 <h1 id="using-the-svg-dom-wzxhzdk10wzxhzdk11">Using the SVG DOM <a id="SVGDOM"></a></h1>
 <p>Batik provides a fairly complete implementation of the SVG DOM. The SVG DOM provides all the functionality most applications require. In particular, the DOM implements DOM Events, including mutation and UI Events. As an example, DOM events allow you to get notified when the cursor moves over elements of interest:</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Element</span> <span class="n">of</span> <span class="n">Interest</span><span class="o">.</span>
-<span class="n">Element</span> <span class="n">theElem</span> <span class="o">=</span> <span class="o">...</span><span class="p">;</span>
-<span class="p">((</span><span class="n">EventTarget</span><span class="p">)</span> <span class="n">theElem</span><span class="p">)</span><span class="o">.</span><span class="n">addEventListener</span><span class="p">(</span><span class="s">&quot;mouseover&quot;</span><span class="p">,</span> <span class="n">mouseOverListener</span><span class="p">,</span> <span class="n">true</span><span class="p">);</span>
+<div class="codehilite"><pre><span class="c1">// Element of Interest.</span>
+<span class="n">Element</span> <span class="n">theElem</span> <span class="o">=</span> <span class="o">...;</span>
+<span class="o">((</span><span class="n">EventTarget</span><span class="o">)</span> <span class="n">theElem</span><span class="o">).</span><span class="na">addEventListener</span><span class="o">(</span><span class="s">&quot;mouseover&quot;</span><span class="o">,</span> <span class="n">mouseOverListener</span><span class="o">,</span> <span class="kc">true</span><span class="o">);</span>
 </pre></div>
 
 
 <p>where <code>mouseOverListener</code> implements the <a href="http://java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/events/EventListener.html">org.w3c.dom.events.EventListener</a> interface. This interface consists of the method:</p>
-<div class="codehilite"><pre><span class="n">void</span> <span class="n">handleEvent</span><span class="p">(</span><span class="n">Event</span> <span class="n">evt</span><span class="p">);</span>
+<div class="codehilite"><pre><span class="kt">void</span> <span class="nf">handleEvent</span><span class="o">(</span><span class="n">Event</span> <span class="n">evt</span><span class="o">);</span>
 </pre></div>
 
 
 <p>This is called whenever the event occurs with the element it is registered on. It is worth reviewing the DOM Events specification as there are many useful features to this interface that are not immediately obvious.</p>
 <p>It is also worth looking at the DOM interfaces defined by the SVG specification as they provide a large number of useful methods, in particular those of <a href="../../javadoc/org/w3c/dom/svg/SVGLocatable.html">SVGLocatable</a> :</p>
-<div class="codehilite"><pre><span class="sr">//</span> <span class="n">Returns</span> <span class="n">Bounding</span> <span class="n">box</span> <span class="n">of</span> <span class="n">SVG</span> <span class="n">Element</span><span class="o">.</span>
-<span class="n">public</span> <span class="n">SVGRect</span>   <span class="n">getBBox</span> <span class="p">(</span>  <span class="p">);</span>
-<span class="sr">//</span> <span class="n">Returns</span> <span class="n">the</span> <span class="n">transformation</span> <span class="n">matrix</span> <span class="n">to</span> <span class="n">the</span> <span class="n">screen</span><span class="o">.</span>
-<span class="n">public</span> <span class="n">SVGMatrix</span> <span class="n">getScreenCTM</span> <span class="p">(</span>  <span class="p">);</span>
-<span class="sr">//</span> <span class="n">Returns</span> <span class="n">the</span> <span class="n">transformation</span> <span class="n">matrix</span> <span class="n">to</span> <span class="n">the</span> <span class="n">given</span> <span class="n">element</span><span class="o">.</span>
-<span class="n">public</span> <span class="n">SVGMatrix</span> <span class="n">getTransformToElement</span> <span class="p">(</span> <span class="n">SVGElement</span> <span class="n">element</span> <span class="p">)</span>
-                <span class="n">throws</span> <span class="n">SVGException</span><span class="p">;</span>
-<span class="n">In</span> <span class="n">particular</span><span class="p">,</span> <span class="sb">`getScreenCTM`</span> <span class="n">is</span> <span class="n">very</span> <span class="n">useful</span> <span class="k">for</span> <span class="n">taking</span> <span class="n">the</span> <span class="sb">`clientX`</span> <span class="ow">and</span> <span class="sb">`clientY`</span> <span class="n">attributes</span> <span class="n">of</span> <span class="n">the</span> <span class="n">DOM</span> <span class="p">[</span><span class="n">UIEvent</span><span class="p">](</span><span class="n">http:</span><span class="sr">//</span><span class="n">java</span><span class="o">.</span><span class="n">sun</span><span class="o">.</span><span class="n">com</span><span class="sr">/j2se/</span><span class="mf">1.5.0</span><span class="sr">/docs/</span><span class="n">api</span><span class="sr">/org/</span><span class="n">w3c</span><span class="sr">/dom/</span><span class="n">events</span>
 <span class="o">/</span><span class="n">UIEvent</span><span class="o">.</span><span class="n">html</span><span class="p">)</span> <span class="ow">and</span> <span class="n">mapping</span> <span class="n">them</span> <span class="n">to</span> <span class="n">the</span> <span class="n">coordinate</span> <span class="nb">system</span> <span class="n">of</span> <span class="n">an</span> <span class="n">element</span> <span class="n">in</span> <span class="n">the</span> <span class="n">SVG</span> <span class="n">document:</span>
-<span class="n">SVGMatrix</span> <span class="n">mat</span>  <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="n">getScreenCTM</span><span class="p">();</span>
-<span class="n">SVGMatrix</span> <span class="n">imat</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="n">inverse</span><span class="p">();</span>
-<span class="n">SVGPoint</span>  <span class="n">cPt</span>  <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="n">getRootElement</span><span class="p">()</span><span class="o">.</span><span class="n">createSVGPoint</span><span class="p">();</span>
-<span class="n">cPt</span><span class="o">.</span><span class="n">setX</span><span class="p">(</span><span class="n">uiEvt</span><span class="o">.</span><span class="n">getClientX</span><span class="p">());</span>
-<span class="n">cPt</span><span class="o">.</span><span class="n">setY</span><span class="p">(</span><span class="n">uiEvt</span><span class="o">.</span><span class="n">getClientY</span><span class="p">());</span>
-<span class="n">cPt</span> <span class="o">=</span> <span class="n">cPt</span><span class="o">.</span><span class="n">matrixTransform</span><span class="p">(</span><span class="n">imat</span><span class="p">);</span>
+<div class="codehilite"><pre><span class="c1">// Returns Bounding box of SVG Element.</span>
+<span class="kd">public</span> <span class="n">SVGRect</span>   <span class="nf">getBBox</span> <span class="o">(</span>  <span class="o">);</span>
+<span class="c1">// Returns the transformation matrix to the screen.</span>
+<span class="kd">public</span> <span class="n">SVGMatrix</span> <span class="nf">getScreenCTM</span> <span class="o">(</span>  <span class="o">);</span>
+<span class="c1">// Returns the transformation matrix to the given element.</span>
+<span class="kd">public</span> <span class="n">SVGMatrix</span> <span class="nf">getTransformToElement</span> <span class="o">(</span> <span class="n">SVGElement</span> <span class="n">element</span> <span class="o">)</span>
+                <span class="kd">throws</span> <span class="n">SVGException</span><span class="o">;</span>
+<span class="n">In</span> <span class="n">particular</span><span class="o">,</span> <span class="err">`</span><span class="n">getScreenCTM</span><span class="err">`</span> <span class="n">is</span> <span class="n">very</span> <span class="n">useful</span> <span class="k">for</span> <span class="n">taking</span> <span class="n">the</span> <span class="err">`</span><span class="n">clientX</span><span class="err">`</span> <span class="n">and</span> <span class="err">`</span><span class="n">clientY</span><span class="err">`</span> <span class="n">attributes</span> <span class="n">of</span> <span class="n">the</span> <span class="n">DOM</span> <span class="o">[</span><span class="n">UIEvent</span><span class="o">](</span><span class="nl">http:</span><span class="c1">//java.sun.com/j2se/1.5.0/docs/api/org/w3c/dom/events/UIEvent.html) and mapping them to the coordinate system of an element in the SVG document:</span>
+<span class="n">SVGMatrix</span> <span class="n">mat</span>  <span class="o">=</span> <span class="n">elem</span><span class="o">.</span><span class="na">getScreenCTM</span><span class="o">();</span>
+<span class="n">SVGMatrix</span> <span class="n">imat</span> <span class="o">=</span> <span class="n">mat</span><span class="o">.</span><span class="na">inverse</span><span class="o">();</span>
+<span class="n">SVGPoint</span>  <span class="n">cPt</span>  <span class="o">=</span> <span class="n">document</span><span class="o">.</span><span class="na">getRootElement</span><span class="o">().</span><span class="na">createSVGPoint</span><span class="o">();</span>
+<span class="n">cPt</span><span class="o">.</span><span class="na">setX</span><span class="o">(</span><span class="n">uiEvt</span><span class="o">.</span><span class="na">getClientX</span><span class="o">());</span>
+<span class="n">cPt</span><span class="o">.</span><span class="na">setY</span><span class="o">(</span><span class="n">uiEvt</span><span class="o">.</span><span class="na">getClientY</span><span class="o">());</span>
+<span class="n">cPt</span> <span class="o">=</span> <span class="n">cPt</span><span class="o">.</span><span class="na">matrixTransform</span><span class="o">(</span><span class="n">imat</span><span class="o">);</span>
 </pre></div>
 
 



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


Mime
View raw message