Philippe GIL wrote:
Bonjour Paul,

Thanks for your code. You are using SWT_AWT class. Does it still
experimental and only for win32?

That's working code when the JSVGCanvas is added to a JPanel;

addEventListener is called for each svg element you need to get inputs
getCurrentTarget returns the "clicked" Element.

Actually getCurrentTarget is the element the event listener is registered on. getTarget() is the element that the user clicked on. To understand why there are both you need to understand DOM event dispatching - all events travel from the root of the document to the element receiving the event (the element 'clicked on'), this phase is called event capture. As the event propagates it calls any event listeners that are registered with 'true' as the third parameter. Then all listeners on the element receiving the event are called. Then the event 'bubbles' back to the root of the document tree, calling any listeners that are registered with 'false' as the third parameter (this is also when onXXX event attributes are dispatched).

This way you can register one event listener on the root of the SVG tree and
receive essentially all events in the DOM tree, (you can also do this for
a subgroup and just get events from that subtree) and you can tell what element
was clicked by checking the getTarget() function.

EventListener onClick = new OnClickAction();

EventTarget t;
t = (EventTarget)(svgCanvas.getSVGDocument().
getElementById(svgid));
// Adds a 'onclick' listener
t.addEventListener("click", onClick, false);

This registers 'onClick' to recieve events during the 'bubbling' phase.




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]



Reply via email to