On 09/08/13 13:58, Robert Marcano wrote:
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
Hi Robert, thanks for your reply. I've applied your suggestion but
haven't managed to add links to my document yet as far as I can tell.
The pointer doesn't change over the text (not sure if it that's the
default) and more importantly the event handler isn't triggered. Here's
what it looks like now:
for(int i=0;i<labels.getLength();i++) {
n = labels.item(i);
log.info("A label:"+n.getFirstChild().getNodeValue());//prints as
//expected
EventListener l = new EventListener() {
public void handleEvent(Event evt) {
log.info("Clicked on "+(
(Node) evt.getTarget()).getFirstChild().getNodeValue());
}
};
((EventTarget) n).addEventListener("click", l, false);
}
Quite happy to RTFM if someone can point me to a suitable FM. I'm aware
of http://xmlgraphics.apache.org/batik/using/, but it's low on examples.
Cheers,
Jim
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: batik-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org
___________________________________________________________
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/
___________________________________________________________
--
Dr Jim Burton
Senior Lecturer in Computing
School of Computing, Engineering and Mathematics
University of Brighton
___________________________________________________________
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: batik-users-unsubscr...@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org