deweese     2003/06/16 18:37:57

  Modified:    sources/org/apache/batik/apps/svgbrowser
                        JSVGViewerFrame.java
               sources/org/apache/batik/bridge SVGEllipseElementBridge.java
                        SVGShapeElementBridge.java SVGUtilities.java
               sources/org/apache/batik/gvt ShapeNode.java
               sources/org/apache/batik/swing JSVGCanvas.java
               sources/org/apache/batik/swing/svg JSVGComponent.java
  Log:
  
  
  Revision  Changes    Path
  1.94      +16 -5     
xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
  
  Index: JSVGViewerFrame.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java,v
  retrieving revision 1.93
  retrieving revision 1.94
  diff -u -r1.93 -r1.94
  --- JSVGViewerFrame.java      11 Apr 2003 13:54:36 -0000      1.93
  +++ JSVGViewerFrame.java      17 Jun 2003 01:37:56 -0000      1.94
  @@ -435,9 +435,10 @@
           // of unnecessary large images.
           //
           svgCanvas = new JSVGCanvas(userAgent, true, true){
  -                Dimension screenSize = Toolkit.getDefaultToolkit().getScreenSize();
  +                Dimension screenSize;
                   
                   {
  +                    screenSize = Toolkit.getDefaultToolkit().getScreenSize();
                       setMaximumSize(screenSize);
                   }
                   
  @@ -447,7 +448,20 @@
                       if (s.height > screenSize.height) s.height = screenSize.height;
                       return s;
                   }
  +
                   
  +                /**
  +                 * This method is called when the component knows the desired
  +                 * size of the window (based on width/height of outermost SVG
  +                 * element). We override it to immediately pack this frame.
  +                 */
  +                public void setMySize(Dimension d) {
  +                    setPreferredSize(d);
  +                    invalidate();
  +                    if (JSVGViewerFrame.this.autoAdjust) {
  +                        JSVGViewerFrame.this.pack();
  +                    }
  +                }
               };
           
           javax.swing.ActionMap map = svgCanvas.getActionMap();
  @@ -1847,9 +1861,6 @@
           svgCanvas.setSelectionOverlayXORMode
               (application.isSelectionOverlayXORMode());
           svgCanvas.requestFocus();  // request focus when load completes.
  -        if (autoAdjust) {
  -            pack();
  -        }
       }
   
       /**
  
  
  
  1.12      +3 -7      
xml-batik/sources/org/apache/batik/bridge/SVGEllipseElementBridge.java
  
  Index: SVGEllipseElementBridge.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGEllipseElementBridge.java,v
  retrieving revision 1.11
  retrieving revision 1.12
  diff -u -r1.11 -r1.12
  --- SVGEllipseElementBridge.java      11 Apr 2003 13:54:46 -0000      1.11
  +++ SVGEllipseElementBridge.java      17 Jun 2003 01:37:57 -0000      1.12
  @@ -81,11 +81,6 @@
               throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
                                         new Object[] {SVG_RX_ATTRIBUTE, s});
           }
  -     // A value of zero disables rendering of the element
  -     if (rx == 0) {
  -            shapeNode.setShape(null);
  -         return;
  -     }
   
           // 'ry' attribute - required
           s = e.getAttributeNS(null, SVG_RY_ATTRIBUTE);
  @@ -97,8 +92,9 @@
               throw new BridgeException(e, ERR_ATTRIBUTE_MISSING,
                                         new Object[] {SVG_RY_ATTRIBUTE, s});
           }
  +
        // A value of zero disables rendering of the element
  -     if (ry == 0) {
  +     if ((rx == 0) || (ry == 0)) {
               shapeNode.setShape(null);
            return;
        }
  
  
  
  1.22      +2 -4      
xml-batik/sources/org/apache/batik/bridge/SVGShapeElementBridge.java
  
  Index: SVGShapeElementBridge.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGShapeElementBridge.java,v
  retrieving revision 1.21
  retrieving revision 1.22
  diff -u -r1.21 -r1.22
  --- SVGShapeElementBridge.java        30 May 2003 01:07:15 -0000      1.21
  +++ SVGShapeElementBridge.java        17 Jun 2003 01:37:57 -0000      1.22
  @@ -45,9 +45,7 @@
        }
           // delegates to subclasses the shape construction
           buildShape(ctx, e, shapeNode);
  -        if (shapeNode.getShape() == null) {
  -         return null; // Disable the rendering if something bad happens
  -        }
  +
           // 'shape-rendering' and 'color-rendering'
           RenderingHints hints = CSSUtilities.convertShapeRendering(e, null);
           hints = CSSUtilities.convertColorRendering(e, hints);
  
  
  
  1.25      +45 -37    xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java
  
  Index: SVGUtilities.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/bridge/SVGUtilities.java,v
  retrieving revision 1.24
  retrieving revision 1.25
  diff -u -r1.24 -r1.25
  --- SVGUtilities.java 28 May 2003 14:40:57 -0000      1.24
  +++ SVGUtilities.java 17 Jun 2003 01:37:57 -0000      1.25
  @@ -703,21 +703,25 @@
               break;
           case OBJECT_BOUNDING_BOX:
               Rectangle2D bounds = filteredNode.getGeometryBounds();
  -            dx = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
  -                (dxStr, BatikExtConstants.BATIK_EXT_DX_ATRIBUTE, uctx);
  -            dx *= bounds.getWidth();
  -
  -            dy = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox
  -                (dyStr, BatikExtConstants.BATIK_EXT_DY_ATRIBUTE, uctx);
  -            dy *= bounds.getHeight();
  -
  -            dw = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
  -                (dwStr, BatikExtConstants.BATIK_EXT_DW_ATRIBUTE, uctx);
  -            dw *= bounds.getWidth();
  -
  -            dh = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox
  -                (dhStr, BatikExtConstants.BATIK_EXT_DH_ATRIBUTE, uctx);
  -            dh *= bounds.getHeight();
  +            if (bounds == null) {
  +                dx = dy = dw = dh = 0;
  +            } else {
  +                dx = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
  +                    (dxStr, BatikExtConstants.BATIK_EXT_DX_ATRIBUTE, uctx);
  +                dx *= bounds.getWidth();
  +
  +                dy = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox
  +                    (dyStr, BatikExtConstants.BATIK_EXT_DY_ATRIBUTE, uctx);
  +                dy *= bounds.getHeight();
  +
  +                dw = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
  +                    (dwStr, BatikExtConstants.BATIK_EXT_DW_ATRIBUTE, uctx);
  +                dw *= bounds.getWidth();
  +
  +                dh = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox
  +                    (dhStr, BatikExtConstants.BATIK_EXT_DH_ATRIBUTE, uctx);
  +                dh *= bounds.getHeight();
  +            }
               break;
           default:
               throw new Error(); // can't be reached
  @@ -798,25 +802,27 @@
           switch (unitsType) {
           case OBJECT_BOUNDING_BOX:
               Rectangle2D bounds = filteredNode.getGeometryBounds();
  -            if (xStr.length() != 0) {
  -                x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
  -                    (xStr, SVG_X_ATTRIBUTE, uctx);
  -                x = bounds.getX() + x*bounds.getWidth();
  -            }
  -            if (yStr.length() != 0) {
  -                y = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox
  -                    (yStr, SVG_Y_ATTRIBUTE, uctx);
  -                y = bounds.getY() + y*bounds.getHeight();
  -            }
  -            if (wStr.length() != 0) {
  -                w = UnitProcessor.svgHorizontalLengthToObjectBoundingBox
  -                    (wStr, SVG_WIDTH_ATTRIBUTE, uctx);
  -                w *= bounds.getWidth();
  -            }
  -            if (hStr.length() != 0) {
  -                h = UnitProcessor.svgVerticalLengthToObjectBoundingBox
  -                    (hStr, SVG_HEIGHT_ATTRIBUTE, uctx);
  -                h *= bounds.getHeight();
  +            if (bounds != null) {
  +                if (xStr.length() != 0) {
  +                    x = UnitProcessor.svgHorizontalCoordinateToObjectBoundingBox
  +                        (xStr, SVG_X_ATTRIBUTE, uctx);
  +                    x = bounds.getX() + x*bounds.getWidth();
  +                }
  +                if (yStr.length() != 0) {
  +                    y = UnitProcessor.svgVerticalCoordinateToObjectBoundingBox
  +                        (yStr, SVG_Y_ATTRIBUTE, uctx);
  +                    y = bounds.getY() + y*bounds.getHeight();
  +                }
  +                if (wStr.length() != 0) {
  +                    w = UnitProcessor.svgHorizontalLengthToObjectBoundingBox
  +                        (wStr, SVG_WIDTH_ATTRIBUTE, uctx);
  +                    w *= bounds.getWidth();
  +                }
  +                if (hStr.length() != 0) {
  +                    h = UnitProcessor.svgVerticalLengthToObjectBoundingBox
  +                        (hStr, SVG_HEIGHT_ATTRIBUTE, uctx);
  +                    h *= bounds.getHeight();
  +                }
               }
               break;
           case USER_SPACE_ON_USE:
  @@ -1061,8 +1067,10 @@
   
           AffineTransform Mx = new AffineTransform();
           Rectangle2D bounds = node.getGeometryBounds();
  -        Mx.translate(bounds.getX(), bounds.getY());
  -        Mx.scale(bounds.getWidth(), bounds.getHeight());
  +        if (bounds != null) {
  +            Mx.translate(bounds.getX(), bounds.getY());
  +            Mx.scale(bounds.getWidth(), bounds.getHeight());
  +        }
           Mx.concatenate(Tx);
           return Mx;
       }
  
  
  
  1.21      +9 -3      xml-batik/sources/org/apache/batik/gvt/ShapeNode.java
  
  Index: ShapeNode.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/gvt/ShapeNode.java,v
  retrieving revision 1.20
  retrieving revision 1.21
  diff -u -r1.20 -r1.21
  --- ShapeNode.java    30 May 2003 01:07:16 -0000      1.20
  +++ ShapeNode.java    17 Jun 2003 01:37:57 -0000      1.21
  @@ -98,6 +98,8 @@
        * @param newShapePainter the new ShapePainter to use
        */
       public void setShapePainter(ShapePainter newShapePainter) {
  +        if (shape == null) // Doesn't matter if we don't have a shape.
  +            return;
           fireGraphicsNodeChangeStarted();
           invalidateGeometryCache();
           this.shapePainter = newShapePainter;
  @@ -252,6 +254,8 @@
       public Shape getSensitiveArea() {
           if (sensitiveArea != null) 
               return sensitiveArea;
  +        if (shapePainter == null)
  +            return null;
   
           // <!> NOT REALLY NICE CODE BUT NO OTHER WAY
           ShapePainter strokeShapePainter = null;
  @@ -260,8 +264,9 @@
               strokeShapePainter = shapePainter;
           } else if (shapePainter instanceof FillShapePainter) {
               fillShapePainter = shapePainter;
  -        } else {
  +        } else if (shapePainter instanceof CompositeShapePainter) {
               CompositeShapePainter cp = (CompositeShapePainter)shapePainter;
  +
               for (int i=0; i < cp.getShapePainterCount(); ++i) {
                   ShapePainter sp = cp.getShapePainter(i);
                   if (sp instanceof StrokeShapePainter) {
  @@ -270,7 +275,8 @@
                       fillShapePainter = sp;
                   }
               }
  -        }
  +        } else return null; // Don't know what we have...
  +
   
           switch(pointerEventType) {
           case VISIBLE_PAINTED:
  
  
  
  1.39      +68 -84    xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java
  
  Index: JSVGCanvas.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/JSVGCanvas.java,v
  retrieving revision 1.38
  retrieving revision 1.39
  diff -u -r1.38 -r1.39
  --- JSVGCanvas.java   11 Jun 2003 22:07:27 -0000      1.38
  +++ JSVGCanvas.java   17 Jun 2003 01:37:57 -0000      1.39
  @@ -511,134 +511,118 @@
       }
   
       /**
  -     * A swing action to zoom in the canvas.
  +     * A swing action to append an affine transform to the current
  +     * rendering transform.  Before the rendering transform is
  +     * applied the method translates the center of the display to
  +     * 0,0 so scale and rotate occur around the middle of
  +     * the display.
        */
  -    protected class ZoomInAction extends AbstractAction {
  +    protected class AffineAction extends AbstractAction {
  +        AffineTransform at;
  +        public AffineAction(AffineTransform at) {
  +            this.at = at;
  +        }
  +
           public void actionPerformed(ActionEvent evt) {
               if (gvtRoot == null) {
                   return;
               }
  -            AffineTransform at = getRenderingTransform();
  +            AffineTransform rat = getRenderingTransform();
               if (at != null) {
                   Dimension dim = getSize();
                   int x = dim.width / 2;
                   int y = dim.height / 2;
                   AffineTransform t = AffineTransform.getTranslateInstance(x, y);
  -                t.scale(2, 2);
  -                t.translate(-x, -y);
                   t.concatenate(at);
  +                t.translate(-x, -y);
  +                t.concatenate(rat);
                   setRenderingTransform(t);
               }
           }
       }
   
       /**
  -     * A swing action to zoom out the canvas.
  +     * A swing action to apply a zoom factor to the canvas.
  +     * This can be used to zoom in (scale > 1) and out (scale <1).
        */
  -    protected class ZoomOutAction extends AbstractAction {
  -        public void actionPerformed(ActionEvent evt) {
  -            if (gvtRoot == null) {
  -                return;
  -            }
  -            AffineTransform at = getRenderingTransform();
  -            if (at != null) {
  -                Dimension dim = getSize();
  -                int x = dim.width / 2;
  -                int y = dim.height / 2;
  -                AffineTransform t = AffineTransform.getTranslateInstance(x, y);
  -                t.scale(.5, .5);
  -                t.translate(-x, -y);
  -                t.concatenate(at);
  -                setRenderingTransform(t);
  -            }
  +    protected class ZoomAction extends AffineAction {
  +        public ZoomAction(double scale) {
  +            super(AffineTransform.getScaleInstance(scale, scale));
  +        }
  +        public ZoomAction(double scaleX, double scaleY) {
  +            super(AffineTransform.getScaleInstance(scaleX, scaleY));
           }
       }
   
       /**
  -     * A swing action to scroll the canvas to the right.
  +     * A swing action to zoom in the canvas.
        */
  -    protected class ScrollRightAction extends AbstractAction {
  +    protected class ZoomInAction extends ZoomAction {
  +        ZoomInAction() { super(2); }
  +    }
   
  -        /** The scroll increment. */
  -        protected int inc;
  +    /**
  +     * A swing action to zoom out the canvas.
  +     */
  +    protected class ZoomOutAction extends ZoomAction {
  +        ZoomOutAction() { super(.5); }
  +    }
   
  -        public ScrollRightAction(int inc) {
  -            this.inc = inc;
  +    /**
  +     * A swing action to Rotate the canvas.
  +     */
  +    protected class RotateAction extends AffineAction {
  +        public RotateAction(double theta) {
  +            super(AffineTransform.getRotateInstance(theta));
           }
  +    }
   
  -        public void actionPerformed(ActionEvent evt) {
  -            if (gvtRoot == null) {
  -                return;
  -            }
  -            AffineTransform at = new AffineTransform(getRenderingTransform());
  -            at.translate(-inc, 0);
  -            setRenderingTransform(at);
  +    /**
  +     * A swing action to Pan/scroll the canvas.
  +     */
  +    protected class ScrollAction extends AffineAction {
  +        public ScrollAction(double tx, double ty) {
  +            super(AffineTransform.getTranslateInstance(tx, ty));
           }
       }
   
       /**
  -     * A swing action to scroll the canvas to the left.
  +     * A swing action to scroll the canvas to the right,
  +     * by a fixed amount
        */
  -    protected class ScrollLeftAction extends AbstractAction {
  -
  -        /** The scroll increment. */
  -        protected int inc;
  -
  -        public ScrollLeftAction(int inc) {
  -            this.inc = inc;
  +    protected class ScrollRightAction extends ScrollAction {
  +        public ScrollRightAction(int inc) {
  +            super(-inc, 0);
           }
  +    }
   
  -        public void actionPerformed(ActionEvent evt) {
  -            if (gvtRoot == null) {
  -                return;
  -            }
  -            AffineTransform at = new AffineTransform(getRenderingTransform());
  -            at.translate(inc, 0);
  -            setRenderingTransform(at);
  +    /**
  +     * A swing action to scroll the canvas to the left,
  +     * by a fixed amount
  +     */
  +    protected class ScrollLeftAction extends ScrollAction {
  +        public ScrollLeftAction(int inc) {
  +            super(inc, 0);
           }
       }
   
       /**
  -     * A swing action to scroll the canvas up.
  +     * A swing action to scroll the canvas up,
  +     * by a fixed amount
        */
  -    protected class ScrollUpAction extends AbstractAction {
  -
  -        /** The scroll increment. */
  -        protected int inc;
  -
  +    protected class ScrollUpAction extends ScrollAction {
           public ScrollUpAction(int inc) {
  -            this.inc = inc;
  -        }
  -
  -        public void actionPerformed(ActionEvent evt) {
  -            if (gvtRoot == null) {
  -                return;
  -            }
  -            AffineTransform at = new AffineTransform(getRenderingTransform());
  -            at.translate(0, inc);
  -            setRenderingTransform(at);
  +            super(0, inc);
           }
       }
   
       /**
  -     * A swing action to scroll the canvas down.
  +     * A swing action to scroll the canvas down,
  +     * by a fixed amount
        */
  -    protected class ScrollDownAction extends AbstractAction {
  -
  -        /** The scroll increment. */
  -        protected int inc;
  -
  +    protected class ScrollDownAction extends ScrollAction {
           public ScrollDownAction(int inc) {
  -            this.inc = inc;
  -        }
  -
  -        public void actionPerformed(ActionEvent evt) {
  -            if (gvtRoot == null) {
  -                return;
  -            }
  -            AffineTransform at = new AffineTransform(getRenderingTransform());
  -            at.translate(0, -inc);
  -            setRenderingTransform(at);
  +            super(0, -inc);
           }
       }
   
  
  
  
  1.70      +22 -19    xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java
  
  Index: JSVGComponent.java
  ===================================================================
  RCS file: /home/cvs/xml-batik/sources/org/apache/batik/swing/svg/JSVGComponent.java,v
  retrieving revision 1.69
  retrieving revision 1.70
  diff -u -r1.69 -r1.70
  --- JSVGComponent.java        11 Jun 2003 22:07:27 -0000      1.69
  +++ JSVGComponent.java        17 Jun 2003 01:37:57 -0000      1.70
  @@ -894,6 +894,21 @@
                "Confirm", JOptionPane.YES_NO_OPTION) == JOptionPane.YES_OPTION;
       }
   
  +
  +    /**
  +     * This method is called when the component knows the desired
  +     * size of the window (based on width/height of outermost SVG
  +     * element).
  +     * The default implementation simply calls setPreferredSize,
  +     * and invalidate.
  +     * However it is often useful to pack the window containing 
  +     * this component.
  +     */
  +    public void setMySize(Dimension d) {
  +        setPreferredSize(d);
  +        invalidate();
  +    }
  +
       /**
        * The JGVTComponentListener.
        */
  @@ -1065,8 +1080,9 @@
               }
   
               Dimension2D dim = bridgeContext.getDocumentSize();
  -            setMySize(new Dimension((int)dim.getWidth(),
  -                                    (int)dim.getHeight()));
  +            Dimension   mySz = new Dimension((int)dim.getWidth(),
  +                                             (int)dim.getHeight());
  +            JSVGComponent.this.setMySize(mySz);
               SVGSVGElement elt = svgDocument.getRootElement();
               Dimension d = getSize();
               prevComponentSize = d;
  @@ -1097,20 +1113,6 @@
               }
           }
   
  -        public void setMySize(Dimension d) {
  -            setPreferredSize(d);
  -            invalidate();
  -            Container p = getParent();
  -            while (p != null) {
  -                if (p instanceof Window) {
  -                    Window w = (Window) p;
  -                    w.pack();
  -                    break;
  -                }
  -                p = p.getParent();
  -            }
  -        }
  -
           /**
            * Called when a build was cancelled.
            */
  @@ -1152,8 +1154,9 @@
                   JSVGComponent.this.image = null;
                   repaint();
               } else {
  -                setMySize(new Dimension((int)dim.getWidth(),
  -                                        (int)dim.getHeight()));
  +                Dimension d= new Dimension((int)dim.getWidth(),
  +                                           (int)dim.getHeight());
  +                JSVGComponent.this.setMySize(d);
                   JSVGComponent.this.setGraphicsNode(gn, false);
                   computeRenderingTransform();
               }
  
  
  

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

Reply via email to