You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Vepsu <ve...@gmail.com> on 2008/06/04 14:11:25 UTC
Adding element to DOM (problem)
Hello,
I have a problem and I can't seem to get around it..
So my java-app loads SVG-map and then I'm trying to add an element to it by
using DOM and I would like to see the change in SVGCanvas.
But when I add an element, the svgCanvas doesn't seem to update at all, even
that I'm pretty sure that the DOM-structure changes.
Funny thing is, that setAttributes -method works nicely and I can change
elements which are
already there (ie. change a fill-color for a circle).
Some code:
// Loading the document
String parser = XMLResourceDescriptor.getXMLParserClassName();
SAXSVGDocumentFactory f = new SAXSVGDocumentFactory(parser);
String uri = img.toString();
doc = (SVGDocument)f.createDocument(uri);
JSVGCanvas svgCanvas = new JSVGCanvas();
svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
svgCanvas.setSVGDocument((SVGDocument)doc);
// Trying to add DOM-element
UpdateManager um = svgCanvas.getUpdateManager();
um.getUpdateRunnableQueue().invokeLater(new Runnable() {
public void run() {
// This WORKS
Element cir = doc.getElementById("mycircle");
cir.setAttribute("fill", "yellow");
// This doesn't
Element newMarker = doc.createElement("circle");
newMarker.setAttribute("cx", "120");
newMarker.setAttribute("cy", "120");
newMarker.setAttribute("fill", "blue");
newMarker.setAttribute("r", "50");
newMarker.setAttribute("stroke", "black");
newMarker.setAttribute("stroke-width", "4");
svgCanvas.getSVGDocument().getRootElement().appendChild(newMarker);
svgCanvas.repaint();
}
});
Any help would be welcomed.
--
View this message in context: http://www.nabble.com/Adding-element-to-DOM-%28problem%29-tp17645225p17645225.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Adding element to DOM (problem)
Posted by Vepsu <ve...@gmail.com>.
Archie Cobbs wrote:
>
> On Wed, Jun 4, 2008 at 7:11 AM, Vepsu <ve...@gmail.com> wrote:
>> Element newMarker = doc.createElement("circle");
>
> That should be createElementNS(SVG_NAMESPACE_URI, "circle") instead...
>
> -Archie
>
> --
> Archie L. Cobbs
>
>
Thank you Archie, that did the trick. I also had to change the
namespace-parameters to null for the setAttributeNS -methods.
But it works now, you saved my day.
--
View this message in context: http://www.nabble.com/Adding-element-to-DOM-%28problem%29-tp17645225p17662467.html
Sent from the Batik - Users mailing list archive at Nabble.com.
---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
Re: Adding element to DOM (problem)
Posted by Archie Cobbs <ar...@dellroad.org>.
On Wed, Jun 4, 2008 at 7:11 AM, Vepsu <ve...@gmail.com> wrote:
> Element newMarker = doc.createElement("circle");
That should be createElementNS(SVG_NAMESPACE_URI, "circle") instead...
-Archie
--
Archie L. Cobbs