deweese     01/10/17 05:33:00

  Modified:    samples/extensions solidColor.svg
               sources/org/apache/batik/extension/svg
                        BatikBridgeExtension.java BatikDomExtension.java
                        BatikExtConstants.java
  Added:       samples/extensions colorSwitch.svg
               sources/org/apache/batik/extension/svg
                        ColorSwitchBridge.java ColorSwitchElement.java
  Log:
  1) Improved the solidColor test a bit
  2) Added a ColorSwitch element which is a Paint Server which
     selects which child element to use based on switch like parameters.
  
  Revision  Changes    Path
  1.2       +22 -8     xml-batik/samples/extensions/solidColor.svg
  
  Index: solidColor.svg
  ===================================================================
  RCS file: /home/cvs/xml-batik/samples/extensions/solidColor.svg,v
  retrieving revision 1.1
  retrieving revision 1.2
  diff -u -r1.1 -r1.2
  --- solidColor.svg    2001/10/16 23:25:31     1.1
  +++ solidColor.svg    2001/10/17 12:33:00     1.2
  @@ -14,7 +14,7 @@
   <!-- regularPoly extension tag test                                         -->
   <!--                                                                        -->
   <!-- @author [EMAIL PROTECTED]                                       -->
  -<!-- @version $Id: solidColor.svg,v 1.1 2001/10/16 23:25:31 deweese Exp $ -->
  +<!-- @version $Id: solidColor.svg,v 1.2 2001/10/17 12:33:00 deweese Exp $ -->
   <!-- ====================================================================== -->
   
   <?xml-stylesheet type="text/css" href="extension.css" ?>
  @@ -33,7 +33,19 @@
           <text x="225" y="40" class="title">
               Solid Color Paint Server
           </text>
  +
  +        <path d="M25,135 c50,-50 50,50 100,0 c50,-50 50,50 100,0 
  +                 c50,-50 50,50 100,0c50,-50 50,50 100,0" 
  +              fill="none" stroke="black" stroke-width="10"/> 
  +  
  +        <path d="M25,275 c50,-50 50,50 100,0 c50,-50 50,50 100,0 
  +                 c50,-50 50,50 100,0c50,-50 50,50 100,0" 
  +              fill="none" stroke="black" stroke-width="10"/> 
     
  +        <path d="M25,415 c50,-50 50,50 100,0 c50,-50 50,50 100,0 
  +                 c50,-50 50,50 100,0c50,-50 50,50 100,0" 
  +              fill="none" stroke="black" stroke-width="10"/> 
  +  
           <switch>
             <g requiredExtensions="http://xml.apache.org/batik/ext/solidColor/1.0";
                fill="#0D0" stroke="#88F" stroke-width="2">
  @@ -45,16 +57,18 @@
               <circle fill="url(#SolidPurple)"   cx="85"  cy="135" r="50"/>
               <circle fill="url(#TransPurple)"   cx="225" cy="135" r="50"/>
               <circle fill="url(#orange)"        cx="365" cy="135" r="50"/>
  -                                            
  -            <circle stroke="url(#SolidPurple)" cx="85"  cy="275" r="50"/>
  -            <circle stroke="url(#TransPurple)" cx="225" cy="275" r="50"/>
  -            <circle stroke="url(#orange)"      cx="365" cy="275" r="50"/>
  +
  +            <g stroke-width="5" fill="none">
  +                <circle stroke="url(#SolidPurple)" cx="85"  cy="275" r="50"/>
  +                <circle stroke="url(#TransPurple)" cx="225" cy="275" r="50"/>
  +                <circle stroke="url(#orange)"      cx="365" cy="275" r="50"/>
  +            </g>
   
  -            <circle fill="url(#SolidPurple)"  opacity="0.5" 
  +            <circle fill="url(#SolidPurple)"  fill-opacity="0.5" 
                       cx="85"  cy="415" r="50"/>
  -            <circle fill="url(#TransPurple)"  opacity="0.5" 
  +            <circle fill="url(#TransPurple)"  fill-opacity="0.5" 
                       cx="225" cy="415" r="50"/>
  -            <circle fill="url(#orange)"       opacity="0.5" 
  +            <circle fill="url(#orange)"       fill-opacity="0.5" 
                       cx="365" cy="415" r="50"/>
             </g>
            
  
  
  
  1.1                  xml-batik/samples/extensions/colorSwitch.svg
  
  Index: colorSwitch.svg
  ===================================================================
  <?xml version="1.0" standalone="no"?>
  <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
  "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd";>
  
  <!-- ====================================================================== -->
  <!-- Copyright (C) The Apache Software Foundation. All rights reserved.     -->
  <!--                                                                        -->
  <!-- This software is published under the terms of the Apache Software      -->
  <!-- License version 1.1, a copy of which has been included with this       -->
  <!-- distribution in  the LICENSE file.                                     -->
  <!-- ====================================================================== -->
  
  <!-- ====================================================================== -->
  <!-- regularPoly extension tag test                                         -->
  <!--                                                                        -->
  <!-- @author [EMAIL PROTECTED]                                       -->
  <!-- @version $Id: colorSwitch.svg,v 1.1 2001/10/17 12:33:00 deweese Exp $ -->
  <!-- ====================================================================== -->
  
  <?xml-stylesheet type="text/css" href="extension.css" ?>
  
  <svg id="body" width="450" height="500" xml:space="preserve" 
       viewBox="0 0 450 500"
       xmlns:svg="http://www.w3.org/2000/svg";
       xmlns:batik="http://xml.apache.org/batik/ext";>
  
      <title>Star Extension Tag</title>
    
      <!-- ============================================================= -->
      <!-- Test content                                                  -->
      <!-- ============================================================= -->
      <g id="testContent" class="legend" style="text-anchor:middle">
          <text x="225" y="40" class="title">
              Color Switch Paint Server
          </text>
    
          <path d="M25,135 c50,-50 50,50 100,0 c50,-50 50,50 100,0 
                   c50,-50 50,50 100,0c50,-50 50,50 100,0" 
                fill="none" stroke="black" stroke-width="10"/> 
    
          <path d="M25,275 c50,-50 50,50 100,0 c50,-50 50,50 100,0 
                   c50,-50 50,50 100,0c50,-50 50,50 100,0" 
                fill="none" stroke="black" stroke-width="10"/> 
    
          <path d="M25,415 c50,-50 50,50 100,0 c50,-50 50,50 100,0 
                   c50,-50 50,50 100,0c50,-50 50,50 100,0" 
                fill="none" stroke="black" stroke-width="10"/> 
    
          <switch>
            <g requiredExtensions="http://xml.apache.org/batik/ext/colorSwitch/1.0";
               fill="#0D0" stroke="#88F" stroke-width="2">
  
              <batik:colorSwitch id="TransPurple">
                  <batik:solidColor color="red" 
                         requiredExtensions="NonExistantExtension"/>
                  <batik:solidColor color="#FF00FF" opacity=".5"
                         
requiredExtensions="http://xml.apache.org/batik/ext/solidColor/1.0"/>
                  <linearGradient>
                      <stop offset="0" stop-color="#FF0000" stop-opacity="0.5"/>
                  </linearGradient>
              </batik:colorSwitch>
  
              <batik:colorSwitch id="SolidPurple">
                  <batik:solidColor color="#FF00FF" 
                         
requiredExtensions="http://xml.apache.org/batik/ext/solidColor/1.0"/>
                  <linearGradient>
                      <stop offset="0" stop-color="#FFFF00" />
                  </linearGradient>
              </batik:colorSwitch>
  
              <batik:colorSwitch id="orange">
                  <batik:solidColor color="orange" opacity="1"
                         requiredExtensions="NonExistantExtension" />
                  <linearGradient y2="100%">
                      <stop offset=".1" stop-color="crimson" />
                      <stop offset=".5" stop-color="gold" stop-opacity="0.5"/>
                      <stop offset=".9" stop-color="crimson" />
                  </linearGradient>
              </batik:colorSwitch>
  
  
              <circle fill="url(#SolidPurple)"   cx="85"  cy="135" r="50"/>
              <circle fill="url(#TransPurple)"   cx="225" cy="135" r="50"/>
              <circle fill="url(#orange)"        cx="365" cy="135" r="50"/>
                                              
              <g stroke-width="5" fill="none">
                  <circle stroke="url(#SolidPurple)" cx="85"  cy="275" r="50"/>
                  <circle stroke="url(#TransPurple)" cx="225" cy="275" r="50"/>
                  <circle stroke="url(#orange)"      cx="365" cy="275" r="50"/>
              </g>
  
              <circle fill="url(#SolidPurple)"  fill-opacity="0.5" 
                      cx="85"  cy="415" r="50"/>
              <circle fill="url(#TransPurple)"  fill-opacity="0.5" 
                      cx="225" cy="415" r="50"/>
              <circle fill="url(#orange)"       fill-opacity="0.5" 
                      cx="365" cy="415" r="50"/>
            </g>
           
            <g fill="red">
              <circle cx="85"  cy="135" r="50"/>
              <circle cx="225" cy="135" r="50"/>
              <circle cx="365" cy="135" r="50"/>
                                              
              <circle cx="85"  cy="275" r="50"/>
              <circle cx="225" cy="275" r="50"/>
              <circle cx="365" cy="275" r="50"/>
        
              <circle cx="85"  cy="415" r="50"/>
              <circle cx="225" cy="415" r="50"/>
              <circle cx="365" cy="415" r="50"/>
            </g>
          </switch>
      </g>
  
      <!-- ============================================================= -->
      <!-- Batik sample mark                                             -->
      <!-- ============================================================= -->
      <use xlink:href="../batikLogo.svg#Batik_Tag_Box" />
  </svg>
  
  
  
  1.4       +2 -0      
xml-batik/sources/org/apache/batik/extension/svg/BatikBridgeExtension.java
  
  Index: BatikBridgeExtension.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikBridgeExtension.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BatikBridgeExtension.java 2001/10/16 23:25:31     1.3
  +++ BatikBridgeExtension.java 2001/10/17 12:33:00     1.4
  @@ -41,6 +41,7 @@
               "http://xml.apache.org/batik/ext/star/1.0"; ,
               "http://xml.apache.org/batik/ext/histogramNormalization/1.0"; ,
               "http://xml.apache.org/batik/ext/solidColor/1.0"; ,
  +            "http://xml.apache.org/batik/ext/colorSwitch/1.0"; ,
           };
           Vector v = new Vector(extensions.length);
           for (int i=0; i<extensions.length; i++) {
  @@ -94,5 +95,6 @@
           ctx.putBridge(new BatikStarElementBridge());
           ctx.putBridge(new BatikHistogramNormalizationElementBridge());
           ctx.putBridge(new SolidColorBridge());
  +        ctx.putBridge(new ColorSwitchBridge());
       }
   }
  
  
  
  1.5       +19 -1     
xml-batik/sources/org/apache/batik/extension/svg/BatikDomExtension.java
  
  Index: BatikDomExtension.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikDomExtension.java,v
  retrieving revision 1.4
  retrieving revision 1.5
  diff -u -r1.4 -r1.5
  --- BatikDomExtension.java    2001/10/16 23:25:31     1.4
  +++ BatikDomExtension.java    2001/10/17 12:33:00     1.5
  @@ -91,6 +91,11 @@
               (BATIK_EXT_NAMESPACE_URI,
                BATIK_EXT_SOLID_COLOR_TAG,
                new SolidColorElementFactory());
  +
  +        di.registerCustomElementFactory
  +            (BATIK_EXT_NAMESPACE_URI,
  +             BATIK_EXT_COLOR_SWITCH_TAG,
  +             new ColorSwitchElementFactory());
       }
   
       /**
  @@ -144,7 +149,6 @@
       protected static class SolidColorElementFactory 
           implements SVGDOMImplementation.ElementFactory {
           public SolidColorElementFactory() {
  -            System.out.println("FActory created");
           }
           /**
            * Creates an instance of the associated element type.
  @@ -154,5 +158,19 @@
           }
       }
   
  +    /**
  +     * To create a 'solidColor' element.
  +     */
  +    protected static class ColorSwitchElementFactory 
  +        implements SVGDOMImplementation.ElementFactory {
  +        public ColorSwitchElementFactory() {
  +        }
  +        /**
  +         * Creates an instance of the associated element type.
  +         */
  +        public Element create(String prefix, Document doc) {
  +            return new ColorSwitchElement(prefix, (AbstractDocument)doc);
  +        }
  +    }
   
   }
  
  
  
  1.4       +4 -0      
xml-batik/sources/org/apache/batik/extension/svg/BatikExtConstants.java
  
  Index: BatikExtConstants.java
  ===================================================================
  RCS file: 
/home/cvs/xml-batik/sources/org/apache/batik/extension/svg/BatikExtConstants.java,v
  retrieving revision 1.3
  retrieving revision 1.4
  diff -u -r1.3 -r1.4
  --- BatikExtConstants.java    2001/10/16 23:25:31     1.3
  +++ BatikExtConstants.java    2001/10/17 12:33:00     1.4
  @@ -27,6 +27,10 @@
       public static final String BATIK_EXT_SOLID_COLOR_TAG = 
           "solidColor";
   
  +    /** Tag name for Batik's regular poly extension. */
  +    public static final String BATIK_EXT_COLOR_SWITCH_TAG = 
  +        "colorSwitch";
  +
       /** Tag name for Batik's star extension. */
       public static final String BATIK_EXT_HISTOGRAM_NORMALIZATION_TAG =
           "histogramNormalization";
  
  
  
  1.1                  
xml-batik/sources/org/apache/batik/extension/svg/ColorSwitchBridge.java
  
  Index: ColorSwitchBridge.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.extension.svg;
  
  import java.awt.Color;
  import java.awt.Paint;
  
  import org.apache.batik.bridge.BridgeContext;
  import org.apache.batik.bridge.AbstractSVGBridge;
  import org.apache.batik.bridge.PaintBridge;
  import org.apache.batik.bridge.SVGUtilities;
  import org.apache.batik.bridge.Bridge;
  import org.apache.batik.gvt.GraphicsNode;
  
  import org.w3c.dom.Element;
  import org.w3c.dom.Node;
  import org.w3c.dom.svg.SVGTests;
  
  /**
   * Bridge class for a regular polygon element.
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas Deweese</a>
   */
  public class ColorSwitchBridge 
      extends AbstractSVGBridge
      implements PaintBridge, BatikExtConstants {
  
      /**
       * Constructs a new bridge for the &lt;rect> element.
       */
      public ColorSwitchBridge() { /* nothing */ }
  
      /**
       * Returns the SVG namespace URI.
       */
      public String getNamespaceURI() {
          return BATIK_EXT_NAMESPACE_URI;
      }
  
      /**
       * Returns 'rect'.
       */
      public String getLocalName() {
          return BATIK_EXT_COLOR_SWITCH_TAG;
      }
  
      /**
       * Creates a <tt>Paint</tt> according to the specified parameters.
       *
       * @param ctx the bridge context to use
       * @param paintElement the element that defines a Paint
       * @param paintedElement the element referencing the paint
       * @param paintedNode the graphics node on which the Paint will be applied
       * @param opacity the opacity of the Paint to create
       */
      public Paint createPaint(BridgeContext ctx,
                               Element paintElement,
                               Element paintedElement,
                               GraphicsNode paintedNode,
                               float opacity) {
          Element clrDef = null;
          for (Node n = paintElement.getFirstChild(); 
               n != null; 
               n = n.getNextSibling()) {
              if ((n.getNodeType() != Node.ELEMENT_NODE))
                  continue;
              Element ref = (Element)n;
              if ( // (ref instanceof SVGTests) &&
                  SVGUtilities.matchUserAgent(ref, ctx.getUserAgent())) {
                  clrDef = ref;
                  break;
              }
          }
  
          if (clrDef == null)
              return Color.black;
  
          Bridge bridge = ctx.getBridge(clrDef);
          if (bridge == null || !(bridge instanceof PaintBridge))
              return Color.black;
  
          return ((PaintBridge)bridge).createPaint(ctx, clrDef, 
                                                   paintedElement,
                                                   paintedNode,
                                                   opacity);
      }
  }
  
  
  
  1.1                  
xml-batik/sources/org/apache/batik/extension/svg/ColorSwitchElement.java
  
  Index: ColorSwitchElement.java
  ===================================================================
  /*****************************************************************************
   * Copyright (C) The Apache Software Foundation. All rights reserved.        *
   * ------------------------------------------------------------------------- *
   * This software is published under the terms of the Apache Software License *
   * version 1.1, a copy of which has been included with this distribution in  *
   * the LICENSE file.                                                         *
   *****************************************************************************/
  
  package org.apache.batik.extension.svg;
  
  import org.w3c.dom.Node;
  
  import org.apache.batik.dom.AbstractDocument;
  import org.apache.batik.extension.PrefixableStylableExtensionElement;
  
  /**
   * This class implements a regular polygon extension to SVG
   *
   * @author <a href="mailto:[EMAIL PROTECTED]";>Thomas DeWeese</a>
   * @version $Id: ColorSwitchElement.java,v 1.1 2001/10/17 12:33:00 deweese Exp $
   */
  public class ColorSwitchElement
      extends    PrefixableStylableExtensionElement 
      implements BatikExtConstants {
  
      /**
       * Creates a new BatikRegularPolygonElement object.
       */
      protected ColorSwitchElement() {
      }
  
      /**
       * Creates a new BatikRegularPolygonElement object.
       * @param prefix The namespace prefix.
       * @param owner The owner document.
       */
      public ColorSwitchElement(String prefix, AbstractDocument owner) {
          super(prefix, owner);
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getLocalName()}.
       */
      public String getLocalName() {
          return BATIK_EXT_COLOR_SWITCH_TAG;
      }
  
      /**
       * <b>DOM</b>: Implements {@link org.w3c.dom.Node#getNamespaceURI()}.
       */
      public String getNamespaceURI() {
          return BATIK_EXT_NAMESPACE_URI;
      }
  
      /**
       * Returns a new uninitialized instance of this object's class.
       */
      protected Node newNode() {
          return new ColorSwitchElement();
      }
  }
  
  
  

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

Reply via email to