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 Le...@csiro.au on 2001/10/27 01:43:11 UTC

FW: Refreshing screen display after modifying attributes on graph ics node of tree

Hi,

I have an svg document containing more than 1 SVG layer.  The layers are
displayed on the screen.  I want to give the user the ability to turn of
some of the layers after it has been displayed. 

However I am having a problem with this.  I have attempted to set the
graphic nodes in the GVT tree invisible and to redisplay the updated GVT
tree.  However the changes in the GVT Tree are not updated on the display
immediately.  But I noticed that the changes seem to take effect, ie a
layer set to invisible no longer appears, only when you zoom in.   

Question : how can I get the display to reflect the changes in the GVT Tree
immediately.

+++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
The code to set the visibility of the graphic nodes and re-rendering is as
follows: 

****************************************************


public class RimisCanvas extends JSVGCanvas  {

    public RimisCanvas() {
        	super();

    }

    public void modifySVG(String id, boolean visflag){
            System.out.println(bridgeContext);
        System.out.println(id);
        System.out.println(visflag);
        System.out.println(svgDocument);
		org.w3c.dom.Element e = svgDocument.getElementById(id);
        System.out.println("e:"+e);
		GraphicsNode gn = bridgeContext.getGraphicsNode(e);
        if (gn instanceof CompositeGraphicsNode){
            CompositeGraphicsNode cgn = (CompositeGraphicsNode)gn;
            for (int i = 0; i<cgn.size();i++){
                 System.out.println("CGN 1:"+cgn.get(i));
                  if (cgn.get(i) instanceof CompositeGraphicsNode){
                    CompositeGraphicsNode cgn2 =
(CompositeGraphicsNode)cgn.get(i);
                    for (int j = 0; j<cgn2.size();j++){
                        System.out.println("j:"+j);
                        System.out.println("CGN
2:"+((CompositeGraphicsNode)cgn2.get(j)).get(0));
                        GraphicsNode shpnode =
(GraphicsNode)((CompositeGraphicsNode)cgn2.get(j)).get(0);
                   	if (visflag) {
                            System.out.print("inside visflag true");
	    	            	shpnode.setVisible(true);
                        } else {
                            System.out.print("inside visflag false");
                            shpnode.setVisible(false);
                        }

                    }
                  }
            }
        AffineTransform at = new AffineTransform(getRenderingTransform());
       setRenderingTransform(at);
    }
}

**************************************************************
++++++++++++++++++++++++++++++++++++++++++++++


The operating system : Windows 2000. Java version : JDK1.3.1.  Batik version
1.1rc2.


Some of the commands I have tried unsuccessfully to repaint are as follows:
	(a) immediateRepaint()
	 (b) invalidate() 
	(c)AffineTransform at = getRenderingTransform()
		 setRenderingTransform(at)


Could you also advise me if there is a better way of setting a layer to be
invisible after it is displayed on the screen.


Thank you.


Regards
Leakha






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


Re: FW: Refreshing screen display after modifying attributes on graphics node of tree

Posted by Thomas E Deweese <th...@kodak.com>.
>>>>> "VH" == Vincent Hardy <vi...@sun.com> writes:

VH> In SVG, your API to manipulate the graphics is the DOM and the
VH> best way to do what you want is to use scripting (e.g., Java or
VH> JavaScript).

    Agreed this is the 'correct' way to do this (and keeps you
independent of a particular SVG implementation).

VH> The problem is that right now, Batik does not support
VH> scripting. One way to work around this (and until we support
VH> scripting) is to do a setDocument on the JSVGCanvas after you have
VH> modified the DOM.

    This will work but forces the recreation of the GVT tree.  Since
they are actually manipulating the GVT tree directly they can make use
of JGVTComponent.flush() (JGVTComponent is JSVGCanvas's parent class).
This should clear the rendering cache for them.  So at the end of your
modify run just call flush().  You can also call flush with a
java.awt.Rectangle and only that region of the cached data will be
cleared.

    Hope this helps...

VH> So, for example:

VH> Document doc = ...;

VH> Element elt = doc.getElementById("myLayer");

VH> elt.setAttributeNS(null, "visibility", "hidden");

VH> myCanvas.setDocument(doc);

VH> I think it is better now to hook in at the GVT level.  I hope this
VH> helps.  Vincent.

VH> Leakha.Henry@csiro.au wrote:
>>  Hi,
>> 
>> I have an svg document containing more than 1 SVG layer.  The
>> layers are displayed on the screen.  I want to give the user the
>> ability to turn of some of the layers after it has been displayed.
>> 
>> However I am having a problem with this.  I have attempted to set
>> the graphic nodes in the GVT tree invisible and to redisplay the
>> updated GVT tree.  However the changes in the GVT Tree are not
>> updated on the display immediately.  But I noticed that the changes
>> seem to take effect, ie a layer set to invisible no longer appears,
>> only when you zoom in.
>> 
>> Question : how can I get the display to reflect the changes in the
>> GVT Tree immediately.
>> 
>> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++ The
>> code to set the visibility of the graphic nodes and re-rendering is
>> as follows:
>> 
>> ****************************************************
>> 
>> public class RimisCanvas extends JSVGCanvas {
>> 
>> public RimisCanvas() { super();
>> 
>> }
>> 
>> public void modifySVG(String id, boolean visflag){
>> System.out.println(bridgeContext); System.out.println(id);
>> System.out.println(visflag); System.out.println(svgDocument);
>> org.w3c.dom.Element e = svgDocument.getElementById(id);
>> System.out.println("e:"+e); GraphicsNode gn =
>> bridgeContext.getGraphicsNode(e); if (gn instanceof
>> CompositeGraphicsNode){ CompositeGraphicsNode cgn =
>> (CompositeGraphicsNode)gn; for (int i = 0; i<cgn.size();i++){
>> System.out.println("CGN 1:"+cgn.get(i)); if (cgn.get(i) instanceof
>> CompositeGraphicsNode){ CompositeGraphicsNode cgn2 =
>> (CompositeGraphicsNode)cgn.get(i); for (int j = 0;
>> j<cgn2.size();j++){ System.out.println("j:"+j);
>> System.out.println("CGN
>> 2:"+((CompositeGraphicsNode)cgn2.get(j)).get(0)); GraphicsNode
>> shpnode =
>> (GraphicsNode)((CompositeGraphicsNode)cgn2.get(j)).get(0); if
>> (visflag) { System.out.print("inside visflag true");
>> shpnode.setVisible(true); } else { System.out.print("inside visflag
>> false"); shpnode.setVisible(false); }
>> 
>> } } } AffineTransform at = new
>> AffineTransform(getRenderingTransform());
>> setRenderingTransform(at); } }
>> 
>> **************************************************************
>> ++++++++++++++++++++++++++++++++++++++++++++++
>> 
>> The operating system : Windows 2000. Java version : JDK1.3.1.
>> Batik version 1.1rc2.
>> 
>> Some of the commands I have tried unsuccessfully to repaint are as
>> follows: (a) immediateRepaint() (b) invalidate() (c)AffineTransform
>> at = getRenderingTransform() setRenderingTransform(at)
>> 
>> Could you also advise me if there is a better way of setting a
>> layer to be invisible after it is displayed on the screen.
>> 
>> Thank you.
>> 
>> Regards Leakha
>> 
>> ---------------------------------------------------------------------
>> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For
>> additional commands, e-mail: batik-users-help@xml.apache.org

VH> ---------------------------------------------------------------------
VH> To unsubscribe, e-mail: batik-users-unsubscribe@xml.apache.org For
VH> 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: FW: Refreshing screen display after modifying attributes on graphics node of tree

Posted by Vincent Hardy <vi...@sun.com>.
In SVG, your API to manipulate the graphics is the DOM and the best
way to do what you want is to use scripting (e.g., Java or JavaScript).

The problem is that right now, Batik does not support scripting. One
way to work around this (and until we support scripting) is to do 
a setDocument on the JSVGCanvas after you have modified the DOM.

So, for example:

Document doc = ...;

Element elt = doc.getElementById("myLayer");

elt.setAttributeNS(null, "visibility", "hidden");

myCanvas.setDocument(doc);

I think it is better now to hook in at the GVT level.
I hope this helps.
Vincent.

Leakha.Henry@csiro.au wrote:
> 
> Hi,
> 
> I have an svg document containing more than 1 SVG layer.  The layers are
> displayed on the screen.  I want to give the user the ability to turn of
> some of the layers after it has been displayed.
> 
> However I am having a problem with this.  I have attempted to set the
> graphic nodes in the GVT tree invisible and to redisplay the updated GVT
> tree.  However the changes in the GVT Tree are not updated on the display
> immediately.  But I noticed that the changes seem to take effect, ie a
> layer set to invisible no longer appears, only when you zoom in.
> 
> Question : how can I get the display to reflect the changes in the GVT Tree
> immediately.
> 
> +++++++++++++++++++++++++++++++++++++++++++++++++++++++++++
> The code to set the visibility of the graphic nodes and re-rendering is as
> follows:
> 
> ****************************************************
> 
> public class RimisCanvas extends JSVGCanvas  {
> 
>     public RimisCanvas() {
>                 super();
> 
>     }
> 
>     public void modifySVG(String id, boolean visflag){
>             System.out.println(bridgeContext);
>         System.out.println(id);
>         System.out.println(visflag);
>         System.out.println(svgDocument);
>                 org.w3c.dom.Element e = svgDocument.getElementById(id);
>         System.out.println("e:"+e);
>                 GraphicsNode gn = bridgeContext.getGraphicsNode(e);
>         if (gn instanceof CompositeGraphicsNode){
>             CompositeGraphicsNode cgn = (CompositeGraphicsNode)gn;
>             for (int i = 0; i<cgn.size();i++){
>                  System.out.println("CGN 1:"+cgn.get(i));
>                   if (cgn.get(i) instanceof CompositeGraphicsNode){
>                     CompositeGraphicsNode cgn2 =
> (CompositeGraphicsNode)cgn.get(i);
>                     for (int j = 0; j<cgn2.size();j++){
>                         System.out.println("j:"+j);
>                         System.out.println("CGN
> 2:"+((CompositeGraphicsNode)cgn2.get(j)).get(0));
>                         GraphicsNode shpnode =
> (GraphicsNode)((CompositeGraphicsNode)cgn2.get(j)).get(0);
>                         if (visflag) {
>                             System.out.print("inside visflag true");
>                                 shpnode.setVisible(true);
>                         } else {
>                             System.out.print("inside visflag false");
>                             shpnode.setVisible(false);
>                         }
> 
>                     }
>                   }
>             }
>         AffineTransform at = new AffineTransform(getRenderingTransform());
>        setRenderingTransform(at);
>     }
> }
> 
> **************************************************************
> ++++++++++++++++++++++++++++++++++++++++++++++
> 
> The operating system : Windows 2000. Java version : JDK1.3.1.  Batik version
> 1.1rc2.
> 
> Some of the commands I have tried unsuccessfully to repaint are as follows:
>         (a) immediateRepaint()
>          (b) invalidate()
>         (c)AffineTransform at = getRenderingTransform()
>                  setRenderingTransform(at)
> 
> Could you also advise me if there is a better way of setting a layer to be
> invisible after it is displayed on the screen.
> 
> Thank you.
> 
> Regards
> Leakha
> 
> ---------------------------------------------------------------------
> 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