You are viewing a plain text version of this content. The canonical link for it is here.
Posted to batik-users@xmlgraphics.apache.org by Age Bosma <ag...@gmail.com> on 2009/01/07 15:19:10 UTC

Creating two elements referencing each other by ID

Hi,

Here was I thinking I was doing fine using Batik with just one
question so far yesterday, now I ran into a different issue again
already.

What I'm basically trying to achieve is the following:

---------------------------------------------------------------------------------------
<rect x="20" y="20" width="250" height="250"
style="opacity:0;fill:blue" id="rect_highlight">
    <animate attributeType="CSS" attributeName="opacity" from="0"
to="1" begin="0s;fade_out.end" dur="3s" id="fade_in"/>
    <animate attributeType="CSS" attributeName="opacity" from="1"
to="0" begin="fade_in.end" dur="3s" id="fade_out"/>
</rect>
---------------------------------------------------------------------------------------

Where the rect constantly fades in and out. Loading the document like
this in Batik results in no problems, it works as expected.

There are, however, two things that need to be done different:
1. The animation need to start at on an event
2. The animation elements need to be added by means of Java.

Removing the '0s' from the fade_in element's begin attribute and using
the following takes case of the first thing (as in: it works):

---------------------------------------------------------------------------------------
SVGAnimateElement fadeInAnimation = (SVGAnimateElement)
svgDoc.getElementById("fade_in");
fadeInAnimation.beginElement();
---------------------------------------------------------------------------------------

Settings the values of both begin attributes is what's causing
problems. Setting the value (the id of the second element) in the
first element's attribute while the second one isn't added yet results
in a NullPointerException.
Trying to deal with this issue in the following way:

---------------------------------------------------------------------------------------
Element rectHighlight = svgDoc.getElementById("rect_highlight");

SVGAnimateElement fadeInAnimation = (SVGAnimateElement)
svgDoc.createElementNS(svgNS, "animate");
fadeInAnimation.setAttributeNS(null, "attributeType", "CSS");
fadeInAnimation.setAttributeNS(null, "attributeName", "opacity");
fadeInAnimation.setAttributeNS(null, "from", "0");
fadeInAnimation.setAttributeNS(null, "to", "1");
fadeInAnimation.setAttributeNS(null, "dur", "3s");
fadeInAnimation.setAttributeNS(null, "id", "fade_in");

rectHighlight.appendChild(fadeInAnimation);

Element fadeOutAnimation = svgDoc.createElementNS(svgNS, "animate");
fadeOutAnimation.setAttributeNS(null, "attributeType", "CSS");
fadeOutAnimation.setAttributeNS(null, "attributeName", "opacity");
fadeOutAnimation.setAttributeNS(null, "from", "0");
fadeOutAnimation.setAttributeNS(null, "to", "1");
fadeOutAnimation.setAttributeNS(null, "begin", "fade_in.end");
fadeOutAnimation.setAttributeNS(null, "dur", "3s");
fadeOutAnimation.setAttributeNS(null, "id", "fade_out");

rectHighlight.appendChild(fadeOutAnimation);
fadeInAnimation.setAttributeNS(null, "begin", "fade_out.end");

fadeInAnimation.beginElement();
---------------------------------------------------------------------------------------

This results in the rect fading in and out only once.
Settings both begin attributes after both elements have been appended
results in the animation to fade in once with the rect disappearing as
soon as the fade in animation finishes.
Retrieving the animation elements over again
(getElementById("fade_in"), etc.), just in case, just before settings
the begin attribute makes no difference.

What is the proper way to deal with the NullPointerException when
you're trying to add an element referencing another element which
isn't present yet? Or is there a way without depening on the addition
order as much as above?
Why does the animation only run once when using the above example? I
get the feeling that the begin attributes aren't properly set (or at
all) but why?

Yours,

Age Bosma

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Creating two elements referencing each other by ID

Posted by Helder Magalhães <he...@gmail.com>.
> Now the NPE occurs as soon as you start the animation with
> beginElement() :

I tried to find a related know issue in the bug tracker [1] but wasn't
able to find anything. If no one else adds up new information in about
a couple of days, I'd invite you to create a reduced test case and
create a new issue to make sure this doesn't get lost. A link to this
thread may be sufficient, although it would be much better if this
could be reproduced using a single file (manipulating the document
using ECMAScript, for example), easing reproducibility. ;-)

Regards,
 Helder


[1] https://issues.apache.org/bugzilla/buglist.cgi?query_format=specific&bug_status=__open__&product=Batik

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Creating two elements referencing each other by ID

Posted by Age Bosma <ag...@gmail.com>.
In additional to the previous reply:
When I set the begin attribute of the first to be added element to
'indefinite' first and chaging this value to the id of the second
element after it's added does not result in a NPE at first as it would
without setting the first element's begin attribute to 'indefinite'.
Now the NPE occurs as soon as you start the animation with
beginElement() :

-----------------------------------------------------------------------------
java.lang.NullPointerException
  at org.apache.batik.anim.timing.TimedElement.addInstanceTime(Unknown Source)
  at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.newInterval(Unknown
Source)
  at org.apache.batik.anim.timing.TimedElement.notifyNewInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.selectNewInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.sampleAt(Unknown Source)
  at org.apache.batik.anim.timing.TimedDocumentRoot.seekTo(Unknown Source)
  at org.apache.batik.anim.AnimationEngine.tick(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationEngine.access$600(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationEngine$AnimationTickRunnable.run(Unknown
Source)
  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:619)
-----------------------------------------------------------------------------

2009/1/13 Age Bosma <ag...@gmail.com>:
> 2009/1/12 Helder Magalhães <he...@gmail.com>:
>>> I still haven't found a solution. Does no one have any idea?
>>
>> I believe this was caused by a bug in version 1.7 (you didn't include
>> the Batik version used!) which is already fixed in current development
>
> Indeed, my bad, I should have included those details.
> I used 1.7 with JDK 1.6u7.
>
>> version [1]. I've tested with Batik 1.8 revision 733683, JDK 1.6u11 in
>> Windows XP SP3 and no NullPointerException was thrown. Visual result
>
> I now tested it with the 2009-01-04 source available for download but
> the problem remains or even got worse. This should be rev731265, not
> sure where you got a later version from.
> I still get a NullPointerException as soon as I try to add the begin
> attribute containing an id of an element which isn't present yet.
>
> ---------------------------------------------------------------------------------------
> java.lang.NullPointerException
>  at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.<init>(Unknown Source)
>  at org.apache.batik.anim.timing.TimingSpecifierListProducer.syncbase(Unknown
> Source)
>  at org.apache.batik.parser.TimingSpecifierParser.handleTimingSpecifier(Unknown
> Source)
>  at org.apache.batik.parser.TimingSpecifierListParser.doParse(Unknown Source)
>  at org.apache.batik.parser.AbstractParser.parse(Unknown Source)
>  at org.apache.batik.anim.timing.TimingSpecifierListProducer.parseTimingSpecifierList(Unknown
> Source)
>  at org.apache.batik.anim.timing.TimedElement.parseBegin(Unknown Source)
>  at org.apache.batik.anim.timing.TimedElement.parseAttributes(Unknown Source)
>  at org.apache.batik.bridge.SVGAnimationElementBridge.initializeTimedElement(Unknown
> Source)
>  at org.apache.batik.bridge.SVGAnimationElementBridge.initializeTimedElement(Unknown
> Source)
>  at org.apache.batik.bridge.SVGAnimationElementBridge.handleElement(Unknown
> Source)
>  at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
>  at org.apache.batik.bridge.SVGGElementBridge.handleElementAdded(Unknown
> Source)
>  at org.apache.batik.bridge.SVGGElementBridge.handleDOMNodeInsertedEvent(Unknown
> Source)
>  at org.apache.batik.bridge.BridgeContext$DOMNodeInsertedEventListener.handleEvent(Unknown
> Source)
>  at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown Source)
>  at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown Source)
>  at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
>  at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
>  at org.apache.batik.dom.AbstractParentNode.fireDOMNodeInsertedEvent(Unknown
> Source)
>  at org.apache.batik.dom.AbstractParentNode.appendChild(Unknown Source)
>  at mpsf.MPSFView$10.run(MPSFView.java:486)
>  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
>  at java.lang.Thread.run(Thread.java:619)
> ---------------------------------------------------------------------------------------
>
> Now with the never Batik version I also get a NullPointerException
> when I try to set the begin attribute of the first element after I
> added the second:
>
> ---------------------------------------------------------------------------------------
> java.lang.NullPointerException
>  at org.apache.batik.anim.timing.TimedElement.addInstanceTime(Unknown Source)
>  at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.newInterval(Unknown
> Source)
>  at org.apache.batik.anim.timing.TimedElement.notifyNewInterval(Unknown Source)
>  at org.apache.batik.anim.timing.TimedElement.selectNewInterval(Unknown Source)
>  at org.apache.batik.anim.timing.TimedElement.sampleAt(Unknown Source)
>  at org.apache.batik.anim.timing.TimedDocumentRoot.seekTo(Unknown Source)
>  at org.apache.batik.anim.AnimationEngine.tick(Unknown Source)
>  at org.apache.batik.bridge.SVGAnimationEngine.access$600(Unknown Source)
>  at org.apache.batik.bridge.SVGAnimationEngine$AnimationTickRunnable.run(Unknown
> Source)
>
>  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
>  at java.lang.Thread.run(Thread.java:619)
> ---------------------------------------------------------------------------------------
>
>> was compared with the one obtained using Opera 10.0a. I'm also
>> attaching the test case, which was incomplete (missing the surrounding
>> "svg" element).
>>
>
> I didn't include the tags in the example since it was just for
> illustrating the situation I'm trying to achieve.
>

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Creating two elements referencing each other by ID

Posted by Age Bosma <ag...@gmail.com>.
2009/1/12 Helder Magalhães <he...@gmail.com>:
>> I still haven't found a solution. Does no one have any idea?
>
> I believe this was caused by a bug in version 1.7 (you didn't include
> the Batik version used!) which is already fixed in current development

Indeed, my bad, I should have included those details.
I used 1.7 with JDK 1.6u7.

> version [1]. I've tested with Batik 1.8 revision 733683, JDK 1.6u11 in
> Windows XP SP3 and no NullPointerException was thrown. Visual result

I now tested it with the 2009-01-04 source available for download but
the problem remains or even got worse. This should be rev731265, not
sure where you got a later version from.
I still get a NullPointerException as soon as I try to add the begin
attribute containing an id of an element which isn't present yet.

---------------------------------------------------------------------------------------
java.lang.NullPointerException
  at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.<init>(Unknown Source)
  at org.apache.batik.anim.timing.TimingSpecifierListProducer.syncbase(Unknown
Source)
  at org.apache.batik.parser.TimingSpecifierParser.handleTimingSpecifier(Unknown
Source)
  at org.apache.batik.parser.TimingSpecifierListParser.doParse(Unknown Source)
  at org.apache.batik.parser.AbstractParser.parse(Unknown Source)
  at org.apache.batik.anim.timing.TimingSpecifierListProducer.parseTimingSpecifierList(Unknown
Source)
  at org.apache.batik.anim.timing.TimedElement.parseBegin(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.parseAttributes(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationElementBridge.initializeTimedElement(Unknown
Source)
  at org.apache.batik.bridge.SVGAnimationElementBridge.initializeTimedElement(Unknown
Source)
  at org.apache.batik.bridge.SVGAnimationElementBridge.handleElement(Unknown
Source)
  at org.apache.batik.bridge.GVTBuilder.build(Unknown Source)
  at org.apache.batik.bridge.SVGGElementBridge.handleElementAdded(Unknown
Source)
  at org.apache.batik.bridge.SVGGElementBridge.handleDOMNodeInsertedEvent(Unknown
Source)
  at org.apache.batik.bridge.BridgeContext$DOMNodeInsertedEventListener.handleEvent(Unknown
Source)
  at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown Source)
  at org.apache.batik.dom.events.EventSupport.fireEventListeners(Unknown Source)
  at org.apache.batik.dom.events.EventSupport.dispatchEvent(Unknown Source)
  at org.apache.batik.dom.AbstractNode.dispatchEvent(Unknown Source)
  at org.apache.batik.dom.AbstractParentNode.fireDOMNodeInsertedEvent(Unknown
Source)
  at org.apache.batik.dom.AbstractParentNode.appendChild(Unknown Source)
  at mpsf.MPSFView$10.run(MPSFView.java:486)
  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:619)
---------------------------------------------------------------------------------------

Now with the never Batik version I also get a NullPointerException
when I try to set the begin attribute of the first element after I
added the second:

---------------------------------------------------------------------------------------
java.lang.NullPointerException
  at org.apache.batik.anim.timing.TimedElement.addInstanceTime(Unknown Source)
  at org.apache.batik.anim.timing.SyncbaseTimingSpecifier.newInterval(Unknown
Source)
  at org.apache.batik.anim.timing.TimedElement.notifyNewInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.selectNewInterval(Unknown Source)
  at org.apache.batik.anim.timing.TimedElement.sampleAt(Unknown Source)
  at org.apache.batik.anim.timing.TimedDocumentRoot.seekTo(Unknown Source)
  at org.apache.batik.anim.AnimationEngine.tick(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationEngine.access$600(Unknown Source)
  at org.apache.batik.bridge.SVGAnimationEngine$AnimationTickRunnable.run(Unknown
Source)

  at org.apache.batik.util.RunnableQueue.run(Unknown Source)
  at java.lang.Thread.run(Thread.java:619)
---------------------------------------------------------------------------------------

> was compared with the one obtained using Opera 10.0a. I'm also
> attaching the test case, which was incomplete (missing the surrounding
> "svg" element).
>

I didn't include the tags in the example since it was just for
illustrating the situation I'm trying to achieve.

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org


Re: Creating two elements referencing each other by ID

Posted by Helder Magalhães <he...@gmail.com>.
> I still haven't found a solution. Does no one have any idea?

I believe this was caused by a bug in version 1.7 (you didn't include
the Batik version used!) which is already fixed in current development
version [1]. I've tested with Batik 1.8 revision 733683, JDK 1.6u11 in
Windows XP SP3 and no NullPointerException was thrown. Visual result
was compared with the one obtained using Opera 10.0a. I'm also
attaching the test case, which was incomplete (missing the surrounding
"svg" element).

Hope this helps,
 Helder Magalhães

[1] http://xmlgraphics.apache.org/batik/download.cgi#Subversion+repository

Re: Creating two elements referencing each other by ID

Posted by Age Bosma <ag...@gmail.com>.
Age Bosma wrote:

> 
> What is the proper way to deal with the NullPointerException when
> you're trying to add an element referencing another element which
> isn't present yet? Or is there a way without depening on the addition
> order as much as above?
> Why does the animation only run once when using the above example? I
> get the feeling that the begin attributes aren't properly set (or at
> all) but why?
> 

I still haven't found a solution. Does no one have any idea?

Age

---------------------------------------------------------------------
To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org