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 "Mark A. Jordan" <js...@yahoo.com> on 2005/06/21 21:29:56 UTC

Programmatically Change Display Attribute -- Rendering not happening

Hello.

I have successfully created a Java application using the sample provided on the
Batik website (JSVGCanvas tutorial --
http://xml.apache.org/batik/svgcanvas.html).  Upon button click, I have added
code to get a specific element (by id) and then I use the setAttribute method
to change the "display" attribute to "none" or "inline" accordingly (I'm
toggling between the two values to prove a point).

My problem is that I don't know how to force the SVG image to re-render.  If I
move the mouse over the SVG, the change is reflected in the image, i.e., my
element appears or disappears accordingly.  I'm looking for the magic function
call to force the render without further action from the user.

I have previously set the document state (setDocumentState) of the canvas
object to ALWAYS_DYNAMIC.

Here's my code:

======================
                System.out.println("Rock on...");
                Document doc = svgCanvas.getSVGDocument();
                if(null == doc) {
                    System.out.println("Didn't get the document.");
                    return;
                }

                String idToGet = "green";
                Element elementToChange =
svgCanvas.getSVGDocument().getElementById( idToGet );

                if(null == elementToChange) {
                    System.out.println("Didn't get the '" + idToGet + "'
elements.");
                    return;
                }

                String displayAttr = elementToChange.getAttribute("display");
                // if attribute is "inline", then set to "none"
                if(displayAttr.compareToIgnoreCase("inline") == 0) {
                    System.out.println("Setting display='none' for the '" +
idToGet + "' element.");
                    elementToChange.setAttribute("display", "none");
                    //elementToChange.removeAttribute("display");
                } else {
                    System.out.println("Setting display='inline' for the '" +
idToGet + "' element.");
                    elementToChange.setAttribute("display", "inline");
                }
                // this doesn't cause the image to appear --
svgCanvas.repaint();
                //svgCanvas.getUpdateManager().  probably something here
======================

Thanks in advance,
Mark Jordan

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


Re: Programmatically Change Display Attribute -- Rendering not happening

Posted by Arian Hojat <ar...@yahoo.com>.
I havent touched SVG in java for a while. But a couple
years ago, when i had problems getting the canvas to
be dynamic, I just reset the canvas with dynamic doc I
was building
svgCanvas.setSVGDocument((SVGDocument)doc);

Maybe thats a quick fix just to get results.



--- "Mark A. Jordan" <js...@yahoo.com> wrote:

> Hello.
> 
> I have successfully created a Java application using
> the sample provided on the
> Batik website (JSVGCanvas tutorial --
> http://xml.apache.org/batik/svgcanvas.html).  Upon
> button click, I have added
> code to get a specific element (by id) and then I
> use the setAttribute method
> to change the "display" attribute to "none" or
> "inline" accordingly (I'm
> toggling between the two values to prove a point).
> 
> My problem is that I don't know how to force the SVG
> image to re-render.  If I
> move the mouse over the SVG, the change is reflected
> in the image, i.e., my
> element appears or disappears accordingly.  I'm
> looking for the magic function
> call to force the render without further action from
> the user.
> 
> I have previously set the document state
> (setDocumentState) of the canvas
> object to ALWAYS_DYNAMIC.
> 
> Here's my code:
> 
> ======================
>                 System.out.println("Rock on...");
>                 Document doc =
> svgCanvas.getSVGDocument();
>                 if(null == doc) {
>                     System.out.println("Didn't get
> the document.");
>                     return;
>                 }
> 
>                 String idToGet = "green";
>                 Element elementToChange =
> svgCanvas.getSVGDocument().getElementById( idToGet
> );
> 
>                 if(null == elementToChange) {
>                     System.out.println("Didn't get
> the '" + idToGet + "'
> elements.");
>                     return;
>                 }
> 
>                 String displayAttr =
> elementToChange.getAttribute("display");
>                 // if attribute is "inline", then
> set to "none"
>                
> if(displayAttr.compareToIgnoreCase("inline") == 0) {
>                     System.out.println("Setting
> display='none' for the '" +
> idToGet + "' element.");
>                    
> elementToChange.setAttribute("display", "none");
>                    
> //elementToChange.removeAttribute("display");
>                 } else {
>                     System.out.println("Setting
> display='inline' for the '" +
> idToGet + "' element.");
>                    
> elementToChange.setAttribute("display", "inline");
>                 }
>                 // this doesn't cause the image to
> appear --
> svgCanvas.repaint();
>                 //svgCanvas.getUpdateManager(). 
> probably something here
> ======================
> 
> Thanks in advance,
> Mark Jordan
> 
>
---------------------------------------------------------------------
> To unsubscribe, e-mail:
> batik-users-unsubscribe@xmlgraphics.apache.org
> For additional commands, e-mail:
> batik-users-help@xmlgraphics.apache.org
> 
> 


__________________________________________________
Do You Yahoo!?
Tired of spam?  Yahoo! Mail has the best spam protection around 
http://mail.yahoo.com 

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


Re: Programmatically Change Display Attribute -- Rendering not happening

Posted by "Mark A. Jordan" <js...@yahoo.com>.
My apologies.  I didn't check the FAQ.  I am a subhuman.

http://xml.apache.org/batik/faqs.html#faq-21
http://xml.apache.org/batik/faqs.html#faq-22

--- "Mark A. Jordan" <js...@yahoo.com> wrote:

> Hello.
> 
> I have successfully created a Java application using the sample provided on
> the
> Batik website (JSVGCanvas tutorial --
> http://xml.apache.org/batik/svgcanvas.html).  Upon button click, I have added
> code to get a specific element (by id) and then I use the setAttribute method
> to change the "display" attribute to "none" or "inline" accordingly (I'm
> toggling between the two values to prove a point).
> 
> My problem is that I don't know how to force the SVG image to re-render.  If
> I
> move the mouse over the SVG, the change is reflected in the image, i.e., my
> element appears or disappears accordingly.  I'm looking for the magic
> function
> call to force the render without further action from the user.
> 
> I have previously set the document state (setDocumentState) of the canvas
> object to ALWAYS_DYNAMIC.
> 
> Here's my code:
> 
> ======================
>                 System.out.println("Rock on...");
>                 Document doc = svgCanvas.getSVGDocument();
>                 if(null == doc) {
>                     System.out.println("Didn't get the document.");
>                     return;
>                 }
> 
>                 String idToGet = "green";
>                 Element elementToChange =
> svgCanvas.getSVGDocument().getElementById( idToGet );
> 
>                 if(null == elementToChange) {
>                     System.out.println("Didn't get the '" + idToGet + "'
> elements.");
>                     return;
>                 }
> 
>                 String displayAttr = elementToChange.getAttribute("display");
>                 // if attribute is "inline", then set to "none"
>                 if(displayAttr.compareToIgnoreCase("inline") == 0) {
>                     System.out.println("Setting display='none' for the '" +
> idToGet + "' element.");
>                     elementToChange.setAttribute("display", "none");
>                     //elementToChange.removeAttribute("display");
>                 } else {
>                     System.out.println("Setting display='inline' for the '" +
> idToGet + "' element.");
>                     elementToChange.setAttribute("display", "inline");
>                 }
>                 // this doesn't cause the image to appear --
> svgCanvas.repaint();
>                 //svgCanvas.getUpdateManager().  probably something here
> ======================
> 
> Thanks in advance,
> Mark Jordan
> 
> ---------------------------------------------------------------------
> 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