Hussein,
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?
Cheers,
Mike
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()");
}
}
-----Original Message-----
From: Hussein Shafie [mailto:[email protected]]
Sent: Wed 6/6/2007 3:01 AM
To: Santy, Michael
Cc: xmleditor-support at xmlmind.com
Subject: Re: [XXE] mouse listener on css extension
Santy, Michael wrote:
>
> In my application, I have written a CSS extension to render a set of
> attributes on a single node in a very specialized way that cannot be
> done in pure CSS. The CSS extension returns the desired textual
> representation as intended.
>
> These attributes will be edited when a user double clicks on content
> returned from the CSS extension. I'm having trouble figuring out how to
> bind mouse clicks to the StyleValue returned by a CSS extension.
You cannot do that: style sheet extensions and user input such as
double-clicks are totally unrelated concepts.
> The only way that I've seen as a possibility is to replace the CSS
> extension with a ComponentFactory. This ComponentFactory would have to
> return a JLabel that has a mouse listener registered that opens the
> custom dialog on a double click.
>
> Is there a more straightforward approach that I'm overlooking?
Using a standard Java[tm] AWT/Swing Component created using a
ComponentFactory (rather an style extension) is certainly a clean and
simple way to achieve what you want.
http://www.xmlmind.com/xmleditor/_distrib/doc/dev/styleext.html#solution4
http://www.xmlmind.com/xmleditor/_distrib/doc/dev/styleext.html#solution1
(You could create a Gadget using a GadgetFactory, which is much more
efficient than creating a Component, but doing so is not documented and
is not officially supported:
http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmledit/gadget/Gadget.html
Use the grabsMouseButton and handleMouseEvent methods to do something
when the Gadget is double-clicked.
http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmledit/styledview/GadgetFactory.html
Gadgets returned by GadgetFactory must implement the
StyledElementViewPart interface.
http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmledit/styledgadget/TextLabel.html
TextLabel is a simple styled Gadget
http://www.xmlmind.com/xmleditor/_distrib/doc/api/com/xmlmind/xmledit/styledview/TextLabelVP.html
TextLabelVP is a TextLabel which implements the StyledElementViewPart
interface.)
-------------- next part --------------
An HTML attachment was scrubbed...
URL:
http://www.xmlmind.com/pipermail/xmleditor-support/attachments/20070606/f6a3f099/attachment.htm