xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From André Ávila <asan...@nextech.com.br>
Subject Re: Synchronizing JSVGCanvas - Again
Date Wed, 12 Apr 2006 18:08:14 GMT
Hi Thomas,

> > They both could be holding SVG documents.
>
>    Ohh, the way you were talking it sounded like the top
> was empty and you had replaced it's paint method...

Sorry, I was not very clear about what I'm doing. This is the exact
situation I'm dealing with: the top canvas is empty, the bottom canvas has a
document, like you said. I need the top canvas to be an SVGCanvas because,
eventually, it might display documents as well.

But for the moment yes, we can assume the top canvas is empty and the user
will only draw Java2D shapes on it.

> > It seems a very good idea. I couldn't find much on using overlays in the
> > list, so maybe you can point me some further directions.
>
>    The Source code?  There really isn't much to know...

Yes, now I noticed... :)

>
> > I implemented the DrawOverlay class as an inner class of my SVG canvas]
> > private class DrawOverlay implements Overlay {
> >
> >   public void paint(Graphics g) {
> >    Graphics2D g2d = (Graphics2D)g;
> >    drawTool.drawShapes(g2d);    // Redraw all shapes
> >    repaint();    // Calls repaint on owner SVGCanvas
>
>     Don't call repaint this should lead to an infinite loop.
> If your list of shapes changes you will need to trigger a
> repaint of the canvas, it will then call your overlay to paint...

Right, that was dumb.

> > So here's my question: when is the overlay paint() method called? My
> first
> > guess was that it would be called every time the canvas repaint() (or
> > paint()?) was called, but I see this is not the case.
>
>    It is called whenever the canvas is painted - if the canvas has an
> offscreen image (i.e. it is rendering an SVG document), which from your
> earlier talk I'm guessing your top Canvas doesn't.  I would lean towards
> considering this behavior a bug (it's easy to fix, move the loop at the
> end
> of batik.swing.gvt.JGVTComponent.paintComponent outside the check if the
> image is null).

Ok, got it now. Looks like I'm almost there. Still, for some reason the
shapes are not transformed right.

Here's what I did to clear things a little bit. I have only one canvas now,
default subclass of JSVGCanvas (no overridden methods, just plain old
JSVGCanvas). It has a document rendered. I add my DrawOverlay to it, drawing
only a standard rectangle. When I try to pan the image, the rectangle goes
off on its own. If you would spare a few minutes on this, you could easily
reproduce this behavior using the following code:

 private class DrawOverlay implements Overlay {

    Shape rect = new Rectangle2D.Double(200,200,100,100);

    public void paint(Graphics g) {
        AffineTransform at = getPaintingTransform();

        Graphics2D g2d = (Graphics2D)g;

        Shape s = null;
        if (at != null) {
            s = at.createTransformedShape(rect);
        } else {
            s = rect;
        }

        g2d.setColor(Color.RED);
        g2d.draw(s);
}

It's a bit strange, because it is essentially the same code as in
TextSelectionManager.SelectionOverlay.paint(). What am I missing?


---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Mime
View raw message