Re: [Java-gnome-developer] OptionMenu events etc..
Brought to you by:
afcowie
From: Jonas B. <jb...@ni...> - 2003-10-03 20:47:37
|
On Thu, 2 Oct 2003 13:18:32 +0100, Mark Howard <mh...@de...> wrote: > The next stage is to actually receive notification of the events from > the native layer. This is done through the addEvents method. The jni > code is done in other parts of java-gnome, so for things like Buttons > and OptionMenus, it's just a case of adding: > protected static void addEvents(EventMap anEvtMap) { > Widget.addEvents(anEvtMap); > anEvtMap.addEvent("clicked", "handleClick", ButtonEvent.Type.CLICK,=20 > ButtonListener.class); Hi.. I took a look at some of the classes and thought they had some weird= =20 initialization style: public class ToggleButton extends Button { protected void initializeEventHandlers() { super.initializeEventHandlers(); evtMap.initialize(this); } protected static void addEvents(EventMap evtMap) { Button.addEvents(evtMap); // .. add togglebutton-specific events } } public class Button extends Bin { protected void initializeEventHandlers() { super.initializeEventHandlers(); evtMap.initialize(this); } protected static void addEvents(EventMap evtMap) { Widget.addEvents(evtMap); // .. add button-specific events } } public class Bin extends Container { // no initializeEventHandlers(), so it uses the one from Container protected static void addEvents(EventMap evtMap) { Container.addEvents(evtMap); } } public class Container extends Widget { protected void initializeEventHandlers() { evtMap.initialize(this); } protected static void addEvents(EventMap evtMap) { Widget.addEvents(evtMap); // .. add container-specific events } } public class HBox extends Box { // no initializeEventHandlers(), so it uses the one from Container protected static void addEvents(EventMap evtMap) { Box.addEvents(evtMap); } } public class Box extends Container { // no initializeEventHandlers(), so it uses the one from Container protected static void addEvents(EventMap evtMap) { Container.addEvents(evtMap); } } Now first off, ToggleButton.addEvents() calls Button.addEvents() i.e. the= =20 superclass' addEvents(). But Button.addEvents() call Widget.addEvents()=20 while its superclass is Bin. Bin again calls its superclass' addEvents(),= =20 and so does Container. As a first impression, one would think the=20 Widget.addEvents() in the Button class should be Bin.addEvents(). On the other hand, one can see that the initializeEventHandlers() always=20 also calls initializeEventHandlers() for it's superclass. And since all=20 implementations of initializeEventHandlers() call their superclasses'=20 initializeEventHandlers(), one would think that calling for example=20 Container.addEvents() from Bin.addEvents() wouldn't be necessary. If I understood the code correctly however, this will just result in some= =20 signals being registered twice. I didn't have time to figure out whether=20 there are some checks to avoid duplicate registration. But anyway, becaus= e=20 of the subclass calling the superclass, all events seem to get registered= =20 anyway. As far as I understood, all calls to the parent's addEvents() method coul= d=20 be removed, since the super.initializeEventHandlers() will call the=20 initializatieEventHandlers() for its superclasses as well, eventually=20 initializing all superclasses' signals for the object in question. Now if I got something wrong, please correct me. If you give guidelines=20 for how these really should be, I can see if I could create a patch for=20 the javas too.. Anyway I'll try to implement the OptionMenu events according to=20 ToggleButton's example and see what I can do.. - xkr47 |