Hi Thomas,
I did what you suggested but I must have made a mistake because it doesn't seem
to work.
My SVG has a the element
<use xlink:href="#SPIDER" myns:link="resources/images/test.svg" x="911"
y="1204" width="49.25" height="49.25"/>
and this is a snipped of my code:
...................
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
svgCanvas.addSVGLoadEventDispatcherListener(
new SVGLoadEventDispatcherAdapter() {
public void
svgLoadEventDispatchStarted(SVGLoadEventDispatcherEvent e) {
SVGDocument doc = svgCanvas.getSVGDocument();
registerSVGListeners(doc.getRootElement());
}
});
..................
private void registerSVGListeners(Node node){
NamedNodeMap attrs = node.getAttributes();
for(int i =0;i<attrs.getLength();i++){
Node att = attrs.item(i);
if ("myns".equals(att.getPrefix()) &&
"link".equals(att.getLocalName())){
final String id = att.getNodeValue();
EventListener onClick = new EventListener(){
public void handleEvent(Event evt) {
getMediator().openSVG(id);
}
};
EventTarget target = (EventTarget) node;
// Adds a 'onclick' listener
target.addEventListener("click", onClick, true);
}
}
NodeList children = node.getChildNodes();
for (int i=0;i<children.getLength();i++){
Node child = children.item(i);
if (child instanceof Element){
registerSVGListeners(child);
}
}
}
Debugging through the app, I can see that the listeners are set but nothing
happens when I click on the element.
I reckon that the events are not fired.
Any ideas?
Thanks
Alessandro
On Tuesday 09 November 2004 03:23, Thomas DeWeese wrote:
> Hi Alessandro,
>
> Well you basically can't do what you want to the way you
> want. We don't give access to the document at that level.
> However you can register an onload event listener and walk
> the tree there yourself.
>
> If you were willing to switch to using a 'sub element'
> to indicate that the listener should be attached (a bit like
> animation is currently done) then you could use
> getElementsByTagNameNS to find your child elements (of course
> right now it just walks the tree like you would, eventually
> we may build hashes of this info).
>
> You could also conceivably subclass SAXSVGDocumentFactory
> and parse the document yourself. Then just give the parsed document
> to the canvas with 'setSVGDocument(SVGDocument doc)'.
>
> Alessandro Di Bella wrote:
> > I'm new to BATIK and I'm try to do the following...
> >
> > I have an SVG like:
> >
> > <?xml version="1.0"?>
> > <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.1//EN"
> > "http://www.w3.org/Graphics/SVG/1.1/DTD/svg11.dtd">
> > <svg xmlns="http://www.w3.org/2000/svg" xmlns:myns="........">
> > <g myns:type="mytype" ...../>
> > .................
> > </svg>
> >
> > As you can see I defined a different namespace (myns) that allows me to
> > specify the custom attribute "myns:type".
> >
> > The purpose of this is that I would like to intercept the creation of the
> > GVT object built form the <g> element and based on the value of
> > "myns:type" I want attach different listeners to it.
> >
> > I could not find any ContainerListerer-like class to register with the
> > JSVGCanvas so I thought that I could alternatively use a SAXFilter to
> > intercept the
> > SAX events so that I can grab the IDs of the elements I am interested in.
> >
> > Once i know the IDs I can get the components from the SVGDocument, but
> > even like this I cannot see how to specify the DocumentHanlder when the
> > SVG is loaded.
> >
> >
> > Any help wold be greatly appreciated.
> >
> > Thanks
> >
> > Alessandro
> >
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: [EMAIL PROTECTED]
> > For additional commands, e-mail: [EMAIL PROTECTED]
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: [EMAIL PROTECTED]
> For additional commands, e-mail: [EMAIL PROTECTED]
---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]