Thanks for the further explanation of the mouse related callbacks. However, the callbacks that I had setup did not end up being the problem. The problem ended up being that instances of TextLabelVP are converted to ParagraphTextVP when added to ParagraphVP's (see StyledViewFactory's contentToParagraph method). In the conversion, the implementations of "grabsMouseButton" and "handleMouseEvent" are not transferred to the ParagraphTextVP. Since my gadget was extending TextLabelVP, my implementations of "grabsMouseButton" and "handleMouseEvent" were never being called. All that was required to get this to work correctly was to subclass ParagraphTextVP instead of TextLabelVP.
I was really appreciative of the fact that I have the XMLmind source yesterday; this would have been very difficult to debug otherwise. Yet another way in which working with XXE has been a pleasure. Cheers, Mike -----Original Message----- From: Hussein Shafie [mailto:[email protected]] Sent: Fri 6/8/2007 3:48 AM To: Santy, Michael Cc: xmleditor-support at xmlmind.com Subject: Re: [XXE] mouse listener on css extension Santy, Michael wrote: > The Gadget approach is *exactly* what I'm needing. > > I was able to implement a subclass of TextLabelVP, return it from a > implementation of GadgetFactory, and setup a CSS rule to include it in > the editor. It behaved visually like I would expect, however I could > not get it to respond to any events. I implemented the grabsMouseButton > and handleMouseEvent as the documentation specified, but neither of > these methods were ever being called. I even overrode the focusGained > and focusLost method to see if this gadget was responding to any editor > events, and neither of these methods are ever being called as well. > > Below is a listing of the relevant code. The print statement in the > MyGadget constructor is being called and the gadget is included in the > document. When I double-click on the "My Gadget" label in the document, > nothing happens. > > Can anyone please shed some light on what I might be doing wrong? > > > public class MyGadgetFactory implements GadgetFactory { > > public Gadget createGadget(StyledElementView view, int role, Style style, > StyleValue[] parameters, StyledViewFactory viewFactory) { > > return new MyGadget(style, "My Gadget", view, role); > > } > } > > public class MyGadget extends TextLabelVP { > > public MyGadget(Style style, String text, > StyledElementView view, int role) { > super(style, text, view, role); > > Node node = view.getModel(); > > System.err.println("MyGadget::MyGadget() node: "+node); > } > > public boolean grabsMouseButton(MouseEvent e) { > System.err.println("My::grabsMouseButton()"); > boolean rv = false; > if(MouseEvent.BUTTON1==e.getButton() && 2==e.getClickCount()) { > rv = true; //double left-click > } > return rv; > } > > public void handleMouseEvent(MouseEvent e) { > System.err.println("MyGadget::handleMouseEvent()"); > } > } > This should work: --- public boolean grabsMouseButton(MouseEvent e) { System.err.println("My::grabsMouseButton()" + e); return (MouseEvent.BUTTON1==e.getButton()); } public void handleMouseEvent(MouseEvent e { DocumentView docView = (DocumentView) getRoot(); switch (e.getClickCount()) case 1: // Not strictly needed but consistent with the other // StyledElementViewParts. docView.selectNode(node); break; case 2: System.err.println("MyGadget::handleMouseEvent()" + e); break; } } --- Explanations: When grabsMouseButton returns true for a mouse event about button #1, this means: direct *all* subsequent mouse events (press, release, drag, click) about button #1 to my handleMouseEvent methods. When grabsMouseButton returns false for a mouse event about button #1, then, may be the parent of the Gadget, will process all mouse events about button #1, and if not, the grand-parent, and so on, until you reach the root Gadget. (The root Gadget is a com.xmlmind.xmledit.view.DocumentView (or a com.xmlmind.xmledit.styledview.StyledDocumentView). A com.xmlmind.xmledit.view.DocumentView manages mouse event by using much more sophisticated means than grabsMouseButton/handleMouseEvent. It uses com.xmlmind.xmledit.gadget.Bindings: http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmledit/gadget/Bindings.html But this is unrelated to your problem.) -------------- next part -------------- An HTML attachment was scrubbed... URL: http://www.xmlmind.com/pipermail/xmleditor-support/attachments/20070608/3a193039/attachment.htm

