Hi Fabian,

  It is usually a case of getting the correct attributes.  Batik tends to
follow the standard a bit more closely that some other implementations.  The
following code works for me...posted sans the JFrame init...assumes a class
member JSVGCanvas named svgCanvas.

    private void runDemo() {
        svgCanvas.setDocumentState(JSVGCanvas.ALWAYS_DYNAMIC);
        svgCanvas.addGVTTreeBuilderListener(new GVTTreeBuilderAdapter() {
            @Override
            public void gvtBuildCompleted(GVTTreeBuilderEvent e) {

svgCanvas.getUpdateManager().getUpdateRunnableQueue().invokeLater(new
Runnable() {
                    public void run() {
                        Element rect =
svgCanvas.getSVGDocument().createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
SVGConstants.SVG_RECT_TAG);
                        rect.setAttributeNS(null,
SVGConstants.SVG_X_ATTRIBUTE, "100");
                        rect.setAttributeNS(null,
SVGConstants.SVG_Y_ATTRIBUTE, "100");
                        rect.setAttributeNS(null,
SVGConstants.SVG_WIDTH_ATTRIBUTE, "100");
                        rect.setAttributeNS(null,
SVGConstants.SVG_HEIGHT_ATTRIBUTE, "100");
                        rect.setAttributeNS(null,
SVGConstants.SVG_FILL_ATTRIBUTE, "#2222ee");
                        Element animate =
svgCanvas.getSVGDocument().createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
SVGConstants.SVG_ANIMATE_TAG);
                        animate.setAttributeNS(null,
SVGConstants.SVG_ATTRIBUTE_NAME_ATTRIBUTE,
SVGConstants.SVG_OPACITY_ATTRIBUTE);
                        animate.setAttributeNS(null,
SVGConstants.SVG_VALUES_ATTRIBUTE, "1;0");
                        animate.setAttributeNS(null,
SVGConstants.SVG_DUR_ATTRIBUTE, "3s");
                        animate.setAttributeNS(null,
SVGConstants.SVG_REPEAT_COUNT_ATTRIBUTE, "indefinite");
                        rect.appendChild(animate);

svgCanvas.getSVGDocument().getDocumentElement().appendChild(rect);
                    }
                });
            }
        });
        Document doc =
SVGDOMImplementation.getDOMImplementation().createDocument(SVGDOMImplementation.SVG_NAMESPACE_URI,
"svg", null);
        svgCanvas.setSVGDocument((SVGDocument) doc);
    }





On Fri, Mar 12, 2010 at 8:35 AM, Fabian Unfried <i...@funfried.de> wrote:

> Hi,
>
> I would like to know how to handle animations with batik, especially the
> animate tag.
>
> If I put the following svg code into an svg graphic and open it with a java
> application with batik all works just fine and it'll be animated:
>
> <rect x="100" y="100" width="500" height="500">
>        <animate attributeType="CSS" attributeName="opacity"
> calcMode="discrete"
> from="1" to="0" dur="1s" repeatCount="indefinite" />
> </rect>
>
>
> But what do I have to do, if I want to do exactly this during runtime?
>
> I've tried this:
>
>
> SVGOMAnimationElement animate = (SVGOMAnimationElement)
> this.svgDocument.createElementNS(SVGDOMImplementation.SVG_NAMESPACE_URI,
> SVG12Constants.SVG_ANIMATE_TAG);
> animate.setAttribute("dur", "1s");
> animate.setAttribute("values", "0; 0; 1; 1");
> animate.setAttribute("keyTimes", "0; 0.5; 0.7; 1.0");
> animate.setAttribute("attributeName", "opacity");
> animate.setAttribute("attributeType", "CSS");
> animate.setAttribute("repeatCount", "indefinite");
>
> rect.appendChild(animate);
>
> animate.beginElement();
>
>
> but this didn't get animated, so I've tried to use the SVGAnimationEngine,
> but
> I'm not sure how to use the addAnimation() method, or even if I need to do
> that:
>
> SVGAnimationEngine aEngine = getSVGAnimationEngine();
> aEngine.addAnimation((AnimationTarget) rect,
> SVGAnimationEngine.ANIM_TYPE_CSS, "?", "?", AbstractAnimation???);
>
> How can I setup an AbstractAnimation?
>
>
>
> Any help is very appreciated
>
> Thanks in advance.
>
> Kind regards,
>
> Fabian
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscr...@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-h...@xmlgraphics.apache.org
>
>

Reply via email to