xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From "Steiner, Dominik" <Dominik.Stei...@gigatronik.com>
Subject AW: Drawing on a JSVGCanvas with SVGGenerator??
Date Thu, 11 Aug 2005 12:46:02 GMT
Hi,

 

I solved my problem and for those who might run into similar isues:

 

1)       svgGenerator.fill(new
Rectangle2D.Double(mouseEvent.getX(),mouseEvent.getY(),50,50)); 

 

 -----> I had to convert the mouseEvent coordinates to the underlying
viewport by 

 

SVGMatrix screenCTM =
canvas.getSVGDocument().getRootElement().getScreenCTM();

    //    matrix now holds scale/rotation/translate/skew values for both
x and y

    coords[0] = screenCTM.getA() * mouseEvent.getX(),+ screenCTM.getC()
* mouseEvent.getY(),

        + screenCTM.getE();

    coords[1] = screenCTM.getB() * mouseEvent.getX(), + screenCTM.getD()
* mouseEvent.getY(),

        + screenCTM.getF();

 

2)
mapCanvas.getSVGDocument().getRootElement().appendChild(svgGenerator.get
Root());

 

--> I had to get the <g>-Node and not the whole <svg> root to append it
to the underlying canvas (which makes sense anyway) through:

 

mapCanvas.getSVGDocument().getRootElement().appendChild(svgGenerator.get
Root().getLastChild());

 

And then it worked.

 

Dominik Steiner

 

 

 

 

  _____  

Von: Steiner, Dominik 
Gesendet: Mittwoch, 10. August 2005 08:15
An: batik-users@xmlgraphics.apache.org
Betreff: Drawing on a JSVGCanvas with SVGGenerator??

 

Hi my dear Batik fellows,

 

I'm trying to implement a drawing feature into my application:

 

* where the user can draw shapes (e.g. polygons) by clicking and
dragging with the mouse.

* Underlying is a SVG graphic of a map. 

* this shapes should get stored, preferably as a separate SVG file

* all is handled inside a JSVGCanvas

 

Up to now I try to implement this using the SVGGenerator, but I'm not
sure if this is a good approach and I'm having trouble using it.

 

1) I have to instantiate the SVGGenerator with the SVGDocument of my
underlying map

svgGenerator = new SVGGraphics2D(mapSVGDocument);

 

            2) I set the Canvas size of the Generator to that of the map

            svgGenerator.setSVGCanvasSize(mapCanvas.getSize());

 

            3) then the user by clicking on the canvas can draw a
rectangle

            svgGenerator.fill(new
Rectangle2D.Double(mouseEvent.getX(),mouseEvent.getY(),50,50));

 

            4) to get the drawings displayed in my map, I have to use
the UpdateManager of the JSVGCanvas??

 
canvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable(){

 

      public void run() {

 
mapCanvas.getSVGDocument().getRootElement().appendChild(svgGenerator.get
Root());

      }                                                                 

    });

 

 

This doesn't work.

 

1) I also would like to add EventListener to the shapes the user is
drawing. I'm not sure where to add those listeners? Before I add them to
the mapCanvas on traversing the root I got from SVGGenerator?

 

I'm deeply grateful for the help you can give me.

 

Greetings from Germany.

 

Dominik Steiner


Mime
View raw message