xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From Heidrun Beer <hB...@sgmt.at>
Subject Re: Question on Zoom
Date Sat, 12 Sep 2009 10:07:57 GMT
On Wed, 9 Sep 2009 12:39:29 -0600, bharat chatla wrote in
<3f4ad8820909091139u717b5d3dp1f07262ba8bdfa29@mail.gmail.com>:

>Hi all,
>
>Can someone give me sample code on how to control zoom in and zoom out. I
>have added svg file on applet and now with the help of two buttons I want to
>control the zooming feature.
>
>Thanks,
>Bharat



Hi Bharat,


I just researched this issue and found that it caused me severe
headaches :-)

I could zoom in or out, but would lose the pan position when 
zooming.

Or I could pan with four arrow buttons (don't want to use the
zoom/pan interactors), but then my zoom factor would be lost.

Don't ask me why it must be so complicated (and why the Batik
Javadoc never gives any code snippets), but the solution is to 
combine two AffineTransform objects. 

Below is the complete code for one of my six buttons (zoom in, 
zoom out, pan left, pan right, pan up, pan down). Pay attention 
to the line before I hand the affine transform to the canvas: 
here the scale transform and the pan transform are combined.

If you need zoom only, or pan only, you can work with one
of the two AffineTransforms.


        JButton pan_up = new JButton("");
        pan_up.setBounds(50, 30, 18,19);
        pan_up.setFont(new Font("Arial", Font.BOLD, 12));


        try {
            URL url = new URL(getCodeBase(), "PanUp.jpg");
            Icon icon5 = new ImageIcon(url);
            pan_up.setIcon(icon5);
        } catch (Exception e) {
            System.out.println(e.toString());
        }

	pan_up.addActionListener(new ActionListener() {

        public void actionPerformed(ActionEvent e) {

        Runnable r = new Runnable() {

            public void run() {

                AffineTransform at = canvas.getRenderingTransform();
                AffineTransform at2 = canvas.getRenderingTransform();

                double dX = at.getTranslateX();
                double dY = at.getTranslateY();
                double dX2 = at.getScaleX();
                double dY2 = at.getScaleY();

                at.setToTranslation((dX), (dY+100));
                at2.setToScale(dX2, dY2);
                at.concatenate(at2);

                canvas.setRenderingTransform(at);

            }
        };

        UpdateManager um = canvas.getUpdateManager();
        um.getUpdateRunnableQueue().invokeLater(r);

        }
        });


        palette.add(pan_up);




Hope this helps!


Best,


Heidrun Beer

Workgroup for Fundamental Spiritual Research and Mental Training
http://www.sgmt.at
http://www.RecastReality.org



---------------------------------------------------------------------
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