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 Web Query <we...@shermantech.com> on 2004/10/06 02:02:40 UTC

How do I mouse-click on an SVG element and change it's color

Hi,

I just started programming with batik today and have come to a point 
that is stumpping me after hours of looking at the API and tracing code 
through the debugger.  I have managed to take the sample SVGBrowser 
application and implement mouse listening in such a way that I can get 
the GraphicsNode object that I click on (whew - that took some work).  
But, now I need to change the color of the SVG object I selected.  It 
would seem there should be a simple way to do this, but it appears that 
changing the color involves digging up a BridgeContext and a document 
(SVG)Element in addition to the GraphicsNode in order to modify the 
GraphicNode's ShapePainter. 

Is dynamically changing the color of the GraphicsNode possible?
Is there a simple way to change the color of the GraphicsNode object? 
If not, where do I get the BridgeContext and Element necessary to make 
the color changes?
Is there a better way to highlight SVG objects? (such as overlays, etc.)

If any of the above is possible, is there some sample code available to 
demonstrate how this is done?

Thanks,
Chris

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


Re: How do I mouse-click on an SVG element and change it's color

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

Web Query wrote:

> I just started programming with batik today and have come to a point 
> that is stumpping me after hours of looking at the API and tracing code 
> through the debugger.  I have managed to take the sample SVGBrowser 
> application and implement mouse listening in such a way that I can get 
> the GraphicsNode object that I click on (whew - that took some work).  

    This is a lot easier if you use the DOM:

	Element x = document.getElementById(...);
	EventListener el = new EventListener() {
		public void handleEvent(Event evt) {... }
	};
	((EventTarget)x).addEventListener("mousemove", el, false);

     BTW you probably want to look at the DOM events spec (it's a
pretty short read).  It will let you know about event propagation
(which can help avoid registering lots of listeners).

> But, now I need to change the color of the SVG object I selected.  

    Archie already answered this, once again the DOM is your friend.


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


Re: How do I mouse-click on an SVG element and change it's color

Posted by Archie Cobbs <ar...@dellroad.org>.
Web Query wrote:
> Is dynamically changing the color of the GraphicsNode possible?
> Is there a simple way to change the color of the GraphicsNode object? 
> If not, where do I get the BridgeContext and Element necessary to make 
> the color changes?

You don't need to fool with any of the bridge stuff if all you want
is to change the color of something. Instead, just modify the SVG
XML DOM in memory and Batik will automatically notice the changes
(assuming you've told it that the document is dynamic).

E.g.:

  JSVGCanvas canvas = ...
  SVGDocument svg = canvas.getSVGDocument();
  elem = (SVGElement)svg.getElementById("element-id-123");
  elem.setAttributeNS(null, "fill", "#ff0000");

-Archie

__________________________________________________________________________
Archie Cobbs      *        CTO, Awarix        *      http://www.awarix.com

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