Hi Naveed,
The short answer to your question is you don't. The GVT is not
designed to be
used this way, and you will be fighting the system the entire way. While
you are
welcome to hack the source all you want, don't expect a lot of support.
noni_4444 <[EMAIL PROTECTED]> wrote on 09/29/2007 11:52:47 AM:
> I am trying to animate a rectangle within an svgCanvas. To speed up
things i
> want to do it with gvt. As i first step i just modified the following
code
>
> oAnimObject.oFgElm.setAttribute( .... );
> with
> // Getting the graphics node corresponding to svg element
> GraphicsNode gn =
> svgCanvas.getUpdateManager().getBridgeContext().
>
> getGraphicsNode(oAnimObject.oFgElm);
> AffineTransform theTransform = gn.getGlobalTransform();
> Rectangle2D theBounds =
gn.getTransformedBounds(theTransform);
> Graphics2D g2d = (Graphics2D)svgCanvas.getGraphics();
This approach is essentially 100% incompatible with the design of
the JSVGCanvas, which draws to an offscreen buffer, and does dirty region
calculation.
> The behavior i get is that instead of one rectangle i get two rectangles
> drawn on the canvas. My guess is that one of these is the original
rectangle
> (part of the svg file) and second one (drawn at an offset) is the one
drawn
> by the gn.paint(g2d). I would want both of these to overlap. My
svgcanvas
> state is set to dynamic and the above piece of code comes inside the
update
> managers thread. I am using jsvgcanvas.
If you simply update the transform or geometry of the GraphicsNode then
the canvas will automatically update the display. However above you are
'manually' shifting the drawing of the one graphicsNode by adjusting the
Graphics2D transform.
> What i want to know is
> 1. How to do transformation in the right way? What things to
> consider when choosing which transformation method call?
Let the Canvas handle the drawing/updates.
> 2. Is there a way i can set my svgcanvas state to static and
> still be able to view changes made in gvt? If i try it myself, the
canvas
> does update itself. Do i have to call repaint or something like that.
How?
When the canvas is static it doesn't do dirty region tracking so the
only
way to update the display is to redraw the entire screen (as opposed to
subparts).
> 3. Is the graphics object specific to a svgcanvas component.
> Cann't i get a graphics object which i can use directly with a shape
without
> any translation or transformation?
No the GraphicsNodes live in the GVT tree and they assume that the tree
has been walked (updating the Graphics2D's transform as it goes). Don't
forget
that there are many other features of SVG that pretty much require this,
like
filters, clipping, masking, etc...
> 4. Graphics2D is awt based while svgcanvas is a swing
component.
> Mixing both of these causes flickering while animating. Isn't there any
> swing based mechanism of handling changes to GVT?
The flickering is caused because you aren't using the double buffer in
the
canvas, so the drawing and swing updates are out of sync...
> I have not got a chance to work with batik's transformations or with GVT
> previously. So please share any links i can use to learn about these.
Google for AffineTransform they are a common tool of PostScript, PDF,
Flash, XAML, SVG, ....