Hello,
you
could try this ...
Element elem = ((Element)evt.getTarget());
Greetings, Christian.
-----Urspr�ngliche Nachricht-----
Von: Michael H�ndel [mailto:[EMAIL PROTECTED]]
Gesendet: Donnerstag, 19. Dezember 2002 20:20
An: Batik
Betreff: resolve ID of 'click'-event?Hello,
I used the attached code to catch click-events on an DOM-Node. It works fine, but does anybody got an idea how to resolve the ID of the clicked element? I need this, because I want to dynamically add and remove nodes in a hierarchy of <g>-Elements. Every element has an unique id which will be created in the moment the element is added. To add sub-elements to the element I need to resolve the ID of the clicked object, to figure out, to which element I should append the new element... All this works fine in JavaScript, with the evt.getTarget().getOwnerDocument() function... but with Batik??
So far, I've got a code that creates an EventTarget object, but I've got no clue how to resolve the ID of this EventTarget, cause I just kno to resolve ID's with the getAttribute('id') method, but this method just applies to Nodes, not to EventTargets??I my explications haven't been to complicated...
Thanks in advance for your help...
Michael Haendel.
> You could have a look at an example registering a listener
for 'click' event
> on a specific element within a java application:
> http://xml.apache.org/batik/javaScripting.html.
> From there, extending that example, if you attach a listener
for 'onclick'
> on the svg root, you should be able to catch all click events on all
> elements :
>
> SVGDocument doc; //I assume you have the document
>
> Element root = doc.getDocumentElement();
> EventTarget target = (EventTarget)root;
>
> // useCapture = true : to get all click events in the document
> target.addEventListener("click",new ClickListener(), true);
>
> class ClickListener implement EventListener{
> public void handleEvent(Event evt) {
>
> EventTarget clickedElement = evt.getTarget()
>
> //do something
> }
> }
>
> This example provides all the setup to write an event listener.
> Hope this help.
>
> Cheers,
> Nicolas
