You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Selva <se...@yahoo.co.in> on 2006/09/12 15:38:10 UTC

JSVGScrollPane's ScrollBar not updating properly

Hi All,

      After zoomed In the SVGCanvas to larger size, I have moved the
vertical and horizontal scroll bars to the down right corner of the screen.
Now if I tried to zoom out, scrollbars doesn’t change the scroll bars size.
But when I moved the vertical or horizontal scroll bar, it changes the size
of the scroll bar and canvas size.

When I checked in resizeScrollBars() method in JSVGScrollPane, “scrollbar.
SetValues” sets the correct value. But scrollbar slider size is not updated.
But while scroll bars are in top left position, it works fine.

Values while zoom out - 

   maxW = 3850; maxH = 2506 tx = 3242; ty = 1985
   maxW = 3466; maxH = 2256 tx = 2918; ty = 1787
   maxW = 3119; maxH = 2030 tx = 2626; ty = 1608
   maxW = 2808; maxH = 1827 tx = 2364; ty = 1447
   maxW = 2526; maxH = 1645 tx = 2127; ty = 1303
   maxW = 2274; maxH = 1480 tx = 1915; ty = 1172
   maxW = 2047; maxH = 1332 tx = 1723; ty = 1055

Even here changes are in tx and ty values, the scroll bars are not updated.
Please let me know if there is any solution to resolve the issue.

Regards,
Selva

-- 
View this message in context: http://www.nabble.com/JSVGScrollPane%27s-ScrollBar-not-updating-properly-tf2258957.html#a6266310
Sent from the Batik - Users forum at Nabble.com.


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


Re: JSVGScrollPane's ScrollBar not updating properly

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

To update the zoom in transform in canvas, i have translated the zoomed in
transform. but still there is some minor problem.

After zoomed in to large size, i moved the horizontal and vertical scroll
bars to right and bottom corner. Now if i tried to zoomout the document,
scroll bars not moving properly. Herewith i have attached the sample
application. Please let me know where i am doing the mistake.

import javax.swing.JFrame;
import java.awt.BorderLayout;
import javax.swing.JPanel;
import java.awt.*;
import javax.swing.JButton;
import org.apache.batik.swing.JSVGCanvas;
import org.w3c.dom.svg.SVGDocument;
import org.w3c.dom.DOMImplementation;
import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.gvt.GVTTreeRendererAdapter;
import org.w3c.dom.events.EventTarget;
import org.w3c.dom.svg.SVGSVGElement;
import org.w3c.dom.events.EventListener;
import org.w3c.dom.events.Event;
import org.apache.batik.swing.gvt.GVTTreeRendererEvent;
import org.w3c.dom.DOMException;
import org.w3c.dom.Element;
import org.apache.batik.swing.JSVGScrollPane;
import java.awt.event.ActionListener;
import java.awt.event.ActionEvent;
import java.awt.geom.AffineTransform;
import org.apache.batik.util.SVGConstants;
import org.apache.batik.bridge.ViewBox;
import javax.swing.JDialog;
import java.awt.geom.Rectangle2D;

class ExFrame extends JFrame{

    static String svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
    JSVGCanvas svgCanvas = new JSVGCanvas();
    JButton zoomInButton = new JButton("ZoomIn");
    JButton zoomOutButton = new JButton("ZoomOut");

    public static void main(String args[]) {
        ExFrame frame = new ExFrame();
        frame.setDefaultCloseOperation(JDialog.EXIT_ON_CLOSE);
        frame.pack();
        frame.setVisible(true);
    }

    public ExFrame() {
        this.getContentPane().setLayout(new BorderLayout());

        JPanel jPanel1 = new JPanel();
        jPanel1.add(zoomInButton);
        jPanel1.add(zoomOutButton);

        zoomInButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                AffineTransform rat = svgCanvas.getRenderingTransform();
                AffineTransform at = AffineTransform.getScaleInstance(1.1,
1.1);
                AffineTransform t = new AffineTransform(at);
                t.concatenate(rat);

                Rectangle2D viewBox = getViewBoxRect();
                AffineTransform vTx = svgCanvas.getViewBoxTransform();
                final Rectangle docSize =
vTx.createTransformedShape(viewBox).getBounds();
                Rectangle r2d =
t.createTransformedShape(viewBox).getBounds();

                int tx = 0, ty = 0;
                tx = docSize.x - r2d.x;
                ty = docSize.y - r2d.y;
                t.translate( -tx, -ty);
                svgCanvas.setRenderingTransform(t);
            }
        });

        zoomOutButton.addActionListener(new ActionListener() {
            public void actionPerformed(ActionEvent e) {
                AffineTransform rat = svgCanvas.getRenderingTransform();
                AffineTransform at = AffineTransform.getScaleInstance(.9,
.9);
                AffineTransform t = new AffineTransform(at);
                t.concatenate(rat);
               
                Rectangle2D viewBox = getViewBoxRect();
                
                AffineTransform vTx = svgCanvas.getViewBoxTransform();
                final Rectangle docSize =
vTx.createTransformedShape(viewBox).getBounds();
                Rectangle r2d =
t.createTransformedShape(viewBox).getBounds();
                
                int tx = 0, ty = 0;
                tx = docSize.x - r2d.x;
                ty = docSize.y - r2d.y;
                t.translate( -tx, -ty);
                svgCanvas.setRenderingTransform(t);
            }
        });

        DOMImplementation impl =
SVGDOMImplementation.getDOMImplementation();
        SVGDocument doc = (SVGDocument)impl.createDocument(svgNS, "svg",
null);
        svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        JSVGScrollPane graphPane = new JSVGScrollPane(svgCanvas);
        svgCanvas.setDocument(doc);
        graphPane.setPreferredSize(new Dimension(400, 400));
        this.getContentPane().add(graphPane, java.awt.BorderLayout.CENTER);
        this.getContentPane().add(jPanel1, java.awt.BorderLayout.NORTH);
        registerListeners();
    }

    public void registerListeners() {
        svgCanvas.addGVTTreeRendererListener(new GVTTreeRendererAdapter() {
            public void gvtRenderingPrepare(GVTTreeRendererEvent e) {
            }
            public void gvtRenderingCompleted(GVTTreeRendererEvent e) {
                resizeCircle();
            }
        });

        SVGDocument doc = svgCanvas.getSVGDocument();
        SVGSVGElement svgRoot = doc.getRootElement();
        EventTarget t = (EventTarget)svgRoot;
        t.addEventListener("SVGLoad", new OnLoadAction(), false);
    }

    public class OnLoadAction implements EventListener {
        public void handleEvent(Event evt) {
        }
    }

    protected Rectangle2D getViewBoxRect() {
        SVGSVGElement el = svgCanvas.getSVGDocument().getRootElement();
        String viewBoxStr = el.getAttributeNS(null,
SVGConstants.SVG_VIEW_BOX_ATTRIBUTE);
        float[] rect = ViewBox.parseViewBoxAttribute(el, viewBoxStr);
        return new Rectangle2D.Float(rect[0], rect[1], rect[2], rect[3]);
    }


    private void resizeCircle() throws DOMException {
        try {
            SVGDocument doc = svgCanvas.getSVGDocument();
            doc.getRootElement().setAttribute("width", "" + 100);
            doc.getRootElement().setAttribute("height", "" + 100);
            doc.getRootElement().setAttribute("viewBox", "0 0 " + 100 + " "
+ 100);
            doc.getRootElement().setAttribute("preserveAspectRatio",
"none");

            Element rect =
doc.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI, "rect");
            rect.setAttributeNS(null, "id", "rec");
            rect.setAttributeNS(null, "x", "25");
            rect.setAttributeNS(null, "y", "25");
            rect.setAttributeNS(null, "width", "50");
            rect.setAttributeNS(null, "height", "50");
            rect.setAttributeNS(null, "style", "fill:red; stroke:green");
            doc.getRootElement().appendChild(rect);
        } catch (Exception e) {}
    }

}

Thanks in advance.

Regards,
Selva

-- 
View this message in context: http://www.nabble.com/JSVGScrollPane%27s-ScrollBar-not-updating-properly-tf2258957.html#a6322136
Sent from the Batik - Users forum at Nabble.com.


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


Re: JSVGScrollPane's ScrollBar not updating properly

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

I have done the following changes in JSVGScrollPane.java instead of 
"vertical.  setValues(ty, vpSize.height, 0, maxH)" and
"horizontal.setValues(tx, vpSize.width,  0, maxW)". Now horizontal and
vertical scroll bars are updating properly. But SVGCanvas is not updating
properly it means the zoom out changes are not updated in Canvas. It is
happening only when there is no shapes in the viewing transform. You can
reproduce this problem in the attached code in earlier mail.

but if we move the scroll bars, it is showing the SVG document properly. Can
you please explain what may be the problem?

        vertical.setMaximum(maxH);
        vertical.setMinimum(0);
        vertical.setValue(ty);
        vertical.getModel().setExtent(vpSize.height);

        horizontal.setMaximum(maxW);
        horizontal.setMinimum(0);
        horizontal.setValue(tx);
        horizontal.getModel().setExtent(vpSize.width);

Thanks in advance.

Regards,
Selva

-- 
View this message in context: http://www.nabble.com/JSVGScrollPane%27s-ScrollBar-not-updating-properly-tf2258957.html#a6303356
Sent from the Batik - Users forum at Nabble.com.


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


Re: JSVGScrollPane's ScrollBar not updating properly

Posted by Selva <se...@yahoo.co.in>.
Hi Thomas,

>    Are you using the SVN version of Batik?  I know that I fixed a number 
> of bugs in the scrollbar code after the 1.6 release.

Actually my JSVGScrollPane.java updated from SVN. I have compared it from
the follwing link.
http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/swing/JSVGScrollPane.java?view=log


Thanks,
Selva


-- 
View this message in context: http://www.nabble.com/JSVGScrollPane%27s-ScrollBar-not-updating-properly-tf2258957.html#a6287186
Sent from the Batik - Users forum at Nabble.com.


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


Re: JSVGScrollPane's ScrollBar not updating properly

Posted by th...@kodak.com.
Hi Selva,

    Are you using the SVN version of Batik?  I know that I fixed a number 
of bugs
in the scrollbar code after the 1.6 release.

Selva <se...@yahoo.co.in> wrote on 09/12/2006 09:38:10 AM:

> When I checked in resizeScrollBars() method in JSVGScrollPane, 
“scrollbar.
> SetValues” sets the correct value. But scrollbar slider size is not 
updated.
> But while scroll bars are in top left position, it works fine.
> 
> Values while zoom out - 
> 
>    maxW = 3850; maxH = 2506 tx = 3242; ty = 1985
>    maxW = 3466; maxH = 2256 tx = 2918; ty = 1787
>    maxW = 3119; maxH = 2030 tx = 2626; ty = 1608
>    maxW = 2808; maxH = 1827 tx = 2364; ty = 1447
>    maxW = 2526; maxH = 1645 tx = 2127; ty = 1303
>    maxW = 2274; maxH = 1480 tx = 1915; ty = 1172
>    maxW = 2047; maxH = 1332 tx = 1723; ty = 1055
> 
> Even here changes are in tx and ty values, the scroll bars are not 
updated.
> Please let me know if there is any solution to resolve the issue.
> 
> Regards,
> Selva
> 
> -- 
> View this message in context: http://www.nabble.com/JSVGScrollPane%27s-
> ScrollBar-not-updating-properly-tf2258957.html#a6266310
> Sent from the Batik - Users forum at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>