Index: trunk/src/com/kitfox/svg/Gradient.java
===================================================================
--- trunk/src/com/kitfox/svg/Gradient.java	(revision 4256)
+++ trunk/src/com/kitfox/svg/Gradient.java	(revision 6002)
@@ -1,37 +1,47 @@
 /*
- * Gradient.java
+ * SVG Salamander
+ * Copyright (c) 2004, Mark McKay
+ * All rights reserved.
  *
+ * Redistribution and use in source and binary forms, with or 
+ * without modification, are permitted provided that the following
+ * conditions are met:
  *
- *  The Salamander Project - 2D and 3D graphics libraries in Java
- *  Copyright (C) 2004 Mark McKay
+ *   - 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 
+ *     provided with the distribution.
  *
- *  This library is free software; you can redistribute it and/or
- *  modify it under the terms of the GNU Lesser General Public
- *  License as published by the Free Software Foundation; either
- *  version 2.1 of the License, or (at your option) any later version.
- *
- *  This library is distributed in the hope that it will be useful,
- *  but WITHOUT ANY WARRANTY; without even the implied warranty of
- *  MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
- *  Lesser General Public License for more details.
- *
- *  You should have received a copy of the GNU Lesser General Public
- *  License along with this library; if not, write to the Free Software
- *  Foundation, Inc., 59 Temple Place, Suite 330, Boston, MA 02111-1307 USA
- *
- *  Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
- *  projects can be found at http://www.kitfox.com
+ * THIS SOFTWARE IS PROVIDED BY THE COPYRIGHT HOLDERS AND CONTRIBUTORS
+ * "AS IS" AND ANY EXPRESS OR IMPLIED WARRANTIES, INCLUDING, BUT NOT
+ * LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND FITNESS
+ * FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL THE
+ * COPYRIGHT HOLDER OR CONTRIBUTORS BE LIABLE FOR ANY DIRECT,
+ * INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR CONSEQUENTIAL DAMAGES
+ * (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
+ * SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION)
+ * HOWEVER CAUSED AND ON ANY THEORY OF LIABILITY, WHETHER IN CONTRACT,
+ * 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. 
+ * 
+ * Mark McKay can be contacted at mark@kitfox.com.  Salamander and other
+ * projects can be found at http://www.kitfox.com
  *
  * Created on January 26, 2004, 3:25 AM
  */
-
 package com.kitfox.svg;
 
-import java.net.*;
-import java.util.*;
-import java.awt.geom.*;
-import java.awt.*;
-
-import com.kitfox.svg.xml.*;
+import com.kitfox.svg.xml.StyleAttribute;
+import java.awt.Color;
+import java.awt.geom.AffineTransform;
+import java.net.URI;
+import java.util.ArrayList;
+import java.util.Iterator;
+import java.util.logging.Level;
+import java.util.logging.Logger;
 
 /**
@@ -41,32 +51,35 @@
 abstract public class Gradient extends FillElement
 {
-
+    public static final String TAG_NAME = "gradient";
+    
     public static final int SM_PAD = 0;
     public static final int SM_REPEAT = 1;
     public static final int SM_REFLECT = 2;
-
     int spreadMethod = SM_PAD;
-
     public static final int GU_OBJECT_BOUNDING_BOX = 0;
     public static final int GU_USER_SPACE_ON_USE = 1;
-
     protected int gradientUnits = GU_OBJECT_BOUNDING_BOX;
-
     //Either this gradient contains a list of stops, or it will take it's
     // stops from the referenced gradient
     ArrayList stops = new ArrayList();
     URI stopRef = null;
-//    Gradient stopRef = null;
-
     protected AffineTransform gradientTransform = null;
-
+    
     //Cache arrays of stop values here
     float[] stopFractions;
     Color[] stopColors;
 
-    /** Creates a new instance of Gradient */
-    public Gradient() {
-    }
-    
+    /**
+     * Creates a new instance of Gradient
+     */
+    public Gradient()
+    {
+    }
+
+    public String getTagName()
+    {
+        return TAG_NAME;
+    }
+
     /**
      * Called after the start element but before the end element to indicate
@@ -77,6 +90,9 @@
         super.loaderAddChild(helper, child);
 
-        if (!(child instanceof Stop)) return;
-        appendStop((Stop)child);
+        if (!(child instanceof Stop))
+        {
+            return;
+        }
+        appendStop((Stop) child);
     }
 
@@ -84,14 +100,21 @@
     {
         super.build();
-        
+
         StyleAttribute sty = new StyleAttribute();
         String strn;
-        
+
         if (getPres(sty.setName("spreadMethod")))
         {
             strn = sty.getStringValue().toLowerCase();
-            if (strn.equals("repeat")) spreadMethod = SM_REPEAT;
-            else if (strn.equals("reflect")) spreadMethod = SM_REFLECT;
-            else spreadMethod = SM_PAD;
+            if (strn.equals("repeat"))
+            {
+                spreadMethod = SM_REPEAT;
+            } else if (strn.equals("reflect"))
+            {
+                spreadMethod = SM_REFLECT;
+            } else
+            {
+                spreadMethod = SM_PAD;
+            }
         }
 
@@ -99,23 +122,34 @@
         {
             strn = sty.getStringValue().toLowerCase();
-            if (strn.equals("userspaceonuse")) gradientUnits = GU_USER_SPACE_ON_USE;
-            else gradientUnits = GU_OBJECT_BOUNDING_BOX;
-        }
-
-        if (getPres(sty.setName("gradientTransform"))) gradientTransform = parseTransform(sty.getStringValue());
+            if (strn.equals("userspaceonuse"))
+            {
+                gradientUnits = GU_USER_SPACE_ON_USE;
+            } else
+            {
+                gradientUnits = GU_OBJECT_BOUNDING_BOX;
+            }
+        }
+
+        if (getPres(sty.setName("gradientTransform")))
+        {
+            gradientTransform = parseTransform(sty.getStringValue());
+        }
         //If we still don't have one, set it to identity
-        if (gradientTransform == null) gradientTransform = new AffineTransform();
-
-        
+        if (gradientTransform == null)
+        {
+            gradientTransform = new AffineTransform();
+        }
+
+
         //Check to see if we're using our own stops or referencing someone else's
         if (getPres(sty.setName("xlink:href")))
         {
-            try {
+            try
+            {
                 stopRef = sty.getURIValue(getXMLBase());
 //System.err.println("Gradient: " + sty.getStringValue() + ", " + getXMLBase() + ", " + src);
 //                URI src = getXMLBase().resolve(href);
 //                stopRef = (Gradient)diagram.getUniverse().getElement(src);
-            }
-            catch (Exception e)
+            } catch (Exception e)
             {
                 throw new SVGException("Could not resolve relative URL in Gradient: " + sty.getStringValue() + ", " + getXMLBase(), e);
@@ -123,14 +157,17 @@
         }
     }
-    
+
     public float[] getStopFractions()
     {
         if (stopRef != null)
         {
-            Gradient grad = (Gradient)diagram.getUniverse().getElement(stopRef);
+            Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);
             return grad.getStopFractions();
         }
 
-        if (stopFractions != null) return stopFractions;
+        if (stopFractions != null)
+        {
+            return stopFractions;
+        }
 
         stopFractions = new float[stops.size()];
@@ -138,7 +175,10 @@
         for (Iterator it = stops.iterator(); it.hasNext();)
         {
-            Stop stop = (Stop)it.next();
+            Stop stop = (Stop) it.next();
             float val = stop.offset;
-            if (idx != 0 && val < stopFractions[idx - 1]) val = stopFractions[idx - 1];
+            if (idx != 0 && val < stopFractions[idx - 1])
+            {
+                val = stopFractions[idx - 1];
+            }
             stopFractions[idx++] = val;
         }
@@ -151,9 +191,12 @@
         if (stopRef != null)
         {
-            Gradient grad = (Gradient)diagram.getUniverse().getElement(stopRef);
+            Gradient grad = (Gradient) diagram.getUniverse().getElement(stopRef);
             return grad.getStopColors();
         }
 
-        if (stopColors != null) return stopColors;
+        if (stopColors != null)
+        {
+            return stopColors;
+        }
 
         stopColors = new Color[stops.size()];
@@ -161,7 +204,7 @@
         for (Iterator it = stops.iterator(); it.hasNext();)
         {
-            Stop stop = (Stop)it.next();
+            Stop stop = (Stop) it.next();
             int stopColorVal = stop.color.getRGB();
-            Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int)(stop.opacity * 255), 0, 255));
+            Color stopColor = new Color((stopColorVal >> 16) & 0xff, (stopColorVal >> 8) & 0xff, stopColorVal & 0xff, clamp((int) (stop.opacity * 255), 0, 255));
             stopColors[idx++] = stopColor;
         }
@@ -169,5 +212,5 @@
         return stopColors;
     }
-    
+
     public void setStops(Color[] colors, float[] fractions)
     {
@@ -176,17 +219,23 @@
             throw new IllegalArgumentException();
         }
-        
+
         this.stopColors = colors;
         this.stopFractions = fractions;
         stopRef = null;
     }
-    
+
     private int clamp(int val, int min, int max)
     {
-        if (val < min) return min;
-        if (val > max) return max;
+        if (val < min)
+        {
+            return min;
+        }
+        if (val > max)
+        {
+            return max;
+        }
         return val;
     }
-    
+
     public void setStopRef(URI grad)
     {
@@ -200,6 +249,7 @@
 
     /**
-     * Updates all attributes in this diagram associated with a time event.
-     * Ie, all attributes with track information.
+     * Updates all attributes in this diagram associated with a time event. Ie,
+     * all attributes with track information.
+     *
      * @return - true if this node has changed state as a result of the time
      * update
@@ -214,5 +264,5 @@
         boolean shapeChange = false;
         String strn;
-        
+
 
         if (getPres(sty.setName("spreadMethod")))
@@ -220,7 +270,14 @@
             int newVal;
             strn = sty.getStringValue().toLowerCase();
-            if (strn.equals("repeat")) newVal = SM_REPEAT;
-            else if (strn.equals("reflect")) newVal = SM_REFLECT;
-            else newVal = SM_PAD;
+            if (strn.equals("repeat"))
+            {
+                newVal = SM_REPEAT;
+            } else if (strn.equals("reflect"))
+            {
+                newVal = SM_REFLECT;
+            } else
+            {
+                newVal = SM_PAD;
+            }
             if (spreadMethod != newVal)
             {
@@ -229,11 +286,16 @@
             }
         }
-        
+
         if (getPres(sty.setName("gradientUnits")))
         {
             int newVal;
             strn = sty.getStringValue().toLowerCase();
-            if (strn.equals("userspaceonuse")) newVal = GU_USER_SPACE_ON_USE;
-            else newVal = GU_OBJECT_BOUNDING_BOX;
+            if (strn.equals("userspaceonuse"))
+            {
+                newVal = GU_USER_SPACE_ON_USE;
+            } else
+            {
+                newVal = GU_OBJECT_BOUNDING_BOX;
+            }
             if (newVal != gradientUnits)
             {
@@ -253,9 +315,10 @@
         }
 
-        
+
         //Check to see if we're using our own stops or referencing someone else's
         if (getPres(sty.setName("xlink:href")))
         {
-            try {
+            try
+            {
                 URI newVal = sty.getURIValue(getXMLBase());
                 if ((newVal == null && stopRef != null) || !newVal.equals(stopRef))
@@ -264,15 +327,15 @@
                     stateChange = true;
                 }
-            }
-            catch (Exception e)
-            {
-                e.printStackTrace();
-            }
-        }
-        
+            } catch (Exception e)
+            {
+                Logger.getLogger(SVGConst.SVG_LOGGER).log(Level.WARNING,
+                    "Could not parse xlink:href", e);
+            }
+        }
+
         //Check stops, if any
         for (Iterator it = stops.iterator(); it.hasNext();)
         {
-            Stop stop = (Stop)it.next();
+            Stop stop = (Stop) it.next();
             if (stop.updateTime(curTime))
             {
@@ -282,7 +345,6 @@
             }
         }
-        
+
         return stateChange;
     }
-
 }
