Addressing my own comments: On Wednesday 25 February 2009, Roberto Villarreal wrote: > Thomas -- > > On Wed February 25 2009 5:38:55 am [email protected] wrote: > > Hi Roberto, > > > > Roberto Villarreal <[email protected]> wrote on 02/24/2009 > > 07:07:47 > > > > PM: > > > What I need to do: > > > > > > 1) Add and remove predefined graphical 'widgets' (which are > > > predefined SVG files) onto a given background, viewing the end > > > result. Picture a bookcase and adding/removing shelves from > > > it, where in straight Swing one could merely add/remove JLabels > > > from a JPanel > > > > In SVG you would merely add/remove an 'image' element (or a > > 'use' element). > > After I sent this, I started going the SVG-manipulation route (I > was hoping I wouldn't have to get into the guts of how SVG works). > What I had done was merely read in the SVGDocument for each 'child' > file, went through it's child nodes, and imported/added those nodes > to the 'parent' SVGDocument then updated the canvas with that > document. > > 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?
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? 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. 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? [snip] Roberto --------------------------------------------------------------------- To unsubscribe, e-mail: [email protected] For additional commands, e-mail: [email protected]
