|
View:
New views
11 Messages
—
Rating Filter:
Alert me
|
|
|
locate an SVG element using x, y positionHello,
I’d like to add a mouse listener on my JSVGCanvas to select an element of my rendered SVG. How can I find the right node using x,y mouse postion?
Olivier Dao Ho Dac Flight Test Software Architect Airbus - EVIDA Phone : + 33 (0)5 67 19 81 34 Fax : +33(0)5 61 93 80 02
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. |
|
|
Re: locate an SVG element using x, y positionOn Mon, 26 Oct 2009 10:44:49 +0100, HODAC, Olivier wrote in
<1950_1256550419_4AE57013_1950_34_1_0471C9AC78F671458C5E3F9C69B73C8609879CB1@...>: >I'd like to add a mouse listener on my JSVGCanvas to select an element >of my rendered SVG. >How can I find the right node using x,y mouse postion? I have explored that, but the problem is that you have only the bounds of the element to locate your mouse point in. This is a rectangle. If now the element is, say, an ellipse or a line or another shape that is not rectangular, the function won't work with mouse points inside that rectangle, but outside the shape. You need to add an event listener to each element as you create it. If you load your drawing from a file, you need to loop through the whole element tree and add it to each element. It's not so much code, as you do it all in a loop. Here is the code that I am using, after I have retrieved my document string from a database and created the document. I have the special situation that I skip the first element, which is a background rectangle that I don't want to be moveable. It is always the first in the document. BackG = doc.getElementById("BackgroundRectangle"); EventTarget etr = null; Node no = (Node) BackG; Node no2 = no.getNextSibling(); if (no2!=null) { do { etr = (EventTarget) no2; etr.addEventListener("click",new org.w3c.dom.events.EventListener() { org.w3c.dom.events.Event evt; public void handleEvent(org.w3c.dom.events.Event evt) { EventTarget etr2 = evt.getTarget(); ActivateSelEl(etr2); // function that selects the element, // retrieves its bounds and sets a flag // that tells the canvas to paint a // selection rectangle with mouse // anchors on top of the SVG drawing // in its paint function repaint(); } public void run() { handleEvent(evt); } },false ); no2=no2.getNextSibling(); } while (no2!=null); } Best, Heidrun Beer Workgroup for Fundamental Spiritual Research and Mental Training http://www.sgmt.at http://www.RecastReality.org --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscribe@... For additional commands, e-mail: batik-users-help@... |
|
|
Re: locate an SVG element using x, y positionHi Heidrun, HODAC,
> On Mon, 26 Oct 2009 10:44:49 +0100, HODAC, Olivier wrote: > > >I'd like to add a mouse listener on my JSVGCanvas to select an element > >of my rendered SVG. > >How can I find the right node using x,y mouse postion? I suggest following Heidrun's suggestion of adding a mouse event listener (click, mouseOver, mouseExit, etc), although I would suggest doing it a different way. However another approach would be to use the 'getIntersectionList' method available on the svg:svg element. I suggest reading the DOM2 Events specification as it offers everything most people need in this area: http://www.w3.org/TR/DOM-Level-2-Events/ Heidrun Beer <hBeer@...> wrote on 10/26/2009 06:59:11 AM: > You need to add an event listener to each element as > you create it. If you load your drawing from a file, > you need to loop through the whole element tree and > add it to each element. It's not so much code, as > you do it all in a loop. Actually if you want to be notified of all mouse events I would suggest registering one listener on the root SVG element (probably during the capture phase). You can then use the target field to know what element the event is targeted for. > I have the special situation that I skip the first element, > which is a background rectangle that I don't want to be > moveable. It is always the first in the document. This can be handled with the one event listener by simply skipping events that have the background rectangle as the event target. The one listener approach will also save considerably on memory. |
|
|
|
|
|
RE: locate an SVG element using x, y positionHi HODAC,
"HODAC, Olivier" <OLIVIER.HODAC@...> wrote on 10/26/2009 10:31:25 AM: > Seems to be a good Idea, this getIntersectionList with a 1pixel > rect, isn’t it? Right, but I think I confused you a little. > I am looking at the Dom specification, but it seems that I have not > the right technic to sniff around W3C documentation (tell me how to search?). www.google.com ;) More seriously you can download most W3C Specs as PDF. > ONE > I try to get a viewportElement (assuming that it is the displayed > rect to pass as an argument to the function.: > SVGElement viewportElement = canvas.getSVGDocument > ().getRootElement().getViewportElement(); > > Unfortunately, it returns null. Do you know why ? what’s the > difference with the getViewport()? The root SVG element has now ViewportElement since it is the topmost ViewportElement. > TWO > I pass the root element to the function. It fails with nullpointerexception. Any more info on the NPE or how you called the function? > While waiting, I’ll try the Heidrun method. Actually Heidrun's method is my recommended solution but not by adding a listener to every element. Simply add one listener to the root of the SVG tree and check the 'target' field to know what element the hit was on (that is what I meant by 'doing it a different way'). > De : thomas.deweese@... [mailto:thomas.deweese@...] > Envoyé : lundi 26 octobre 2009 13:44 > À : batik-users@... > Cc : batik-users@... > Objet : Re: locate an SVG element using x, y position > > Hi Heidrun, HODAC, > > > On Mon, 26 Oct 2009 10:44:49 +0100, HODAC, Olivier wrote: > > > > >I'd like to add a mouse listener on my JSVGCanvas to select an element > > >of my rendered SVG. > > >How can I find the right node using x,y mouse postion? > > I suggest following Heidrun's suggestion of adding a mouse > event listener (click, mouseOver, mouseExit, etc), although I would > suggest doing it a different way. > > However another approach would be to use the 'getIntersectionList' > method available on the svg:svg element. > > I suggest reading the DOM2 Events specification as it offers > everything most people need in this area: > http://www.w3.org/TR/DOM-Level-2-Events/ > > Heidrun Beer <hBeer@...> wrote on 10/26/2009 06:59:11 AM: > > > You need to add an event listener to each element as > > you create it. If you load your drawing from a file, > > you need to loop through the whole element tree and > > add it to each element. It's not so much code, as > > you do it all in a loop. > > Actually if you want to be notified of all mouse events > I would suggest registering one listener on the root > SVG element (probably during the capture phase). You can > then use the target field to know what element the > event is targeted for. > > > I have the special situation that I skip the first element, > > which is a background rectangle that I don't want to be > > moveable. It is always the first in the document. > > This can be handled with the one event listener by simply > skipping events that have the background rectangle as the > event target. > > The one listener approach will also save considerably on > memory. > 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. |
|
|
|
|
|
RE: locate an SVG element using x, y positionHi HODAC,
"HODAC, Olivier" <OLIVIER.HODAC@...> wrote on 10/26/2009 11:34:17 AM: > Thanks, I have implemented you solution but the event never comes. I > am un eclipse behind a swing component wrapper. I don't know if the > EventTarget actually received the event. How can I check that? I don't know anything about Swing components embedded in SWT. Does that forward event's to the Swing component? The other common problem is that you didn't set the canvas to ALWAYS_DYNAMIC. > I have seen that you register an event listener on the event type > "click". It is hard coded. Is there a list of events as constants? > Is it possible I register all the events to see if it is Eclipse > that consumes the events forgetting to redispatch them? > > > > -----Message d'origine----- > De : Heidrun Beer [mailto:hBeer@...] > Envoyé : lundi 26 octobre 2009 11:59 > À : batik-users@... > Objet : Re: locate an SVG element using x, y position > > On Mon, 26 Oct 2009 10:44:49 +0100, HODAC, Olivier wrote in > <1950_1256550419_4AE57013_1950_34_1_0471C9AC78F671458C5E3F9C69B73C8609879CB1@fr0- > mailmb17.res.airbus.corp>: > > >I'd like to add a mouse listener on my JSVGCanvas to select an element > >of my rendered SVG. > >How can I find the right node using x,y mouse postion? > > > I have explored that, but the problem is that you have > only the bounds of the element to locate your mouse point > in. This is a rectangle. If now the element is, say, an > ellipse or a line or another shape that is not rectangular, > the function won't work with mouse points inside that > rectangle, but outside the shape. > > You need to add an event listener to each element as > you create it. If you load your drawing from a file, > you need to loop through the whole element tree and > add it to each element. It's not so much code, as > you do it all in a loop. > > Here is the code that I am using, after I have retrieved > my document string from a database and created the document. > > I have the special situation that I skip the first element, > which is a background rectangle that I don't want to be > moveable. It is always the first in the document. > > > BackG = doc.getElementById("BackgroundRectangle"); > EventTarget etr = null; > Node no = (Node) BackG; > Node no2 = no.getNextSibling(); > if (no2!=null) { > do { > etr = (EventTarget) no2; > etr.addEventListener("click",new > org.w3c.dom.events.EventListener() > { > org.w3c.dom.events.Event evt; > > public void handleEvent > (org.w3c.dom.events.Event evt) { > EventTarget etr2 = evt.getTarget(); > > ActivateSelEl(etr2); // function that > selects the element, > // retrieves its bounds and sets a flag > // that tells the canvas to paint a > // selection rectangle with mouse > // anchors on top of the SVG drawing > // in its paint function > repaint(); > } > public void run() { > handleEvent(evt); > } > > },false > ); > no2=no2.getNextSibling(); > } while (no2!=null); > } > > > > Best, > > > Heidrun Beer > > Workgroup for Fundamental Spiritual Research and Mental Training > http://www.sgmt.at > http://www.RecastReality.org > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: batik-users-unsubscribe@... > For additional commands, e-mail: batik-users-help@... > > > 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. > > > --------------------------------------------------------------------- > To unsubscribe, e-mail: batik-users-unsubscribe@... > For additional commands, e-mail: batik-users-help@... > |
|
|
Re: locate an SVG element using x, y positionOn Mon, 26 Oct 2009 16:34:17 +0100, HODAC, Olivier wrote in
<30419_1256571256_4AE5C178_30419_466_1_0471C9AC78F671458C5E3F9C69B73C8609879D9D@...>: >Thanks, I have implemented you solution but the event never comes. >I am un eclipse behind a swing component wrapper. I don't know >if the EventTarget actually received the event. How can I check >that? I have seen that you register an event listener on the event >type "click". It is hard coded. Is there a list of events as >constants? Is it possible I register all the events to see >if it is Eclipse that consumes the events forgetting to >redispatch them? Hi Olivier, difficult for me to say. I am a relative beginner in both Java and Batik. I was happy to have an answer to your question, but my IDE is not Eclipse, I am working in NetBeans, and am in no way firm in all the lower level compiler issues. I am happy that I got it to work in my environment, but more than that... sorry! I have yet to see how it works with only one event listener. The idea is very good, should save a lot of memory and speed up performance, maybe you want to try that? All the best, Heidrun Beer Workgroup for Fundamental Spiritual Research and Mental Training http://www.sgmt.at http://www.RecastReality.org --------------------------------------------------------------------- To unsubscribe, e-mail: batik-users-unsubscribe@... For additional commands, e-mail: batik-users-help@... |
|
|
|
|
|
RE: locate an SVG element using x, y positionHi Oliver,
"HODAC, Olivier" <OLIVIER.HODAC@...> wrote on 10/27/2009 12:51:13 PM: > I succeded in catching the event. Thanks, thomas, I had forgot the > ALWAYS_DYNAMIC state. > The solution of Heidrun is the solution I have implemented as it > seems that the evt.getTarget() seems not to point on the right node > (in the case I use refs to symbols, see SVG). Do you know why? The > getTarget() is not the right method to call? Well getTarget will point at the actual geometry element (like a rect, text, or in your case a polygon). In cases like this I normally walk up the tree until I get to the desired element (see 'getParent' on DOM Elements). I'll often add an attribute in a custom namespace rather than simply assume that the first symbol is the right element. > When I write the following piece of code, I point on the polygon > Node of the SVG which is the symbol element (=> no ID => > NullPointerException). I want to get the use element (top, bottom or > middle of the SVG) One thing to watch for is that the element it points at will be in a 'shadow tree' (a copy we make so we can properly perform the CSS cascade). So you need to do some fancy footwork to navigate across the symbol->use boundary (see batik.dom.svg.SVGOMUseShadowRoot.getCSSParentNode). |
|
|
|
| Free embeddable forum powered by Nabble | Forum Help |