xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Gary Frederick <gary.freder...@jsoft.com>
Subject Example code for Batik
Date Fri, 13 Feb 2004 14:29:16 GMT

I'm finally starting to work with Batik and Java. I got a version from 
CVS, built it and ran the tests. I copied an example and built and ran 
that. Now I am ready to take over the world
   or at least my part ;-)

I have some SVG that uses JavaScript to move shapes around. I want to do 
the same with Java. My Java is rusty. I would like a complete example or 
two that included events like mousedown. Any pointers?



Here is a JavaScript version of a program that adds shapes when you 
click the mouse.

<?xml version="1.0"?>
<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
<svg width="800" height="400" onload="init(evt)"
   <title>test adding blocks with mouse</title>
   <desc>copy the shape where the mouse is clicked
         mousedown - get location, add shape</desc>
   <script type="text/ecmascript">
       var svgns = "http://www.w3.org/2000/svg";
       var SVGDoc;
       var mousetrap; // used to trap some mouse events
       var firstShape;

       function init(evt) {
         // Get the Document
         SVGDoc = evt.getTarget().getOwnerDocument();
         firstShape = SVGDoc.getElementById("firstShape");
         mousetrap = SVGDoc.getElementById("trap");
         mousetrap.addEventListener("mousedown", mousedown, false);

       function mousedown(evt){
         var x =  parseInt(evt.clientX);
         var y = parseInt(evt.clientY);
         var aRect = SVGDoc.createElementNS(svgns, "rect");
         aRect.setAttributeNS(null, "width", "42");
         aRect.setAttributeNS(null, "height", "24");
         aRect.setAttributeNS(null, "x", x);
         aRect.setAttributeNS(null, "y", y);
         aRect.setAttributeNS(null, "fill", "lightgreen");
   <rect id="trap" x="0" y="0" width="100%" height="100%"
         fill-opacity="0.2" fill="lightblue"/>
   <g id="firstShape" transform="translate(100 100)">
     <title>first rect</title>
     <rect x="0" y="0" rx="5" width="60" height="28" fill="lightgreen"/>
     <text x="4" y="14">first rect</text>

To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
For additional commands, e-mail: batik-users-help@xml.apache.org

View raw message