Extending ComplexPanel: need to have FocusPanel + LayoutPanel functionalities

214 views
Skip to first unread message

Vhann

unread,
Aug 10, 2011, 10:51:24 AM8/10/11
to Google Web Toolkit
Hi,

I am trying to adapt a slideshow to the web using GWT (it is going to
be a long go considering my rate of progress, but it's okay, I enjoy
getting back to Java).

Basically, the problem I encounter is that a Slide must be able to
catch click events (to start the next SlideItem's Animation or to
notify the SlideShow that it is done and to Transition into the next
Slide). A Slide must also be a LayoutPanel (because SlideItems can be
located anywhere on the Slide).

Now, from what I know there is two ways I can do this: either extend
Composite or extending ComplexPanel (the latter seems the best choice
as it already implements most methods I need). I have tried both, but
I obviously fail to understand how to properly extend these classes.

Now, I haven't found much documentation on how to extend ComplexPanel
(neither on the Javadoc nor on the Internet nor by searching this
newsgroup). I decompressed the gwt-user.jar and looked at the
implementations of LayoutPanel, FocusPanel and various other "full
class" Panel classes.

If I understand everything correctly, I basically need to use
setElement() in my "Slide extends ComplexPanel"'s constructor. If I am
right (if that actually is the correct way to go to do what I want),
should I use Document.get().createDivElement() (as in
LayoutPanel.java) or DOM.createDiv() (as in SimplePanel.java)?

I have no knowledge of ECMAScript (Javascript), but I do know a few
things about HTML and CSS. From what I understand the DOM is used to
handle events and since I want FocusPanel fonctionality, that might be
what I need.


Well, sorry for that long and confusing message; I am trying to give
as much useful informations as possible.

Thanks in advance.
Regards,
Vhann

Jeff Larsen

unread,
Aug 10, 2011, 11:55:31 AM8/10/11
to google-we...@googlegroups.com
I would recommend extending the LayoutPanel that is the closest fit to your needs, then sink the appropriate events. You Can use FocusPanel to show you how to sink the events you're interested in. 

Vhann

unread,
Aug 10, 2011, 5:00:55 PM8/10/11
to google-we...@googlegroups.com
Hi Jeff,

The part about extending LayoutPanel is fine, but I have a few questions about how to handle events (the FocusPanel part):

1- From what I understand, most Panel subclasses (that is all except FocusPanel and its subclasses) are more or less simple HTML divisions (<div></div>), tables (<table></table), etc. hence they can't handle input events (mouse or keyboard events). That being said, are you saying I should look at the Java source code of Google's FocusPanel class and somehow use that to have my LayoutPanel subclass be able to handle events?

2- Or do you mean I should make SlideShow (the class instantiating Slides) a FocusPanel and have SlideShow send events to the Slides?

3- Or is there a simple way to have a Panel implements HasClickHandlers without extends FocusPanel I haven't thought of?

Regards,
Vhann

Jeff Larsen

unread,
Aug 10, 2011, 6:06:10 PM8/10/11
to google-we...@googlegroups.com
Yea, any panel can implement ClickHandlers, just do a addDomHandler(handler, ClickEvent.getType());

that sinks the event as well as adds the handler to the panel. I hadn't looked at the source in a while, so I figured it was still the sinkEvents(Event.CLICK | Event.FOCUS ....) thing, but they've pulled that out and now that logic exists in the addDomHandler method. 

You should just be able to do layoutPanel.addDomHandler(new ClickHandler(){ ... }, ClickEvent.getType());


Vhann

unread,
Aug 10, 2011, 9:31:02 PM8/10/11
to google-we...@googlegroups.com
Hi Jeff,

I have tried addDomHandler() and indeed, it works!

Thanks a lot for your help Jeff.

Regards,
Vhann
Reply all
Reply to author
Forward
0 new messages