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 maria teresa <ma...@isti.cnr.it> on 2003/12/09 11:32:59 UTC

JSVGCanvas updating problem

Hi,
I am having a problem using Batik and I hope you can help me
solve it.
I have two svg files stored in a certain directory in my
hard disk; one of them is a background image, while the other
contains all the drawings that two different users dynamically
add to the background.
In my application I use a JFrame containing a JSVGCanvas,
a FileChooser to load the svg background and two buttons,
  each one of which should load onto the background the drawings
of the corresponding user.
In order to extract the drawings of a single user, I parse the drawings file
and extract only the nodes of interest by means of a node iterator and
  a custom filter. Each node extracted is appended to the DOM tree of
the background.
This actually works!
I mean, the svg doc I obtain is exactly how I expected, but it is not
rendered correctly: the canvas displays only the background.

Any suggestion is really appreciated!
Thank you,
maria teresa.

PS:
Here is an excerpt from my code:
  			//f is the background svg file
			//svgCan the JSVGCanvas
			
			Document svgDoc = parser.parse(f.toURL().toString());
			svgCan.setDocument(svgDoc); // cosi'becco Xray "pulito"
			
			svgCan.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
			
			//creating the node iterator:
			DocumentTraversal trav = (DocumentTraversal)doc;
			NodeIterator ni = trav.createNodeIterator(
			doc,
			NodeFilter.SHOW_ELEMENT,
			new FilterId(),//my custom filter
			true);	
			
			Element docRoot = svgDoc.getDocumentElement();
      		//iterate over the elements
			Node node;
			while((node = ni.nextNode()) != null){
					//adding all the filtered nodes to the background
			    System.out.println(node.getNodeValue());
				Node importedNode = svgDoc.importNode(node, true);
                 docRoot.appendChild(importedNode);
                 }

			svgCan.setDocument(svgDoc);	//why this does not work?
	        


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


Re: JSVGCanvas updating problem

Posted by Thomas DeWeese <Th...@Kodak.com>.
Maria Teresa Paratore wrote:

> Then, I used the 'getNamespaceURI()' method as you suggested:
> 
>                      Element docRoot = svgDoc.getDocumentElement();      
> //svgDoc is the 'user svg'
>                      System.out.println(svgDoc.getNamespaceURI()); 
> //this returns 'null'

    I would really have liked to see what docRoot returned but
I suspect that will also return 'null'.

> My question is: the 'user' svg document is correctly
> loaded and displayed by Squiggle... It seems to be a "real" svg:
> It looks like this:
> 
> <!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
>     "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" >
> <svg height="387" width="475" 
> xmlns:xlink="http://www.w3.org/1999/xlink">&gt;

     So this does not explicitly set the default namespace to the svg
namespace. When Batik thinks it is loading an SVG file it sets the
default namespace to SVG (unless the document explicitly sets the
default namespace).  This is not the normal behavior of an XML
parser.  So at this point it becomes an issue of how you are loading
the user documents.

     The way the canvas creates the document is with the
SAXSVGDocumentFactory - this is a document factory that knows it
is supposed to produce an SVG document (it also knows about the
SVG DTD's and takes a few shortcuts there unless validating).
The tricky bit is that the SVG DTD should set the default namespace
on the 'svg' element - but once again it may be a matter of how
the document is being loaded.

     A quick thing to check is adding 
xmlns="http://www.w3.org/2000/svg" to the svg element.

> Sorry, I'm not exactly an XML guru...am I missing anything?
> Thank you in advance.
> 
> Maria Teresa
> 
> 
> 
> At 06:15 AM 12/9/2003 -0500, you wrote:
> 
>> Hi Maria,
>>
>> maria teresa wrote:
>>
>>> I am having a problem using Batik and I hope you can help me
>>> solve it.
>>> I have two svg files stored in a certain directory in my
>>> hard disk; one of them is a background image, while the other
>>> contains all the drawings that two different users dynamically
>>> add to the background.
>>
>>   [...]
>>
>>> In order to extract the drawings of a single user, I parse the 
>>> drawings file and extract only the nodes of interest by means of a 
>>> node iterator and
>>>  a custom filter. Each node extracted is appended to the DOM tree of
>>> the background.
>>> This actually works!
>>
>>
>>> I mean, the svg doc I obtain is exactly how I expected, but it is not
>>> rendered correctly: the canvas displays only the background.
>>
>>
>>    I would suspect that the nodes you are getting from
>> the 'overlay' drawing are not in the SVG namespace.  It is
>> also possible that the coordinate systems do not line up.
>>
>>    You can find out what namespace the elements from the
>> 'user' document are in with 'getNamespaceURI()'.
>>
>>    Also a few other points,
>>
>>         1) Calling setDocument twice in close succession
>>            has only worked relyably very recently.
>>         2) calling setDocumentState should be done before
>>            setting the document to have effect.
>>         3) Modifications of the 'currently displayed' document
>>            should only be done in the updateManager's runnable
>>            queue.
>>
>>     So you might try just commenting out the first 'setDocument' call,
>> this way you can avoid all the above issues.
>>
>>> Any suggestion is really appreciated!
>>> Thank you,
>>> maria teresa.
>>> PS:
>>> Here is an excerpt from my code:
>>>              //f is the background svg file
>>>             //svgCan the JSVGCanvas
>>>
>>>             Document svgDoc = parser.parse(f.toURL().toString());
>>>             svgCan.setDocument(svgDoc); // cosi'becco Xray "pulito"
>>>
>>>             svgCan.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
>>>
>>>             //creating the node iterator:
>>>             DocumentTraversal trav = (DocumentTraversal)doc;
>>>             NodeIterator ni = trav.createNodeIterator(
>>>             doc,
>>>             NodeFilter.SHOW_ELEMENT,
>>>             new FilterId(),//my custom filter
>>>             true);
>>>
>>>             Element docRoot = svgDoc.getDocumentElement();
>>>              //iterate over the elements
>>>             Node node;
>>>             while((node = ni.nextNode()) != null){
>>>                     //adding all the filtered nodes to the background
>>>                 System.out.println(node.getNodeValue());
>>>                 Node importedNode = svgDoc.importNode(node, true);
>>>                 docRoot.appendChild(importedNode);
>>>                 }
>>>             svgCan.setDocument(svgDoc);    //why this does not work?
>>>
>>> ---------------------------------------------------------------------
>>> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>> For additional commands, e-mail: batik-users-help@xml.apache.org
>>
>>
>>
>>
>>
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>> For additional commands, e-mail: batik-users-help@xml.apache.org
> 
> 
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org




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


Re: JSVGCanvas updating problem

Posted by Maria Teresa Paratore <ma...@isti.cnr.it>.
Hi Thomas,
thank you for your advice.
I tried to comment the first 'setDocument' out, but it didn't work.

Then, I used the 'getNamespaceURI()' method as you suggested:

                      Element docRoot = 
svgDoc.getDocumentElement();      //svgDoc is the 'user svg'
                      System.out.println(svgDoc.getNamespaceURI()); 
//this returns 'null'

and it returned "null".
My question is: the 'user' svg document is correctly
loaded and displayed by Squiggle... It seems to be a "real" svg:
It looks like this:

<!DOCTYPE svg PUBLIC "-//W3C//DTD SVG 1.0//EN"
     "http://www.w3.org/TR/2001/REC-SVG-20010904/DTD/svg10.dtd" >
<svg height="387" width="475" xmlns:xlink="http://www.w3.org/1999/xlink">&gt;
     <g id="xray">
         <image height="387" width="475" x="0" xlink:href="xray.jpg" y="0"/>
     </g>
     <g id="CommentNode_Tom">
         <rect ............./>
         <text ......./>
     </g>
     <g id="CommentNode_Tom">
         <rect ............./>
         <text ......./>
     </g>
</svg>

Sorry, I'm not exactly an XML guru...am I missing anything?
Thank you in advance.

Maria Teresa



At 06:15 AM 12/9/2003 -0500, you wrote:
>Hi Maria,
>
>maria teresa wrote:
>
>>I am having a problem using Batik and I hope you can help me
>>solve it.
>>I have two svg files stored in a certain directory in my
>>hard disk; one of them is a background image, while the other
>>contains all the drawings that two different users dynamically
>>add to the background.
>   [...]
>>In order to extract the drawings of a single user, I parse the drawings 
>>file and extract only the nodes of interest by means of a node iterator and
>>  a custom filter. Each node extracted is appended to the DOM tree of
>>the background.
>>This actually works!
>
>>I mean, the svg doc I obtain is exactly how I expected, but it is not
>>rendered correctly: the canvas displays only the background.
>
>    I would suspect that the nodes you are getting from
>the 'overlay' drawing are not in the SVG namespace.  It is
>also possible that the coordinate systems do not line up.
>
>    You can find out what namespace the elements from the
>'user' document are in with 'getNamespaceURI()'.
>
>    Also a few other points,
>
>         1) Calling setDocument twice in close succession
>            has only worked relyably very recently.
>         2) calling setDocumentState should be done before
>            setting the document to have effect.
>         3) Modifications of the 'currently displayed' document
>            should only be done in the updateManager's runnable
>            queue.
>
>     So you might try just commenting out the first 'setDocument' call,
>this way you can avoid all the above issues.
>
>>Any suggestion is really appreciated!
>>Thank you,
>>maria teresa.
>>PS:
>>Here is an excerpt from my code:
>>              //f is the background svg file
>>             //svgCan the JSVGCanvas
>>
>>             Document svgDoc = parser.parse(f.toURL().toString());
>>             svgCan.setDocument(svgDoc); // cosi'becco Xray "pulito"
>>
>>             svgCan.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
>>
>>             //creating the node iterator:
>>             DocumentTraversal trav = (DocumentTraversal)doc;
>>             NodeIterator ni = trav.createNodeIterator(
>>             doc,
>>             NodeFilter.SHOW_ELEMENT,
>>             new FilterId(),//my custom filter
>>             true);
>>
>>             Element docRoot = svgDoc.getDocumentElement();
>>              //iterate over the elements
>>             Node node;
>>             while((node = ni.nextNode()) != null){
>>                     //adding all the filtered nodes to the background
>>                 System.out.println(node.getNodeValue());
>>                 Node importedNode = svgDoc.importNode(node, true);
>>                 docRoot.appendChild(importedNode);
>>                 }
>>             svgCan.setDocument(svgDoc);    //why this does not work?
>>
>>---------------------------------------------------------------------
>>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>>For additional commands, e-mail: batik-users-help@xml.apache.org
>
>
>
>
>---------------------------------------------------------------------
>To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
>For additional commands, e-mail: batik-users-help@xml.apache.org



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


Re: JSVGCanvas updating problem

Posted by Thomas DeWeese <Th...@Kodak.com>.
Hi Maria,

maria teresa wrote:

> I am having a problem using Batik and I hope you can help me
> solve it.
> I have two svg files stored in a certain directory in my
> hard disk; one of them is a background image, while the other
> contains all the drawings that two different users dynamically
> add to the background.
   [...]
> In order to extract the drawings of a single user, I parse the drawings 
> file and extract only the nodes of interest by means of a node iterator and
>  a custom filter. Each node extracted is appended to the DOM tree of
> the background.
> This actually works!

> I mean, the svg doc I obtain is exactly how I expected, but it is not
> rendered correctly: the canvas displays only the background.

    I would suspect that the nodes you are getting from
the 'overlay' drawing are not in the SVG namespace.  It is
also possible that the coordinate systems do not line up.

    You can find out what namespace the elements from the
'user' document are in with 'getNamespaceURI()'.

    Also a few other points,

	1) Calling setDocument twice in close succession
	   has only worked relyably very recently.
	2) calling setDocumentState should be done before
	   setting the document to have effect.
         3) Modifications of the 'currently displayed' document
	   should only be done in the updateManager's runnable
	   queue.

     So you might try just commenting out the first 'setDocument' call,
this way you can avoid all the above issues.

> Any suggestion is really appreciated!
> Thank you,
> maria teresa.
> 
> PS:
> Here is an excerpt from my code:
>              //f is the background svg file
>             //svgCan the JSVGCanvas
>            
>             Document svgDoc = parser.parse(f.toURL().toString());
>             svgCan.setDocument(svgDoc); // cosi'becco Xray "pulito"
>            
>             svgCan.setDocumentState(JSVGComponent.ALWAYS_DYNAMIC);
>            
>             //creating the node iterator:
>             DocumentTraversal trav = (DocumentTraversal)doc;
>             NodeIterator ni = trav.createNodeIterator(
>             doc,
>             NodeFilter.SHOW_ELEMENT,
>             new FilterId(),//my custom filter
>             true);   
>            
>             Element docRoot = svgDoc.getDocumentElement();
>              //iterate over the elements
>             Node node;
>             while((node = ni.nextNode()) != null){
>                     //adding all the filtered nodes to the background
>                 System.out.println(node.getNodeValue());
>                 Node importedNode = svgDoc.importNode(node, true);
>                 docRoot.appendChild(importedNode);
>                 }
> 
>             svgCan.setDocument(svgDoc);    //why this does not work?
>            
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org
> For additional commands, e-mail: batik-users-help@xml.apache.org
> 




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