What I want to do is to insert new Element to SVGDocument taken from JSVG canvas, so that it is should be automatically rendered and can be viewed.
So I have a JSVGCanvas, named SVGcanvas, and at LoadEventDispatcher I get the the SVGDocument, named doc, like this code:
this.SVGCanvas.addSVGLoadEventDispatcherListener(
new SVGLoadEventDispatcherAdapter() {
@Override
public void svgLoadEventDispatchStarted (SVGLoadEventDispatcherEvent e) {
doc = SVGCanvas.getSVGDocument();
...
}
}
up is based on this: http://www.svgopen.org/2002/papers/kormann__developing_svg_apps_with_batik/
and then inside an event listener, I use this code
public void handleEvent (Event evt) {
setRB(this.IDButtonGroup, this.ID);
Element r = ((SVGDocument) doc).createElement("use");
r.setAttribute("xhtml:href", "#cell");
doc.getDocumentElement().appendChild(r);
}
based on this: http://wiki.apache.org/xmlgraphics-batik/DynamicSvgOffscreen
I thought it will work at onscreen, but I still can’t get it to work. Anyone can help? The setRB function is work okay, so I don’t think the problem is in the handler. I think the SVGCanvas not rendering the new doc. The doc should be SVGCanvas’s, and because I had set the Document State of SVG Canvas to be ALWAYS_DYNAMIC, I thought it will be updated automatically. Did I miss something?
Okay, the way I do it is right, but I do miss something.
based on this: http://www.carto.net/papers/svg/manipulating_svg_with_dom_ecmascript/
I should use
and you are done! The cell defs is in the SVGCanvas now!
Oh yeah, the SVGNS and XLINKNS is NameSpace String Constant