You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-commits@xmlgraphics.apache.org by dv...@apache.org on 2007/02/25 19:04:47 UTC

svn commit: r511565 - in /xmlgraphics/batik/trunk/sources/org/apache/batik: apps/svgbrowser/ bridge/svg12/ dom/svg/ ext/awt/geom/ svggen/ util/gui/

Author: dvholten
Date: Sun Feb 25 10:04:46 2007
New Revision: 511565

URL: http://svn.apache.org/viewvc?view=rev&rev=511565
Log:
1.) change some str.indexof( "x" )  to str.indexof( 'x' )
2.) use some more predefined color-constants
3.) fix clone() in ExtendedGeneralPath
4.) some minor String-tuning

Modified:
    xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractSVGList.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/SVGColor.java
    xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/LanguageDialog.java

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java?view=diff&rev=511565&r1=511564&r2=511565
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/apps/svgbrowser/JSVGViewerFrame.java Sun Feb 25 10:04:46 2007
@@ -735,7 +735,7 @@
         locationBar.addActionListener(new AbstractAction() {
             public void actionPerformed(ActionEvent e) {
                 String st = locationBar.getText().trim();
-                int i = st.indexOf("#");
+                int i = st.indexOf( '#' );
                 String t = "";
                 if (i != -1) {
                     t = st.substring(i + 1);
@@ -1317,7 +1317,7 @@
             if (uriChooser.showDialog() == URIChooser.OK_OPTION) {
                 String s = uriChooser.getText();
                 if (s == null) return;
-                int i = s.indexOf("#");
+                int i = s.indexOf( '#' );
                 String t = "";
                 if (i != -1) {
                     t = s.substring(i + 1);
@@ -2043,7 +2043,7 @@
      */
     public class PlayAction extends   AbstractAction
                             implements JComponentModifier {
-        java.util.List components = new LinkedList();
+        List components = new LinkedList();
         public PlayAction() {}
         public void actionPerformed(ActionEvent e) {
             svgCanvas.resumeProcessing();
@@ -2067,7 +2067,7 @@
      */
     public class PauseAction extends   AbstractAction
                             implements JComponentModifier {
-        java.util.List components = new LinkedList();
+        List components = new LinkedList();
         public PauseAction() {}
         public void actionPerformed(ActionEvent e) {
             svgCanvas.suspendProcessing();
@@ -2091,7 +2091,7 @@
      */
     public class StopAction extends    AbstractAction
                             implements JComponentModifier {
-        java.util.List components = new LinkedList();
+        List components = new LinkedList();
         public StopAction() {}
         public void actionPerformed(ActionEvent e) {
             svgCanvas.stopProcessing();
@@ -2612,7 +2612,7 @@
                 return;
             }
 
-            if (s.indexOf("#") != -1) {
+            if (s.indexOf( '#' ) != -1) {
                 localHistory.update(s);
                 locationBar.setText(s);
                 if (debugger != null) {

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java?view=diff&rev=511565&r1=511564&r2=511565
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/bridge/svg12/SVGFlowRootElementBridge.java Sun Feb 25 10:04:46 2007
@@ -397,8 +397,8 @@
     protected void dumpACIWord(AttributedString as) {
         if (as == null) return;
 
-        String chars = "";
-        String brkStr = "";
+        StringBuffer chars = new StringBuffer();
+        StringBuffer brkStr = new StringBuffer();
         AttributedCharacterIterator aci = as.getIterator();
         AttributedCharacterIterator.Attribute WORD_LIMIT =
             TextLineBreaks.WORD_LIMIT;
@@ -406,15 +406,17 @@
         for (char ch = aci.current();
              ch!=AttributedCharacterIterator.DONE;
              ch = aci.next()) {
-            chars  += ch + "  ";
-            int w = ((Integer)aci.getAttribute(WORD_LIMIT)).intValue();
-            if (w >=10)
-                brkStr += ""+w+" ";                            // todo tune stringhandling
-            else
-                brkStr += ""+w+"  ";
+
+                chars.append( ch ).append( ' ' ).append( ' ' );
+                int w = ((Integer)aci.getAttribute(WORD_LIMIT)).intValue();
+                brkStr.append( w ).append( ' ' );
+                if (w < 10) {
+                    // for small values append another ' '
+                    brkStr.append( ' ' );
+                }
         }
-        System.out.println(chars);
-        System.out.println(brkStr);
+        System.out.println( chars.toString() );
+        System.out.println( brkStr.toString() );
     }
 
     protected Element getFlowDivElement(Element elem) {

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractSVGList.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractSVGList.java?view=diff&rev=511565&r1=511564&r2=511565
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractSVGList.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/dom/svg/AbstractSVGList.java Sun Feb 25 10:04:46 2007
@@ -457,10 +457,8 @@
      * the list.
      */
     protected void resetAttribute(SVGItem item) {
-        StringBuffer buf = new StringBuffer(getValueAsString());
-        buf.append(getItemSeparator());
-        buf.append(item.getValueAsString());
-        setAttributeValue(buf.toString());
+        String newValue = getValueAsString() + getItemSeparator() + item.getValueAsString();
+        setAttributeValue( newValue );
         valid = true;
     }
 

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java?view=diff&rev=511565&r1=511564&r2=511565
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/ext/awt/geom/ExtendedGeneralPath.java Sun Feb 25 10:04:46 2007
@@ -19,12 +19,14 @@
 package org.apache.batik.ext.awt.geom;
 
 import java.awt.Shape;
+import java.awt.Rectangle;
 import java.awt.geom.AffineTransform;
 import java.awt.geom.Arc2D;
 import java.awt.geom.GeneralPath;
 import java.awt.geom.PathIterator;
 import java.awt.geom.Point2D;
 import java.awt.geom.Rectangle2D;
+import java.util.Arrays;
 
 /**
  * The <code>ExtendedGeneralPath</code> class represents a geometric
@@ -228,13 +230,13 @@
         // Compute the angle start
         n = Math.sqrt((ux * ux) + (uy * uy));
         p = ux; // (1 * ux) + (0 * uy)
-        sign = (uy < 0) ? -1d : 1d;
+        sign = (uy < 0) ? -1.0 : 1.0;
         double angleStart = Math.toDegrees(sign * Math.acos(p / n));
 
         // Compute the angle extent
         n = Math.sqrt((ux * ux + uy * uy) * (vx * vx + vy * vy));
         p = ux * vx + uy * vy;
-        sign = (ux * vy - uy * vx < 0) ? -1d : 1d;
+        sign = (ux * vy - uy * vx < 0) ? -1.0 : 1.0;
         double angleExtent = Math.toDegrees(sign * Math.acos(p / n));
         if(!sweepFlag && angleExtent > 0) {
             angleExtent -= 360f;
@@ -370,9 +372,10 @@
      * Delegates to the enclosed <code>GeneralPath</code>.
      */
     public void append(PathIterator pi, boolean connect) {
+        double [] vals = new double[6];
 
         while (!pi.isDone()) {
-            double [] vals = new double[6];
+            Arrays.fill( vals, 0 );
             int type = pi.currentSegment(vals);
             pi.next();
             if (connect && (numVals != 0)) {
@@ -414,8 +417,9 @@
      * Delegates to the enclosed <code>GeneralPath</code>.
      */
     public void append(ExtendedPathIterator epi, boolean connect) {
+        float[] vals = new float[ 7 ];
         while (!epi.isDone()) {
-            float [] vals = new float[7];
+            Arrays.fill( vals, 0 );
             int type = epi.currentSegment(vals);
             epi.next();
             if (connect && (numVals != 0)) {
@@ -427,7 +431,7 @@
                         // Change MOVETO to LINETO.
                         type = PathIterator.SEG_LINETO;
                     } else {
-                        // Redundent segment (move to current loc) drop it...
+                        // Redundant segment (move to current loc) drop it...
                         if (epi.isDone()) break; // Nothing interesting
                         type = epi.currentSegment(vals);
                         epi.next();
@@ -472,7 +476,7 @@
     }
 
     /**
-     * Delegates to the enclosed <code>GeneralPath</code>.
+     * get the current position or <code>null</code>.
      */
     public synchronized Point2D getCurrentPoint() {
         if (numVals == 0) return null;
@@ -487,6 +491,8 @@
 
         numSeg = 0;
         numVals = 0;
+        values = null;
+        types = null;
     }
 
     /**
@@ -508,7 +514,7 @@
     /**
      * Delegates to the enclosed <code>GeneralPath</code>.
      */
-    public java.awt.Rectangle getBounds() {
+    public synchronized Rectangle getBounds() {
         return path.getBounds();
     }
 
@@ -678,7 +684,7 @@
             int type = types[segNum++];
             switch (type) {
             case SEG_CLOSE: break;
-            case SEG_MOVETO:
+            case SEG_MOVETO:                   // fallthrough is intended
             case SEG_LINETO: valsIdx+=2; break;
             case SEG_QUADTO: valsIdx+=4; break;
             case SEG_CUBICTO:valsIdx+=6; break;
@@ -695,12 +701,16 @@
             ExtendedGeneralPath result = (ExtendedGeneralPath) super.clone();
             result.path = (GeneralPath) path.clone();
 
-            result.values = new float[values.length];
-            System.arraycopy(values, 0, result.values, 0, values.length);
+            if ( values != null ){
+                result.values = new float[values.length];
+                System.arraycopy(values, 0, result.values, 0, values.length);
+            }
             result.numVals = numVals;
 
-            result.types = new int[types.length];
-            System.arraycopy(types, 0, result.types, 0, types.length);
+            if ( types != null ){
+                result.types = new int[types.length];
+                System.arraycopy(types, 0, result.types, 0, types.length);
+            }
             result.numSeg = numSeg;
 
             return result;
@@ -708,6 +718,13 @@
         return null;
     }
 
+    /**
+     * Make sure, that the requested number of slots in vales[] are available.
+     * Must be called even for numValues = 0, because it is also
+     * used for initialization of those arrays.
+     *
+     * @param numValues number of requested coordinates
+     */
     private void makeRoom(int numValues) {
         if (values == null) {
             values = new float[2*numValues];

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/SVGColor.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/SVGColor.java?view=diff&rev=511565&r1=511564&r2=511565
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/SVGColor.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/svggen/SVGColor.java Sun Feb 25 10:04:46 2007
@@ -37,13 +37,13 @@
     /**
      * Predefined CSS colors
      */
-    public static final Color aqua = new Color(0x00, 0xff, 0xff);
+    public static final Color aqua = Color.cyan;
     public static final Color black = Color.black;
     public static final Color blue = Color.blue;
-    public static final Color fuchsia = new Color(0xff, 0x00, 0xff);
-    public static final Color gray = new Color(0x80, 0x80, 0x80);
-    public static final Color green = new Color(0x00, 0x80, 0x00);
-    public static final Color lime = new Color(0x00, 0xff, 0x00);
+    public static final Color fuchsia = Color.magenta;
+    public static final Color gray = Color.gray;
+    public static final Color green = new Color(0x00, 0x80, 0x00); // NOT Color.green!
+    public static final Color lime = Color.green;
     public static final Color maroon = new Color(0x80, 0x00, 0x00);
     public static final Color navy = new Color(0x00, 0x00, 0x80);
     public static final Color olive = new Color(0x80, 0x80, 0x00);

Modified: xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/LanguageDialog.java
URL: http://svn.apache.org/viewvc/xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/LanguageDialog.java?view=diff&rev=511565&r1=511564&r2=511565
==============================================================================
--- xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/LanguageDialog.java (original)
+++ xmlgraphics/batik/trunk/sources/org/apache/batik/util/gui/LanguageDialog.java Sun Feb 25 10:04:46 2007
@@ -152,7 +152,7 @@
      * Returns the action associated with the given string
      * or null on error
      * @param key the key mapped with the action to get
-     * @throws MissingListenerException if the action is not found
+     * @throws MissingListenerException if the action is not found   todo does it throw ?? seems to return null
      */
     public Action getAction(String key) throws MissingListenerException {
         return (Action)listeners.get(key);
@@ -372,7 +372,8 @@
                 result.append(userListModel.getElementAt(0));
 
                 for (int i = 1; i < userListModel.getSize(); i++) {
-                    result.append("," + userListModel.getElementAt(i));
+                    result.append( ',' );
+                    result.append( userListModel.getElementAt(i) );
                 }
             }
             return result.toString();