Hi Roberto, > > On Wed February 25 2009 5:38:55 am [email protected] wrote:
> > > In SVG you would merely add/remove an 'image' element (or a > > > 'use' element). > On Wednesday 25 February 2009, Roberto Villarreal wrote: > > What I need is for all these graphics to be backed by logic; I > > would need to, for example, process a mouseClicked, know which > > 'model object' backs that graphic, and execute code. Using your > > suggested (or even mine, for that matter), is there any way to > > 'know' which graphic you are interacting with? In other words, in > > my example of the bookcase, is there any way to know that someone > > is clicking on a shelf and be able to track it back to that 'image' > > or 'use' element? With the 'image' it's fairly simple since the image element will be the 'target' for any clicks within the image, for 'use' it's a little more complex since you need to walk out of the 'shadow tree'. With your 'g' example I would mark the group with a special attribute and walk up the tree of DOM nodes (getParent) until I ran into an element with my special attribute. Roberto Villarreal <[email protected]> wrote on 02/25/2009 06:57:56 PM: > Through much blood, sweat, and tears, I think I've figured out how to > do this... I found it in a posting of yours from about four years > ago. Basically, with my whack-n-hack approach to the SVG (before you > informed me of the 'image' and 'use' elements), each image was > encompassed in a 'g' element, so with my bookcase example, I had the > bookcase in one 'g' and each shelf in a 'g' all as siblings under > the 'svg' root. As I reparented those 'children' 'g' elements, I did > an > > ( (EventTarget) g_node ).addEventListener( "click", listener, false ); > > With event 'evt' coming through the handleEvent() method, > evt.getCurrentTarget() gives the the 'g' node, which I can link back > to an object with intelligence. > Can you confirm that this is generally considered the best approach? This will work and is a very common approach. I tend to prefer to register just one listener at the root but it's mostly a matter of preference. > I've seen other postings about using stuff related to the GVT, but > seems that was usually discouraged... but those seem to be old posts. Direct use of the GVT is still discouraged. > Also, is there a place where it's documented what strings you can pass > into addEventListener() for the first argument? Or is there maybe > predefined constants somewhere? batik.util.SVGConstants has the constants. They are defined by the SVG and DOM Events specifications.
