Hi Fabian,

  Note that although the Elements in the example are created at the
beginning of the example, the listener code block runs after the document is
loaded (after theGVTTreeBuilderEvent is fired).


On Mon, Mar 15, 2010 at 5:45 AM, Fabian Unfried <i...@funfried.de> wrote:

> Hi Jonathan,
>
> first of all thanks for your reply, but if you create the elements (rect
> and
> animate) and then create the document and load it, it should be the same if
> you already drawn the elements in a svg file and open it.
>
> Maybe I didn't mention that exactly, my problem is that I have already
> opened
> a svg file in my application and then would like to add an animation, but
> if
> I do this like in your example, it won't be animated.
>
>
> Kind Regards,
>
>
> Fabian
>
> > 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<mailto: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<mailto:
> batik-users-unsubscr...@xmlgraphics.apache.org>
> > For additional commands, e-mail:
> batik-users-h...@xmlgraphics.apache.org<mailto:
> batik-users-h...@xmlgraphics.apache.org>
> >
> >
> >
>
>
>
> ---------------------------------------------------------------------
> 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