Never mind. Been sitting with this problem for two days, but of course I
only discover the problem a few minutes after asking the people here...
 
The problem was caused by calling:
canvas.getSVGDocument().importNode((Node)tc.getTarget().element, true);
This seems to clone the entire tree (once again), causing me to insert a
third clone on the canvas, but then referencing the second clone in all
the other code. Since the second clone wasn't on the canvas, it of
course had no AffineTransform.
 
The fun thing about programming: Nobody has to punish the ignorant
programmer. Ignorance seems to be punished automatically  :)

-----Original Message-----
From: Henric Rosvall [mailto:[EMAIL PROTECTED] 
Sent: den 11 juni 2007 16:20
To: batik-users@xmlgraphics.apache.org
Subject: getAffineTransform -> NullPointerException


Hi !
 
I'm trying to implement copy/cut and paste in my application that uses a
subclassed JSVGCanvas as a canvas.
 
So when the user tells the app to copy the selected objects (I have code
that makes objects selectable, and modifyable in a multitude of ways), I
take the selected elements, and clone them along with all the data about
them (to ensure that leter modifications to the Element doesn't modify
the copied elements).
 
Then when the user selects paste, I clone it all once again (to be able
to paste multiple times), and insert the clone-of-the-clone.
 
The new object is drawn like it should, and everything looks like it
worked - until I try to select the object. This triggers a call to
Element.getTransformToElement(Element), which returns an
SVGLocatableSupport-element, just like it should. But when trying to do
any Matrix-transformations on the SVGLocatableSupport-object, I get a
NullPointerException indicating that the AffineTransform of the Element
is null:
 
java.lang.NullPointerException
 at
org.apache.batik.dom.svg.SVGLocatableSupport$4.getAffineTransform(Unknow
n Source)
 at org.apache.batik.dom.svg.AbstractSVGMatrix.inverse(Unknown Source)
 at printit.svg.JSvgCanvasEnh.drawSelection(JSvgCanvasEnh.java:1146)
 at
printit.controls.toolbars.ToolEventHandler$SelectTool.OnMouseDown(ToolEv
entHandler.java:201)
 at
printit.controls.toolbars.ToolEventHandler$MoveTool.OnMouseDown(ToolEven
tHandler.java:340)
 at
printit.svg.JSvgCanvasEnh$OnMouseDownAction.handleEvent(JSvgCanvasEnh.ja
va:4345)
 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.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(U
nknown Source)
 at
org.apache.batik.bridge.BridgeEventSupport$Listener.dispatchMouseEvent(U
nknown Source)
 at
org.apache.batik.bridge.BridgeEventSupport$Listener.mousePressed(Unknown
Source)
 at
org.apache.batik.gvt.event.AWTEventDispatcher.processMouseEvent(Unknown
Source)
 at
org.apache.batik.gvt.event.AWTEventDispatcher.dispatchMouseEvent(Unknown
Source)
 at org.apache.batik.gvt.event.AWTEventDispatcher.dispatchEvent(Unknown
Source)
 at org.apache.batik.gvt.event.AWTEventDispatcher.mousePressed(Unknown
Source)
 at org.apache.batik.swing.svg.JSVGComponent$18.run(Unknown Source)
 at org.apache.batik.util.RunnableQueue.run(Unknown Source)
 at java.lang.Thread.run(Unknown Source)
 
Any idea what might be causing this?
I use Element.cloneNode(true);  to clone the original Element
I've checked so that every object in the chain of things that should get
cloned, is really cloned. There are no references left pointing to
anything but cloned objects.
The clones are inserted in much the same way as the original objects,
with basically identical code. Only difference is that the original
objects getAffineTransform works, but the cloned ones don't.
 
Regards
Henric Rosvall

Reply via email to