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 Steve Lamont <sp...@ncmir.ucsd.edu> on 2005/03/15 19:37:17 UTC

Changing color of GVT node, redux

I recently asked about changing the color of GVT nodes and received
one answer, reproduced below, along with my response.  I was hoping
that someone would have further advice on how to do this.

My original question was:

  How does one go about changing the color attribute of an individual
  GVT node?  I've spent most of the morning fishing through the
  documentation, the mailing list archives, and the source code to no
  avail.  I'm clearly missing something.

As I mention below, I do not need or want to save the changes to the
SVG XML -- the XML is effectively read-only.

Guidance would be most appreciated.

							spl

				- - -

> you mean you want to change the color of a shape in your svg file?
>
> (untested syntax)
> 1) lookup the node using methods like
> node=document.getElementById("...")
> 2) set the node attribute like node.setAttribute("fill", "blue");

I'm already doing something quite similar that but it's very slow,
since the SVG has to be transformed into GraphicsNodes.

I'm doing the following to turn off text in the displayed document by
walking the GVT tree:

    private void setTextState( CompositeGraphicsNode cgn,
			       boolean text_state )
	
    {
	
	for ( int i = 0; i < cgn.size(); i++ ) {

	    Object object = cgn.get( i );
	    Class object_class = object.getClass();

	    if ( object_class.equals( CompositeGraphicsNode.class ) )
		this.setTextState( ( CompositeGraphicsNode ) object,
                                   text_state );
	    else if ( object_class.equals( TextNode.class ) ) {

		TextNode text_node = ( TextNode ) object;

		text_node.setVisible( text_state );

	    }

	}
	
    }

and I was hoping that there was some similar

I'm not interested in saving the changes to the document -- the
document is effectively "read only".

There are Graphics2D objects fed to the paint() methods of the
individual objects but it's not clear to me whence those objects come
or how they are manipulated.

							spl

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


Re: Changing color of GVT node, redux

Posted by Cameron McCormack <ca...@aka.mcc.id.au>.
Hi Steve.

Steve Lamont:
>   How does one go about changing the color attribute of an individual
>   GVT node?  I've spent most of the morning fishing through the
>   documentation, the mailing list archives, and the source code to no
>   avail.  I'm clearly missing something.

To change the colour of the graphics node you should change the
ShapePainter that is associated with that ShapeNode.  This, though, is
what is done when you change the 'fill' or 'stroke' properties of a
shape element (such as 'rect'), anyway, so you will be getting hardly
any performance enhancement by doing this.

Cameron

-- 
  e-mail : cam (at) mcc.id.au    	icq : 26955922
     web : http://mcc.id.au/	        msn : cam-msn (at) aka.mcc.id.au
  office : +61399055779		     jabber : heycam (at) jabber.org

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