xmlgraphics-batik-users mailing list archives

Site index · List index
Message view « Date » · « Thread »
Top « Date » · « Thread »
From dao <dao.ho...@gmail.com>
Subject Re: animate an element
Date Mon, 11 Jan 2010 23:22:58 GMT
hello,

The animateElem.getAttributeNS(null, "attributeName"); was empty, you're
true. Actually, I created the anim elements with the "
http://www.w3.org/2000/svg".
It is in fact null... how can I know which element belongs to which
namespace?

But the problem remains: I want to animate the object. I have created the
elements like this:

...

mask.setAttributeNS(null, "opacity", "0");

Element animElement = createOpacityAnimElement(0,0);

animElement.setAttributeNS(null,"id",mask.getAttribute("id")+"anim");

mask.appendChild(animElement);

fillMask(elt, mask, doc);

return mask;

}


 private Element createOpacityAnimElement(float from, float to) {

Element anim = doc.createElementNS(null, "animate");

anim.setAttributeNS(null,"attributeType","CSS");

anim.setAttributeNS(null,"attributeName","opacity");

anim.setAttributeNS(null,"from",Float.toString(from));

anim.setAttributeNS(null,"to",Float.toString(to));

anim.setAttributeNS(null,"dur","1");

anim.setAttributeNS(null,"repeatCount","1");

return anim;

}

The SVG looks like that:
<g id="meter21WarningMask" opacity="1">
<animate dur="1" from="0" to="1" repeatCount="1" attributeName="opacity"
id="meter21WarningMaskanim" attributeType="CSS"/>
<use x="-150.529" y="-141.521" transform="matrix(0.6131 0 0 -0.6131 516.4451
288.623)" width="301.06" xmlns:xlink="http://www.w3.org/1999/xlink"
xlink:href="widgets.svg#warningMask" xlink:type="simple"
xlink:actuate="onLoad" height="283.044" xlink:show="embed"/>
</g>

But when I do this

public void setVisible(final Element elt, boolean b) {

final Element mask = elt2mask.get(elt);

if (mask == null)

return;

Element anim = (Element) mask.getElementsByTagNameNS(null, "animate"
).item(0);

String animId = anim.getAttribute("id");

if (b) {

SvgRepaintEngine.getInstance().push(newAttributeUpdateTask(mask.getAttribute(
"id"),"opacity", "1"));

SvgRepaintEngine.getInstance().push(new AttributeUpdateTask(animId, "from",
"0"));

SvgRepaintEngine.getInstance().push(new AttributeUpdateTask(animId, "to",
"1"));

} else {

SvgRepaintEngine.getInstance().push(newAttributeUpdateTask(mask.getAttribute(
"id"),"opacity", "0"));

SvgRepaintEngine.getInstance().push(new AttributeUpdateTask(animId, "from",
"1"));

SvgRepaintEngine.getInstance().push(new AttributeUpdateTask(animId, "to",
"0"));

}


the animation does not perform, and the opacity changes immediately (I tried
to remove the first change)

Note that the SvgRepaintEngine only calls the invokeLater of the update
manager to make a setAttribute

On Sat, Jan 9, 2010 at 2:58 PM, <thomas.deweese@kodak.com> wrote:

> Hi Dao,
>
> dao <dao.hodac@gmail.com> wrote on 01/06/2010 09:17:33 AM:
>
>
> > hello, I am running into a problem while attempting to animate an object.
> >
> > I create an animation object using batik and I add this to my
> > ALWAYS_DYNAMIC canvas. The dump of the XML is like that after the append:
>
>     What do you get if you call:
>         String an = animateElem.getAttributeNS(null, "attributeName");
>
>     I see that in your 'dump' it looks OK, but the dump can easly not
> represent the details of the DOM in memory.
>
>     Can you post the code you use to create the animate element?
>
> > I get this exception. What's wrong with me?
>
> > org.apache.batik.bridge.BridgeException: file:/C:/Users/to81028/
> > runtime-EclipseApplication/aet/image/toto.svg:0
> > The attribute "" of the element <g> is not animatable
> >     at
>
>    This means that in the animation bridge the getAttributeNS call
> above is returning either null or "" (not entirely sure which).
> Are you perhaps appending the element before setting all of it's
> attributes?
>
> > org.apache.batik.bridge.SVGAnimationElementBridge.initializeAnimation
> > (SVGAnimationElementBridge.java:213)
> >     at
> > org.apache.batik.bridge.SVGAnimationElementBridge.handleElement
> > (SVGAnimationElementBridge.java:154)
> >     at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode
> > (GVTBuilder.java:198)
> >     at
> org.apache.batik.bridge.GVTBuilder.buildComposite(GVTBuilder.java:171)
> >     at org.apache.batik.bridge.GVTBuilder.buildGraphicsNode
> > (GVTBuilder.java:219)
> > ...
> >
> > --
> > Dao Hodac
>



-- 
Dao Hodac

Mime
View raw message