Index: trunk/src/com/kitfox/svg/app/beans/SVGIcon.java
===================================================================
--- trunk/src/com/kitfox/svg/app/beans/SVGIcon.java	(revision 10787)
+++ trunk/src/com/kitfox/svg/app/beans/SVGIcon.java	(revision 11525)
@@ -4,14 +4,14 @@
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms, with or 
+ * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
  * conditions are met:
  *
- *   - Redistributions of source code must retain the above 
+ *   - Redistributions of source code must retain the above
  *     copyright notice, this list of conditions and the following
  *     disclaimer.
  *   - Redistributions in binary form must reproduce the above
  *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials 
+ *     disclaimer in the documentation and/or other materials
  *     provided with the distribution.
  *
@@ -27,6 +27,6 @@
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE. 
- * 
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
  * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
  * projects can be found at http://www.kitfox.com
@@ -37,8 +37,4 @@
 package com.kitfox.svg.app.beans;
 
-import com.kitfox.svg.SVGCache;
-import com.kitfox.svg.SVGDiagram;
-import com.kitfox.svg.SVGException;
-import com.kitfox.svg.SVGUniverse;
 import java.awt.Component;
 import java.awt.Dimension;
@@ -54,6 +50,11 @@
 import java.beans.PropertyChangeSupport;
 import java.net.URI;
+
 import javax.swing.ImageIcon;
 
+import com.kitfox.svg.SVGCache;
+import com.kitfox.svg.SVGDiagram;
+import com.kitfox.svg.SVGException;
+import com.kitfox.svg.SVGUniverse;
 
 /**
@@ -66,18 +67,18 @@
 
     public static final String PROP_AUTOSIZE = "PROP_AUTOSIZE";
-    
+
     private final PropertyChangeSupport changes = new PropertyChangeSupport(this);
-    
+
     SVGUniverse svgUniverse = SVGCache.getSVGUniverse();
     public static final int INTERP_NEAREST_NEIGHBOR = 0;
     public static final int INTERP_BILINEAR = 1;
     public static final int INTERP_BICUBIC = 2;
-    
+
     private boolean antiAlias;
     private int interpolation = INTERP_NEAREST_NEIGHBOR;
     private boolean clipToViewbox;
-    
+
     URI svgURI;
-    
+
 //    private boolean scaleToFit;
     AffineTransform scaleXform = new AffineTransform();
@@ -89,22 +90,23 @@
     public static final int AUTOSIZE_STRETCH = 4;
     private int autosize = AUTOSIZE_NONE;
-    
+
     Dimension preferredSize;
-    
+
     /** Creates a new instance of SVGIcon */
     public SVGIcon()
     {
     }
-    
+
     public void addPropertyChangeListener(PropertyChangeListener p)
     {
         changes.addPropertyChangeListener(p);
     }
-    
+
     public void removePropertyChangeListener(PropertyChangeListener p)
     {
         changes.removePropertyChangeListener(p);
     }
-    
+
+    @Override
     public Image getImage()
     {
@@ -117,13 +119,13 @@
      * @return height of this icon
      */
-    public int getIconHeight()
+    public int getIconHeightIgnoreAutosize()
     {
         if (preferredSize != null &&
-                (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH 
+                (autosize == AUTOSIZE_VERT || autosize == AUTOSIZE_STRETCH
                 || autosize == AUTOSIZE_BESTFIT))
         {
             return preferredSize.height;
         }
-        
+
         SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
         if (diagram == null)
@@ -133,17 +135,17 @@
         return (int)diagram.getHeight();
     }
-    
+
     /**
      * @return width of this icon
      */
-    public int getIconWidth()
+    public int getIconWidthIgnoreAutosize()
     {
         if (preferredSize != null &&
-                (autosize == AUTOSIZE_HORIZ || autosize == AUTOSIZE_STRETCH 
+                (autosize == AUTOSIZE_HORIZ || autosize == AUTOSIZE_STRETCH
                 || autosize == AUTOSIZE_BESTFIT))
         {
             return preferredSize.width;
         }
-        
+
         SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
         if (diagram == null)
@@ -153,5 +155,47 @@
         return (int)diagram.getWidth();
     }
-    
+
+    private boolean isAutoSizeBestFitUseFixedHeight(final int iconWidthIgnoreAutosize, final int iconHeightIgnoreAutosize,
+            final SVGDiagram diagram)
+    {
+        return iconHeightIgnoreAutosize/diagram.getHeight() < iconWidthIgnoreAutosize/diagram.getWidth();
+    }
+
+    @Override
+    public int getIconWidth()
+    {
+        final int iconWidthIgnoreAutosize = getIconWidthIgnoreAutosize();
+        final int iconHeightIgnoreAutosize = getIconHeightIgnoreAutosize();
+        final SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+        if (preferredSize != null && (autosize == AUTOSIZE_VERT ||
+                                     (autosize == AUTOSIZE_BESTFIT && isAutoSizeBestFitUseFixedHeight(iconWidthIgnoreAutosize, iconHeightIgnoreAutosize, diagram))))
+        {
+            final double aspectRatio = diagram.getHeight()/diagram.getWidth();
+            return (int)(iconHeightIgnoreAutosize / aspectRatio);
+        }
+        else
+        {
+            return iconWidthIgnoreAutosize;
+        }
+    }
+
+    @Override
+    public int getIconHeight()
+    {
+        final int iconWidthIgnoreAutosize = getIconWidthIgnoreAutosize();
+        final int iconHeightIgnoreAutosize = getIconHeightIgnoreAutosize();
+        final SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
+        if (preferredSize != null && (autosize == AUTOSIZE_HORIZ ||
+                                      (autosize == AUTOSIZE_BESTFIT && !isAutoSizeBestFitUseFixedHeight(iconWidthIgnoreAutosize, iconHeightIgnoreAutosize, diagram))))
+        {
+            final double aspectRatio = diagram.getHeight()/diagram.getWidth();
+            return (int)(iconWidthIgnoreAutosize * aspectRatio);
+        }
+        else
+        {
+            return iconHeightIgnoreAutosize;
+        }
+    }
+
     /**
      * Draws the icon to the specified component.
@@ -161,17 +205,18 @@
      * @param y - Y coordinate to draw icon
      */
+    @Override
     public void paintIcon(Component comp, Graphics gg, int x, int y)
     {
-        //Copy graphics object so that 
+        //Copy graphics object so that
         Graphics2D g = (Graphics2D)gg.create();
         paintIcon(comp, g, x, y);
         g.dispose();
     }
-    
+
     private void paintIcon(Component comp, Graphics2D g, int x, int y)
     {
         Object oldAliasHint = g.getRenderingHint(RenderingHints.KEY_ANTIALIASING);
         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, antiAlias ? RenderingHints.VALUE_ANTIALIAS_ON : RenderingHints.VALUE_ANTIALIAS_OFF);
-        
+
         Object oldInterpolationHint = g.getRenderingHint(RenderingHints.KEY_INTERPOLATION);
         switch (interpolation)
@@ -187,6 +232,6 @@
                 break;
         }
-        
-        
+
+
         SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
         if (diagram == null)
@@ -194,5 +239,5 @@
             return;
         }
-        
+
         g.translate(x, y);
         diagram.setIgnoringClipHeuristic(!clipToViewbox);
@@ -201,6 +246,6 @@
             g.setClip(new Rectangle2D.Float(0, 0, diagram.getWidth(), diagram.getHeight()));
         }
-        
-        
+
+
         if (autosize == AUTOSIZE_NONE)
         {
@@ -217,15 +262,15 @@
             return;
         }
-        
-        final int width = getIconWidth();
-        final int height = getIconHeight();
+
+        final int width = getIconWidthIgnoreAutosize();
+        final int height = getIconHeightIgnoreAutosize();
 //        int width = getWidth();
 //        int height = getHeight();
-        
+
         if (width == 0 || height == 0)
         {
             return;
         }
-        
+
 //        if (width == 0 || height == 0)
 //        {
@@ -236,20 +281,20 @@
 //            return;
 //        }
-        
+
 //        g.setClip(0, 0, width, height);
-        
-        
+
+
 //        final Rectangle2D.Double rect = new Rectangle2D.Double();
 //        diagram.getViewRect(rect);
-//        
+//
 //        scaleXform.setToScale(width / rect.width, height / rect.height);
         double diaWidth = diagram.getWidth();
         double diaHeight = diagram.getHeight();
-        
+
         double scaleW = 1;
         double scaleH = 1;
         if (autosize == AUTOSIZE_BESTFIT)
         {
-            scaleW = scaleH = (height / diaHeight < width / diaWidth) 
+            scaleW = scaleH = (height / diaHeight < width / diaWidth)
                     ? height / diaHeight : width / diaWidth;
         }
@@ -268,8 +313,8 @@
         }
         scaleXform.setToScale(scaleW, scaleH);
-        
+
         AffineTransform oldXform = g.getTransform();
         g.transform(scaleXform);
-        
+
         try
         {
@@ -280,10 +325,10 @@
             throw new RuntimeException(e);
         }
-        
+
         g.setTransform(oldXform);
-        
-        
+
+
         g.translate(-x, -y);
-        
+
         g.setRenderingHint(RenderingHints.KEY_ANTIALIASING, oldAliasHint);
         if (oldInterpolationHint != null)
@@ -292,5 +337,5 @@
         }
     }
-    
+
     /**
      * @return the universe this icon draws it's SVGDiagrams from
@@ -300,5 +345,5 @@
         return svgUniverse;
     }
-    
+
     public void setSvgUniverse(SVGUniverse svgUniverse)
     {
@@ -307,5 +352,5 @@
         changes.firePropertyChange("svgUniverse", old, svgUniverse);
     }
-    
+
     /**
      * @return the uni of the document being displayed by this icon
@@ -315,5 +360,5 @@
         return svgURI;
     }
-    
+
     /**
      * Loads an SVG document from a URI.
@@ -324,5 +369,5 @@
         URI old = this.svgURI;
         this.svgURI = svgURI;
-        
+
         SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
         if (diagram != null)
@@ -335,8 +380,8 @@
             diagram.setDeviceViewport(new Rectangle(0, 0, size.width, size.height));
         }
-        
+
         changes.firePropertyChange("svgURI", old, svgURI);
     }
-    
+
     /**
      * Loads an SVG document from the classpath.  This function is equivilant to
@@ -347,10 +392,10 @@
     {
         URI old = this.svgURI;
-        
+
         try
         {
             svgURI = new URI(getClass().getResource(resourcePath).toString());
             changes.firePropertyChange("svgURI", old, svgURI);
-            
+
             SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
             if (diagram != null)
@@ -358,5 +403,5 @@
                 diagram.setDeviceViewport(new Rectangle(0, 0, preferredSize.width, preferredSize.height));
             }
-            
+
         }
         catch (Exception e)
@@ -365,28 +410,5 @@
         }
     }
-    
-    /**
-     * If this SVG document has a viewbox, if scaleToFit is set, will scale the viewbox to match the
-     * preferred size of this icon
-     * @deprecated 
-     * @return 
-     */
-    public boolean isScaleToFit()
-    {
-        return autosize == AUTOSIZE_STRETCH;
-    }
-    
-    /**
-     * @deprecated 
-     * @return 
-     */
-    public void setScaleToFit(boolean scaleToFit)
-    {
-        setAutosize(AUTOSIZE_STRETCH);
-//        boolean old = this.scaleToFit;
-//        this.scaleToFit = scaleToFit;
-//        firePropertyChange("scaleToFit", old, scaleToFit);
-    }
-    
+
     public Dimension getPreferredSize()
     {
@@ -400,13 +422,13 @@
             }
         }
-        
+
         return new Dimension(preferredSize);
     }
-    
+
     public void setPreferredSize(Dimension preferredSize)
     {
         Dimension old = this.preferredSize;
         this.preferredSize = preferredSize;
-        
+
         SVGDiagram diagram = svgUniverse.getDiagram(svgURI);
         if (diagram != null)
@@ -414,29 +436,10 @@
             diagram.setDeviceViewport(new Rectangle(0, 0, preferredSize.width, preferredSize.height));
         }
-        
+
         changes.firePropertyChange("preferredSize", old, preferredSize);
     }
-    
-    
+
     /**
      * @return true if antiAliasing is turned on.
-     * @deprecated
-     */
-    public boolean getUseAntiAlias()
-    {
-        return getAntiAlias();
-    }
-    
-    /**
-     * @param antiAlias true to use antiAliasing.
-     * @deprecated
-     */
-    public void setUseAntiAlias(boolean antiAlias)
-    {
-        setAntiAlias(antiAlias);
-    }
-    
-    /**
-     * @return true if antiAliasing is turned on.
      */
     public boolean getAntiAlias()
@@ -444,5 +447,5 @@
         return antiAlias;
     }
-    
+
     /**
      * @param antiAlias true to use antiAliasing.
@@ -454,5 +457,5 @@
         changes.firePropertyChange("antiAlias", old, antiAlias);
     }
-    
+
     /**
      * @return interpolation used in rescaling images
@@ -462,5 +465,5 @@
         return interpolation;
     }
-    
+
     /**
      * @param interpolation Interpolation value used in rescaling images.
@@ -476,5 +479,5 @@
         changes.firePropertyChange("interpolation", old, interpolation);
     }
-    
+
     /**
      * clipToViewbox will set a clip box equivilant to the SVG's viewbox before
@@ -485,5 +488,5 @@
         return clipToViewbox;
     }
-    
+
     public void setClipToViewbox(boolean clipToViewbox)
     {
@@ -508,4 +511,4 @@
         changes.firePropertyChange(PROP_AUTOSIZE, oldAutosize, autosize);
     }
-        
+
 }
Index: trunk/src/com/kitfox/svg/app/data/Handler.java
===================================================================
--- trunk/src/com/kitfox/svg/app/data/Handler.java	(revision 10787)
+++ trunk/src/com/kitfox/svg/app/data/Handler.java	(revision 11525)
@@ -4,14 +4,14 @@
  * All rights reserved.
  *
- * Redistribution and use in source and binary forms, with or 
+ * Redistribution and use in source and binary forms, with or
  * without modification, are permitted provided that the following
  * conditions are met:
  *
- *   - Redistributions of source code must retain the above 
+ *   - Redistributions of source code must retain the above
  *     copyright notice, this list of conditions and the following
  *     disclaimer.
  *   - Redistributions in binary form must reproduce the above
  *     copyright notice, this list of conditions and the following
- *     disclaimer in the documentation and/or other materials 
+ *     disclaimer in the documentation and/or other materials
  *     provided with the distribution.
  *
@@ -27,6 +27,6 @@
  * STRICT LIABILITY, OR TORT (INCLUDING NEGLIGENCE OR OTHERWISE)
  * ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF ADVISED
- * OF THE POSSIBILITY OF SUCH DAMAGE. 
- * 
+ * OF THE POSSIBILITY OF SUCH DAMAGE.
+ *
  * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
  * projects can be found at http://www.kitfox.com
@@ -35,5 +35,4 @@
 package com.kitfox.svg.app.data;
 
-import com.kitfox.svg.SVGConst;
 import java.io.ByteArrayInputStream;
 import java.io.IOException;
@@ -45,4 +44,6 @@
 import java.util.logging.Level;
 import java.util.logging.Logger;
+
+import com.kitfox.svg.SVGConst;
 
 /**
@@ -78,9 +79,11 @@
             }
         }
-        
+
+        @Override
         public void connect() throws IOException
         {
         }
 
+        @Override
         public String getHeaderField(String name)
         {
@@ -93,4 +96,5 @@
         }
 
+        @Override
         public InputStream getInputStream() throws IOException
         {
@@ -104,4 +108,5 @@
     }
 
+    @Override
     protected URLConnection openConnection(URL u) throws IOException
     {
