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 vyang <vy...@apt-cafm.com> on 2007/02/22 19:44:14 UTC

xlink:href problem??

Hello,

I'm having a problem with my canvas displaying an image of a broken picture. 
I create a document in memory and link the svg into the document(which is
done in the constructor).  I then have a method whichs add/removes the
<text> element from the document and resets the canvas document.  After a
few calls of this method my canvas display a broken image picture.  My
coding is as follows:

Constructor:
        impl = SVGDOMImplementation.getDOMImplementation();
        svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
        doc = impl.createDocument(svgNS, "svg", null);
        svgRoot = doc.getDocumentElement();
        groupElement = doc.createElementNS(svgNS, "g");
        svgRoot.appendChild(groupElement);

        loadIconDisplay();



loadIconDisplay:
        Element iconElement = doc.createElementNS(svgNS, "image");
        iconElement.setAttributeNS(null,  "id", "icon");
        iconElement.setAttributeNS(null, "width", Double.toString(275));
        iconElement.setAttributeNS(null,  "height", Double.toString(275));
        iconElement.setAttributeNS(null, "x", Double.toString(x));
        iconElement.setAttributeNS(null, "y", Double.toString(y));
        iconElement.setAttributeNS(xlinkNS, "xlink:href",
iconLibrary.getIconURL());
        groupElement.appendChild(iconElement);
        
        jSVGCanvasIconDisplay.setDocument(doc);



insertIconText:
        if (stringIconText != null) {
            Element tempIconText = doc.getElementById("icontext");
            
            //removes old icon text
            if (tempIconText != null) {
                groupElement.removeChild(tempIconText);
            }
            
            Element iconText = doc.createElementNS(svgNS, "text");
            iconText.setAttributeNS(null, "id", "icontext");
            iconText.setAttributeNS(null, "x", Double.toString(x));
            iconText.setAttributeNS(null, "y", Double.toString(y));
            iconText.setTextContent(stringIconText);
            groupElement.appendChild(iconText);
            
            jSVGCanvasIconDisplay.setDocument(doc);
         }


Any hints/help is much appreciated.
-- 
View this message in context: http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9105802
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: xlink:href problem??

Posted by th...@kodak.com.
Hi Vyang,

vyang <vy...@apt-cafm.com> wrote on 02/26/2007 10:48:23 AM:

> Thanks thomas that worked.  Now I have a question.  I've tried early to 
put
> my statement inside runnablequeue but gives me a nullpointerexception(i
> think).  That is when I didn't set my document state.  So then is
> runnablequeue only available when the document state is set to dynamic?

   Correct the RunnableQueue is only available when the canvas is in
Dynamic document mode.  Also the RunnableQueue is only available after
the first rendering of the GVT tree so you should register a listener
on the canvas for GVT render events and get the runnableQueue instance
after the first one.

> 
> vyang
> 
> 
> thomas.deweese wrote:
> > 
> > Hi Vyang,
> > 
> > vyang <vy...@apt-cafm.com> wrote on 02/23/2007 03:58:58 PM:
> > 
> >> I meant its an image of a svg file on server.  I added your line of 
code 
> > to
> >> my constructor and it doesn't seem to work.  It is coded as follows:
> > 
> >    I suspect the problem is that you are modifying the document while
> > Batik is trying to build the rendering tree.  There are a number
> > of ways to avoid this problem.  Probably the simplest is to 
> > clone the entire tree into a new document before giving it to
> > the Canvas to display.
> > 
> >    The best way would be to change the way you are doing everything
> > and make your Document a dynamic SVG document.  This would allow you
> > to modify the document and have the Canvas automatically update the
> > display.  For this to work however you need to make all your changes
> > to the document in the update manager's RunnableQueue.  You can 
> > look at the Batik FAQ for information on how to run thing in
> > the RunnableQueue.
> > 
> >>         impl = SVGDOMImplementation.getDOMImplementation();
> >>         svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
> >>         xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
> >> 
> >>         doc = impl.createDocument(svgNS, "svg", null);
> >>         SVGOMDocument omDocument = (SVGOMDocument) doc;
> >>         try {
> >>             omDocument.setURLObject(new 
> > File("c:/icontemp.svg").toURL());
> >>         } catch (MalformedURLException ex) {
> >>             ex.printStackTrace();
> >>         }
> >> 
> >>         svgRoot = doc.getDocumentElement();
> >>         groupElement = doc.createElementNS(svgNS, "g");
> >>         svgRoot.appendChild(groupElement);
> >> 
> >> I also notice that if I type real slow the image doesn't get broken 
up 
> > (my
> >> method gets called after a key is pressed).  Any thoughts on whats
> >> happening?
> >> 
> >> vyang
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/xlink%3Ahref-
> problem---tf3274450.html#a9161124
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


RE: xlink:href problem??

Posted by vyang <vy...@apt-cafm.com>.
Thanks thomas that worked.  Now I have a question.  I've tried early to put
my statement inside runnablequeue but gives me a nullpointerexception(i
think).  That is when I didn't set my document state.  So then is
runnablequeue only available when the document state is set to dynamic?

vyang


thomas.deweese wrote:
> 
> Hi Vyang,
> 
> vyang <vy...@apt-cafm.com> wrote on 02/23/2007 03:58:58 PM:
> 
>> I meant its an image of a svg file on server.  I added your line of code 
> to
>> my constructor and it doesn't seem to work.  It is coded as follows:
> 
>    I suspect the problem is that you are modifying the document while
> Batik is trying to build the rendering tree.  There are a number
> of ways to avoid this problem.  Probably the simplest is to 
> clone the entire tree into a new document before giving it to
> the Canvas to display.
> 
>    The best way would be to change the way you are doing everything
> and make your Document a dynamic SVG document.  This would allow you
> to modify the document and have the Canvas automatically update the
> display.  For this to work however you need to make all your changes
> to the document in the update manager's RunnableQueue.  You can 
> look at the Batik FAQ for information on how to run thing in
> the RunnableQueue.
> 
>>         impl = SVGDOMImplementation.getDOMImplementation();
>>         svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>>         xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
>> 
>>         doc = impl.createDocument(svgNS, "svg", null);
>>         SVGOMDocument omDocument = (SVGOMDocument) doc;
>>         try {
>>             omDocument.setURLObject(new 
> File("c:/icontemp.svg").toURL());
>>         } catch (MalformedURLException ex) {
>>             ex.printStackTrace();
>>         }
>> 
>>         svgRoot = doc.getDocumentElement();
>>         groupElement = doc.createElementNS(svgNS, "g");
>>         svgRoot.appendChild(groupElement);
>> 
>> I also notice that if I type real slow the image doesn't get broken up 
> (my
>> method gets called after a key is pressed).  Any thoughts on whats
>> happening?
>> 
>> vyang
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9161124
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: xlink:href problem??

Posted by th...@kodak.com.
Hi Vyang,

vyang <vy...@apt-cafm.com> wrote on 02/23/2007 03:58:58 PM:

> I meant its an image of a svg file on server.  I added your line of code 
to
> my constructor and it doesn't seem to work.  It is coded as follows:

   I suspect the problem is that you are modifying the document while
Batik is trying to build the rendering tree.  There are a number
of ways to avoid this problem.  Probably the simplest is to 
clone the entire tree into a new document before giving it to
the Canvas to display.

   The best way would be to change the way you are doing everything
and make your Document a dynamic SVG document.  This would allow you
to modify the document and have the Canvas automatically update the
display.  For this to work however you need to make all your changes
to the document in the update manager's RunnableQueue.  You can 
look at the Batik FAQ for information on how to run thing in
the RunnableQueue.

>         impl = SVGDOMImplementation.getDOMImplementation();
>         svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
>         xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
> 
>         doc = impl.createDocument(svgNS, "svg", null);
>         SVGOMDocument omDocument = (SVGOMDocument) doc;
>         try {
>             omDocument.setURLObject(new 
File("c:/icontemp.svg").toURL());
>         } catch (MalformedURLException ex) {
>             ex.printStackTrace();
>         }
> 
>         svgRoot = doc.getDocumentElement();
>         groupElement = doc.createElementNS(svgNS, "g");
>         svgRoot.appendChild(groupElement);
> 
> I also notice that if I type real slow the image doesn't get broken up 
(my
> method gets called after a key is pressed).  Any thoughts on whats
> happening?
> 
> vyang
> 
> 
> Bishop, Michael W. CONTR J9C880 wrote:
> > 
> > The one you create in memory.  It doesn't look like you're linking an
> > SVGDocument from a server, it looks like you're linking an image.
> > 
> > Michael Bishop
> > 
> > 
> > --
> > View this message in context:
> > http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9119783
> > Sent from the Batik - Users mailing list archive at Nabble.com.
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> > 
> > 
> > 
> > 
> > ---------------------------------------------------------------------
> > To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> > For additional commands, e-mail: 
batik-users-help@xmlgraphics.apache.org
> > 
> 
> -- 
> View this message in context: http://www.nabble.com/xlink%3Ahref-
> problem---tf3274450.html#a9126677
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 


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


RE: xlink:href problem??

Posted by vyang <vy...@apt-cafm.com>.
I meant its an image of a svg file on server.  I added your line of code to
my constructor and it doesn't seem to work.  It is coded as follows:

        impl = SVGDOMImplementation.getDOMImplementation();
        svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
        
        doc = impl.createDocument(svgNS, "svg", null);
        SVGOMDocument omDocument = (SVGOMDocument) doc;
        try {
            omDocument.setURLObject(new File("c:/icontemp.svg").toURL());
        } catch (MalformedURLException ex) {
            ex.printStackTrace();
        }
        
        svgRoot = doc.getDocumentElement();
        groupElement = doc.createElementNS(svgNS, "g");
        svgRoot.appendChild(groupElement);

I also notice that if I type real slow the image doesn't get broken up (my
method gets called after a key is pressed).  Any thoughts on whats
happening?

vyang


Bishop, Michael W. CONTR J9C880 wrote:
> 
> The one you create in memory.  It doesn't look like you're linking an
> SVGDocument from a server, it looks like you're linking an image.
>  
> Michael Bishop
> 
> 
> --
> View this message in context:
> http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9119783
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 
>  
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 

-- 
View this message in context: http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9126677
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: xlink:href problem??

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
The one you create in memory.  It doesn't look like you're linking an SVGDocument from a server, it looks like you're linking an image.
 
Michael Bishop

________________________________

From: vyang [mailto:vyang@apt-cafm.com]
Sent: Fri 2/23/2007 9:40 AM
To: batik-users@xmlgraphics.apache.org
Subject: RE: xlink:href problem??





Bishop, Michael W. CONTR J9C880 wrote:
>
> I believe you need to set the URL of the SVGDocument.
Which SVGDocument, the one I created in memory or the one that is to be
linked?  The svg that is linked is from server.  Also, the rate at which the
method is access seems to effect how fast I get the broken image.  For
example, I would call the insertText method everytime a key is released but
if I press keys very fast, it'll only take a few tries while pressing the
keys slowly will make it take longer.


vyang


Bishop, Michael W. CONTR J9C880 wrote:
>
> I believe you need to set the URL of the SVGDocument.  Even if you
> create it in memory, Batik needs to know where the SVGDocument's base
> URL is to resolve (some?) image links; especially if your image URL is
> relative:
>
> SVGOMDocument omDocument = (SVGOMDocument) svgDocument;
> omDocument.setURLObject(new
> File("chosen/base/location/of/svg/document").toURL());
>
> Michael Bishop
>
> --
> View this message in context:
> http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9105802
> Sent from the Batik - Users mailing list archive at Nabble.com.
>
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
>
>
>

--
View this message in context: http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9119783
Sent from the Batik - Users mailing list archive at Nabble.com.


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



RE: xlink:href problem??

Posted by vyang <vy...@apt-cafm.com>.

Bishop, Michael W. CONTR J9C880 wrote:
> 
> I believe you need to set the URL of the SVGDocument. 
Which SVGDocument, the one I created in memory or the one that is to be
linked?  The svg that is linked is from server.  Also, the rate at which the
method is access seems to effect how fast I get the broken image.  For
example, I would call the insertText method everytime a key is released but
if I press keys very fast, it'll only take a few tries while pressing the
keys slowly will make it take longer.


vyang


Bishop, Michael W. CONTR J9C880 wrote:
> 
> I believe you need to set the URL of the SVGDocument.  Even if you
> create it in memory, Batik needs to know where the SVGDocument's base
> URL is to resolve (some?) image links; especially if your image URL is
> relative:
> 
> SVGOMDocument omDocument = (SVGOMDocument) svgDocument;
> omDocument.setURLObject(new
> File("chosen/base/location/of/svg/document").toURL());
> 
> Michael Bishop
> 
> -- 
> View this message in context:
> http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9105802
> Sent from the Batik - Users mailing list archive at Nabble.com.
> 
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> ---------------------------------------------------------------------
> To unsubscribe, e-mail: batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail: batik-users-help@xmlgraphics.apache.org
> 
> 
> 

-- 
View this message in context: http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9119783
Sent from the Batik - Users mailing list archive at Nabble.com.


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


RE: xlink:href problem??

Posted by "Bishop, Michael W. CONTR J9C880" <Mi...@je.jfcom.mil>.
I believe you need to set the URL of the SVGDocument.  Even if you
create it in memory, Batik needs to know where the SVGDocument's base
URL is to resolve (some?) image links; especially if your image URL is
relative:

SVGOMDocument omDocument = (SVGOMDocument) svgDocument;
omDocument.setURLObject(new
File("chosen/base/location/of/svg/document").toURL());

Michael Bishop



-----Original Message-----
From: vyang [mailto:vyang@apt-cafm.com] 
Sent: Thursday, February 22, 2007 1:44 PM
To: batik-users@xmlgraphics.apache.org
Subject: xlink:href problem??


Hello,

I'm having a problem with my canvas displaying an image of a broken
picture. 
I create a document in memory and link the svg into the document(which
is
done in the constructor).  I then have a method whichs add/removes the
<text> element from the document and resets the canvas document.  After
a
few calls of this method my canvas display a broken image picture.  My
coding is as follows:

Constructor:
        impl = SVGDOMImplementation.getDOMImplementation();
        svgNS = SVGDOMImplementation.SVG_NAMESPACE_URI;
        xlinkNS = XMLConstants.XLINK_NAMESPACE_URI;
        doc = impl.createDocument(svgNS, "svg", null);
        svgRoot = doc.getDocumentElement();
        groupElement = doc.createElementNS(svgNS, "g");
        svgRoot.appendChild(groupElement);

        loadIconDisplay();



loadIconDisplay:
        Element iconElement = doc.createElementNS(svgNS, "image");
        iconElement.setAttributeNS(null,  "id", "icon");
        iconElement.setAttributeNS(null, "width", Double.toString(275));
        iconElement.setAttributeNS(null,  "height",
Double.toString(275));
        iconElement.setAttributeNS(null, "x", Double.toString(x));
        iconElement.setAttributeNS(null, "y", Double.toString(y));
        iconElement.setAttributeNS(xlinkNS, "xlink:href",
iconLibrary.getIconURL());
        groupElement.appendChild(iconElement);
        
        jSVGCanvasIconDisplay.setDocument(doc);



insertIconText:
        if (stringIconText != null) {
            Element tempIconText = doc.getElementById("icontext");
            
            //removes old icon text
            if (tempIconText != null) {
                groupElement.removeChild(tempIconText);
            }
            
            Element iconText = doc.createElementNS(svgNS, "text");
            iconText.setAttributeNS(null, "id", "icontext");
            iconText.setAttributeNS(null, "x", Double.toString(x));
            iconText.setAttributeNS(null, "y", Double.toString(y));
            iconText.setTextContent(stringIconText);
            groupElement.appendChild(iconText);
            
            jSVGCanvasIconDisplay.setDocument(doc);
         }


Any hints/help is much appreciated.
-- 
View this message in context:
http://www.nabble.com/xlink%3Ahref-problem---tf3274450.html#a9105802
Sent from the Batik - Users mailing list archive at Nabble.com.


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

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