Hello all,

I have recently been working with an application that uses SVGGraphics2D to take information from a canvas and save it to an SVG file. The complication comes from the fact that I wish to use the id tag associated with a number of basic shape elements to embed extra information that can be read in by a different application. In looking over the email archives I was able to find this message (http://mail-archives.apache.org/mod_mbox/xmlgraphics-batik-users/200603.mbox/[EMAIL PROTECTED] ) which sort of deals with my issue and I confess that I found the response a little disappointing.

My basic solution looks something like this (I did not compile this code snippet so apologies if there are minor typos):

...
        svgGenerator.draw(new Rectangle2D.Double(10, 10, 20, 20));
        Node elem = svgGenerator.getRoot();
        while (elem.getLastChild() != null) {
            elem = elem.getLastChild();
        }
        Element lastElement = (Element)elem;
        lastElement.setAttribute("id", "foo");
...

This is not particularly efficient or elegant but I am hoping that it works. My primary question to the newsgroup is, is this method safe? Can I guarantee that this solution will always return the last element drawn?

My secondary question is has anyone ever considered tweaking the API to include methods to access the last element drawn (or filled, etc.)?
Having the 'public void draw(Shape s)' changed to 'public Element draw(Shape s)' would be very useful to me in this instance and it would not be hard to envision others. At least I can't see the harm of adding a completely new method ('public Element drawReturn(Shape)' or something) that emulates the same functionality.

Philip Wilder

Reply via email to