batik-users@xmlgraphics.apache.org
[Top] [All Lists]

Re: adding and id attribute when using SVGGraphics

Subject: Re: adding and id attribute when using SVGGraphics
From: "Abraham Rodriguez Mota"
Date: Tue, 8 Jul 2008 18:09:27 +0100
Hi Thomas,

I agree with your explanation. But I was thinking to keep the SVGGraphics2D object alive and use it every time a user clicks on the element. However, it looks that that will mean that every time the figure is re-draw or modified, the events and id should be added again too. So it looks that is not the best option to achieve my goals.

Maybe it could be worth to try to save the svg representation as a DocumentFragment that can be easily traverse and modified, before it is added to the document.

Anyway, Thanks a lot for your help.

All the best

On Tue, Jul 8, 2008 at 10:37 AM, <thomas.deweese@xxxxxxxxx> wrote:

Hi Abraham,

"Abraham Rodriguez Mota" <abraham.rdgz@xxxxxxxxx> wrote on 07/08/2008 04:59:20 AM:


> I think that your code works making the assumption that the added
> element is always the last children in the document, but I need to
> added elements in different locations through the SVG tree.


   It assumes that the element just drawn is the last child of
the element passed to getRoot, when getRoot is called immediately
after the element is drawn, which should always be the case.

> I also thought that using a Document Fragment and doing what you
> propouse could resolve the problem but I that is to complex for
> something that commun, isn't it?.

   The problem is that the Graphics2D is ment to take a hunk of
Java2D drawing and essentially persist it to SVG.  It isn't
designed to annotate and structure the generated SVG.  It's tricky
enough to transcode almost all of the Graphics2D commands allowing
the user to try and muck with the content as it's generated would
be a real pain.

> On 7/8/08, thomas.deweese@xxxxxxxxx <thomas.deweese@xxxxxxxxx> wrote:
>
> Hi Abraham,
>
> "Abraham Rodriguez Mota" <abraham.rdgz@xxxxxxxxx> wrote on
> 07/07/2008 02:09:43 PM:
>
> > I have been trying to find the way to add an "id" attribute to a
> > rectangle using SVGGraphics2D. I got the code shown below. But I
> > haven't found the way to do it. It looks as it is an old issue but i
> > couldn't find a concrete answer.
>
>   Yah, there isn't a really good answer, but the following
> will work.
>
> > public void paint(SVGGraphics2D g2d) {
> >         EventTarget target;
> >         g2d.setPaint(Color.red);
> >         g2d.fill(new Rectangle(10, 10, 100, 100));          
> >         Element root=svgDocument.getDocumentElement();
> >         g2d.getRoot(root);
>
>         Element curr = root;
>         Element lc = curr;
>         while (lc != null) {
>            curr = lc;
>            lc = (Element)curr.getLastChild();
>         }
>         curr.setAttributeNS(null, "id", "some_id_you_want");
>
> > }

<Prev in Thread] Current Thread [Next in Thread>