I did that: mask.addEventListener("mousemove",
new org.w3c.dom.events.EventListener() { public void handleEvent(Event evt) { MouseEvent e = (MouseEvent) evt; if (e.getButton() == 0) { Point2D newMouseDownPoint; try { newMouseDownPoint = SVGUtil.convert2CanvasCoord(e.getClientX(), e.getClientY(), getCanvas()); String value = String.format(Locale.US, "translate(%f,%f) "+ transformAttInitialValue, newMouseDownPoint.getX()- mouseDownPoint.getX(), newMouseDownPoint.getY()- mouseDownPoint.getY()); //push to the running queue getCanvas().push(new AttributeUpdateTask(id, "transform", value)); } catch (NoninvertibleTransformException e1) { // TODO Auto-generated catch block e1.printStackTrace(); } } } }, false); with public static Point2D convert2CanvasCoord(int screenX, int screenY, AbstractJSVGComponent canvas) throws NoninvertibleTransformException { Point2D doc = new Point(screenX, screenY); AffineTransform tr = canvas.getViewBoxTransform(); Point2D pt; pt = tr.inverseTransform(doc, null); return pt; } If it seems OK, tell me and I add this to the wiki On Fri, Mar 5, 2010 at 11:53 AM, dao <dao.ho...@gmail.com> wrote: > actually, I am already sticked to this event. but now, I want the element > to follow the pointer when left button pressed: > > mask.addEventListener("mousemove", > new org.w3c.dom.events.EventListener() { > > > public void handleEvent(Event evt) { > MouseEvent mouseEvent = (MouseEvent) evt; > if (mouseEvent.getButton() == 1) { > //HELP ME > } > > but the HELP ME part is still confused to me. I found in the batik dist 1.7 > a sample named sydney.svg where some javascript tries to do the same (moving > images on click and drag events). In squiggle, the scale is not preserved, > but the image moves under the pointer. In the code, they use this: > // handle the current zoom and pan > var trans = document.documentElement.currentTranslate; > var scale = document.documentElement.currentScale; > > I could not find such method/member to get that. how can I do? > > rgds > > > > > > On Mon, Mar 1, 2010 at 1:56 PM, jonathan wood > <jonathanshaww...@gmail.com>wrote: > >> Considering your use case, you may want to try a slightly different >> approach. You can bypass the AWTEvent capture and use the DOM Event >> structure in SVG. >> >> Check out http://www.w3.org/TR/SVG/interact.html with special attention >> to pointer-events and event names. >> >> // create a listener: >> >> EventListener myListener = new EventListener() { >> public void handleEvent(Event evt) { >> String evtType = evt.getType(); >> if(evt.equals("mousemove")) { >> ... >> } >> } >> }; >> >> // attach the listener to the element: >> >> ((EventTarget) myEl).addEventListener("mousemove", myListener, false); >> >> >> Keep in mind that you can then use SVGLocatable.getTransformToElement() if >> you need to transform to another coord system within the document. >> >> >> >> >> >> On Mon, Mar 1, 2010 at 6:41 AM, HODAC, Olivier >> <olivier.ho...@airbus.com>wrote: >> >>> OK, I’ll give it a try >>> >>> >>> >>> I thought I missed something, but it is not straightforward at all! >>> >>> >>> >>> Do you think it will be costfull if ran on each mouse move? I want that >>> my user can click an element of the canvas and move it in a different >>> location. And I want the canvas updated during the mousemove so that he can >>> see the result in real time >>> >>> >>> >>> *De :* jonathan wood [mailto:jonathanshaww...@gmail.com] >>> *Envoyé :* lundi 1 mars 2010 04:03 >>> *À :* batik-users@xmlgraphics.apache.org >>> *Objet :* Re: coordinate conversion >>> >>> >>> >>> >>> Most of what you need can be found in SVGLocatable. The below is not >>> tested, but should be close: >>> >>> Point awtPoint = ...; >>> Element myEl = document.getElementById("my-el"); >>> SVGPoint svgPoint = document.getRootElement.createSVGPoint(); >>> svgPoint.setX(awtPoint.getX()); >>> svgPoint.setY(awtPoint.getY()); >>> SVGMatrix m = ((SVGLocatable)myEl).getScreenCTM(); >>> m = m.inverse(); >>> svgPoint = svgPoint.matrixTransform(m); >>> >>> >>> On Fri, Feb 26, 2010 at 8:34 AM, dao <dao.ho...@gmail.com> wrote: >>> >>> hello, >>> >>> Sorry for this stupid question: how do I transform coordinates from a AWT >>> mouse event to the coordinates in the svg file the canvas represents? >>> >>> I mean, I have a panel with the canvas (rotated, zoomed, panned in the >>> worst case) and I want to know the coordinates of the svg point my mouse >>> cursor is pointing. >>> >>> >>> >>> -- >>> Dao Hodac >>> >>> >>> >>> This mail has originated outside your organization, either from an external >>> partner or the Global Internet. >>> >>> Keep this in mind if you answer this message. >>> >>> >>> >>> The information in this e-mail is confidential. The contents may not be >>> disclosed or used by anyone other than the addressee. Access to this e-mail >>> by anyone else is unauthorised. >>> If you are not the intended recipient, please notify Airbus immediately and >>> delete this e-mail. >>> Airbus cannot accept any responsibility for the accuracy or completeness of >>> this e-mail as it has been sent over public networks. If you have any >>> concerns over the content of this message or its Accuracy or Integrity, >>> please contact Airbus immediately. >>> All outgoing e-mails from Airbus are checked using regularly updated virus >>> scanning software but you should take whatever measures you deem to be >>> appropriate to ensure that this message and any attachments are virus free. >>> >>> >> > > > -- > Dao Hodac > -- Dao Hodac