Dear Batik experts,

I am trying to do something with svg's animation features and having the following problem (which is illustrated in the attached program) a ball's color is made to change from red to blue during one second and repeats all over. But I want to stop the color-changing but pressing the button "stop" and also start the color-chaning again by pressing the button "blink" by setting the repeatcount attribute using the following the codes: animateColorE.setAttribute(SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "0");
and
animateColorE.setAttribute(SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "indefinite");
But it just doesn't work...
Could you guys please tell me why or how I can do it right?

thanks very much,
Cui

--------------------------------------------------------------------

package rotationTest;

import java.awt.BorderLayout;
import java.awt.Dimension;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;

import javax.swing.JButton;
import javax.swing.JFrame;
import javax.swing.SwingUtilities;

import org.apache.batik.dom.svg.SVGDOMImplementation;
import org.apache.batik.swing.JSVGCanvas;
import org.apache.batik.util.SVGConstants;
import org.w3c.dom.DOMImplementation;
import org.w3c.dom.Document;
import org.w3c.dom.Element;

public class ColorChangingAndStopping extends JFrame{

   /**
    *
    */
   private static final long serialVersionUID = 1L;

   private JSVGCanvas canvas;
   private Document svgDoc;
   private Element animateColorE;
public ColorChangingAndStopping(){ this.setDefaultCloseOperation(JFrame.EXIT_ON_CLOSE); this.getContentPane().setLayout(new BorderLayout()); this.canvas = new JSVGCanvas();
       this.canvas.setDocumentState (JSVGCanvas.ALWAYS_DYNAMIC);
DOMImplementation dom = SVGDOMImplementation.getDOMImplementation ();
       svgDoc =
dom.createDocument(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_SVG_TAG, null); this.initBall(); this.initStopBtn(); this.canvas.setDocument(svgDoc); this.canvas.setMySize(new Dimension(300, 300)); this.getContentPane().add(this.canvas, "Center"); this.pack();
       this.setVisible(true);
} private void initStopBtn() {
       final JButton centerBtn = new JButton("stop");
       centerBtn.addActionListener(new ActionListener(){
           public void actionPerformed(ActionEvent arg0) {
               if(centerBtn.getText().equals("stop")){
animateColorE.setAttribute(SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "0");
                   centerBtn.setText("blink");
               }
               else{
animateColorE.setAttribute(SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "0"); centerBtn.setText("stop"); }
           }
       });
       this.getContentPane().add(centerBtn, "South");
   }
private void initBall(){ Element ballE = svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_CIRCLE_TAG);
       svgDoc.getDocumentElement().appendChild(ballE);
       ballE.setAttributeNS(null, SVGConstants.SVG_CX_ATTRIBUTE, ""+80);
       ballE.setAttributeNS(null, SVGConstants.SVG_CY_ATTRIBUTE, ""+100);
       ballE.setAttributeNS(null, SVGConstants.SVG_R_ATTRIBUTE, ""+20);
       ballE.setAttributeNS(null, SVGConstants.SVG_FILL_ATTRIBUTE, "red");
animateColorE = svgDoc.createElementNS(SVGConstants.SVG_NAMESPACE_URI, SVGConstants.SVG_ANIMATE_COLOR_TAG); animateColorE.setAttributeNS(null, SVGConstants.SVG_ATTRIBUTE_NAME_ATTRIBUTE, SVGConstants.SVG_FILL_ATTRIBUTE); animateColorE.setAttributeNS(null, SVGConstants.SVG_ATTRIBUTE_TYPE_ATTRIBUTE, "xml"); animateColorE.setAttributeNS(null, SVGConstants.SVG_FROM_ATTRIBUTE, "red"); animateColorE.setAttributeNS(null, SVGConstants.SVG_TO_ATTRIBUTE, "blue"); animateColorE.setAttributeNS(null, SVGConstants.SVG_FILL_ATTRIBUTE, "freeze"); animateColorE.setAttributeNS(null, SVGConstants.SVG_DUR_ATTRIBUTE, "1s"); animateColorE.setAttributeNS(null, SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "indefinite");
       ballE.appendChild(animateColorE);
   }
public static void main(String[] args){
       SwingUtilities.invokeLater(new Runnable() {
           public void run() {
               new ColorChangingAndStopping();
           }
       });
   }
}


---------------------------------------------------------------------
To unsubscribe, e-mail: [email protected]
For additional commands, e-mail: [email protected]

Reply via email to