We are trying to implement a whiteboard-like scribble tool using JSVGComponent. In order to get mouse events we extend JSVGComponent and implement MouseListener & MouseMotionListener. Then the trick is to convert the AWT coordinates into viewbox coords, so that the SVG doc can be appropriately modified. (We are saving the drawing events directly to the SVG for later playback.) Here is how we are doing the coordinate translation:
/** * get an AffineTransform which will convert AWT screen coords to * viewbox coords for the current document. */ private void getInverseAFT() { try { AffineTransform aft = getViewBoxTransform(); inverseAFT = aft.createInverse(); } catch(NoninvertibleTransformException err) { err.printStackTrace(System.err); // FIXME: better error handling } }
/** * Convert an AWT screen coordinate to a SVG viewbox coord for the * current document. */ private Point2D screenToViewBox(java.awt.event.MouseEvent e) { if (inverseAFT == null) { getInverseAFT(); }
Point2D p = new Point2D.Float(e.getX(), e.getY()); return inverseAFT.transform(p, p); }
The problem: if the JSVGComponent has not been resized, getViewBoxTransform() seems to return an AffineTransform that does not do the proper scaling- the AWT coords end up rendering in the upper-left hand corner of the SVG doc. If I resize the component by dragging the resize bar on the frame (or force a resize using setSize()) it works fine.
Can anyone comment on this? We are using the latest batik 1.5 from CVS.
Thanks for your help.
--------------------------------------------------------------------- To unsubscribe, e-mail: [EMAIL PROTECTED] For additional commands, e-mail: [EMAIL PROTECTED]