> > I am trying to programatically zoom into an area which i know the
absolute
> > coordinates of.
> > I searched for a way to do that, and only found this:
> >
> >         AffineTransform at = new AffineTransform();
> >         at.scale(scale, scale);
> >         at.translate(-xStart, -yStart);
> >
> >         at.concatenate(canvas.getRenderingTransform());
> >         canvas.setRenderingTransform(at);
> >
> > but this does not really help me since i know the exact coordinates
(x1,y1,
> > x2,y2) of the area i want to zoom in to.
>
> That's exactly AffineTransform do. What you need is to calculate the
> current view transform compare with the exact coordinate you want to
> zoom. Then just transform scale and transform translate.
>

I don't seem to be able to do it right. after the transfor, i get a white
page with nothing in it. it seems it zooms to an area that is different than
what i want.
If you have an example of doing it the right way, I appreciate it if you can
please post here.

or if you can look at the code below, and tell me where did i go wrong...
in this code, i tried to follow what is done in
org.apache.batik.swing.gvt.AbstractZoomInteractor.mouseReleased


        double x1= my value
        double y1= my value
        double x2= my value
        double y2= my value

        double xCurrent = x2;
        double yCurrent = y2;
        double xStart = x1;
        double yStart = y1;

         if ((xCurrent - xStart) != 0 &&
            (yCurrent - yStart) != 0) {

            int dx = xCurrent - xStart;
            int dy = yCurrent - yStart;

            if (dx < 0) {
                dx = -dx;
                xStart = xCurrent;
            }
            if (dy < 0) {
                dy = -dy;
                yStart = yCurrent;
            }

            Dimension size = c.getSize();

            // Zoom factor
            float scaleX = size.width / (float)dx;
            float scaleY = size.height / (float)dy;
            float scale = (scaleX < scaleY) ? scaleX : scaleY;

            // Zoom translate
            AffineTransform at = new AffineTransform();
            at.scale(scale, scale);
            at.translate(-xStart, -yStart);

            at.concatenate(c.getRenderingTransform());
            c.setRenderingTransform(at);


thanks
hilz




---------------------------------------------------------------------
To unsubscribe, e-mail: [EMAIL PROTECTED]
For additional commands, e-mail: [EMAIL PROTECTED]

Reply via email to