Re: Adding links to a document
Robert Marcano <[email protected]> Fri, 09 Aug 2013 08:28:32 -0430
| Newsgroups | gmane.text.xml.batik.user |
|---|---|
| Message-ID | <[email protected]> |
On 08/08/2013 05:55 PM, James Burton wrote:
> I'm new to using batik, and I want to turn all text elements in an
> SVGDocument into links which pass the text to a callback. Can you point
> me to an example of something similar? I'm finding the text elements
> like this:
There is no need to modify the document
>
> SVGDocument doc = ...
> Element svgRoot = doc.getDocumentElement();
> NodeList labels = svgRoot.getElementsByTagNameNS("*", "text");
> Node n;
> for(int i=0;i<labels.getLength();i++) {
> n = labels.item(i);
> log.info("A label:"+n.getFirstChild().getNodeValue());
EventListener l = new EventListener {
public void handleEvent(Event evt) {
// you can try to use the current n element here, that
// means you need to make it final and build one listener
// for each element or use evt.getTarget() to get the
// element and use only one listener instance per document
}
}
n.addEventListener("click", l, false)
> //presumably, replace n with a link element that contains n?
> }
>
You can use too event bubbling on the addEventListener and attach only
one listener on the document root and check the element type you are
getting, instead of attaching a listener to each element, the advantage
of this method is that it work for all text elements you add later
without need to add a listener to them
> Thanks in advance,
>
> Jim
>
> ___________________________________________________________
> This email has been scanned by MessageLabs' Email Security
> System on behalf of the University of Brighton.
> For more information see http://www.brighton.ac.uk/is/spam/
> ___________________________________________________________
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [email protected]
> For additional commands, e-mail: [email protected]
>