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 Overlay, Interactor and SVGGraphics2D
Date Fri, 12 Aug 2005 09:58:21 GMT
Hi,

 

I'm still trying to implement a SVG drawing editor. Here's what I'm
doing right now:

 

1)       I use Interceptors to get the mouse events

 

public void mousePressed(MouseEvent event) {

      Point2D.Float point = new Point2D.Float(

          event.getPoint().x,event.getPoint().y);

      Point2D.Float p = convertPointToViewBox(event.getPoint());

      

 

      if (SwingUtilities.isLeftMouseButton(event)) {

        if (currentShape == null) {

          currentShape = ShapeFactory.createShape(ShapeFactory.POLYGON);

          currentShape.moveTo(point);

        }

        currentShape.addNewCorner(point);

        drawingOverlay.drawShape(currentShape);

      } else if (SwingUtilities.isRightMouseButton(event)) {

        currentShape.closeShape();

                  // here after the right mouse button click, the shape
gets added to the underlying canvas by using SVGGenerator

        addNodes(new ShapeNodePlugin(currentShape));

        finished = true;

        setEnableNewShapeInteractor(false);

      }

    }

 

2)       In the Interceptor method I draw the shape object  through an
overlay

      drawingOverlay.drawShape(currentShape);

 

3)       When the user clicks the right mouse button, the drawn shape
should get put into the SVGDocument tree

 

 

4)       I initially wanted to do that by using the SVGGenerator like
this

 

   SVGGraphics2D svgGenerator = new
SVGGraphics2D(canvas.getSVGDocument());

    svgGenerator.setSVGCanvasSize(canvas.getSize());

    svgGenerator.draw(shape.getShape());

    Node root = svgGenerator.getRoot().getLastChild();

 

 

5)       And I'm sure it would work, but I noticed that my Overlay draw
routine needs the user coordinates to draw the shape correctly, whereas
the SVGGenerator 

in order to get the node into the SVGDocument needs the viewport
coordinates of my underlying my image.

 

 

What am I doing wrong? Do I have to write my own shape(Graphics) ->
shape(SVG) Generator, by converting every single coordinate of the shape
the user has drawn?

 

I feel like I'm trying to reinvent the wheel, so any hints would be
great.... :-)

 

Dominik Steiner


Mime
View raw message