Re: [Java-gnome-developer] OptionMenu events etc..
Brought to you by:
afcowie
From: Jonas B. <jb...@ni...> - 2003-10-04 23:04:31
|
On Fri, 03 Oct 2003 23:47:19 +0300, Jonas Berlin <jb...@ni...>= =20 wrote: > Hi.. I took a look at some of the classes and thought they had some=20 > weird 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 > } > } I did some research, a bunch debug prints in the signal-related codes to=20 test & verify the behaviour. I found out that my previous statements were at least partially correct. The situation is like this: 1. initializeEventHandlers() methods call super.initializeEventHandlers= ()=20 (except for some cases) 2. most addEvents() methods call addEvents() of some superclass, usuall= y=20 <superclass>.addEvents() or then Widget.addEvents. The result from this duplicate behaviour is that some event handlers get=20 registered multiple times. One easy way to test this is to do: LifeCycleListener lcl =3D new LifeCycleListener() { public void lifeCycleEvent(LifeCycleEvent evt) { System.out.println(evt); } }; Button b =3D new Button("foo"); b.addListener(lcl); b.show(); This will display something like: org.gnu.gtk.event.LifeCycleEvent[source=3Dorg.gnu.gtk.Button@18a992f,id=3D= SHOW] org.gnu.gtk.event.LifeCycleEvent[source=3Dorg.gnu.gtk.Button@18a992f,id=3D= SHOW] Now if you change Button to ToggleButton, it instead shows: org.gnu.gtk.event.LifeCycleEvent[source=3Dorg.gnu.gtk.ToggleButton@f72617= ,id=3DSHOW] org.gnu.gtk.event.LifeCycleEvent[source=3Dorg.gnu.gtk.ToggleButton@f72617= ,id=3DSHOW] org.gnu.gtk.event.LifeCycleEvent[source=3Dorg.gnu.gtk.ToggleButton@f72617= ,id=3DSHOW] ----------- Now I suggest the following: 1. make sure all initializeEventHandlers() call=20 super.initializeEventHandlers(), with the only exception being Widget,=20 which is the topmost widget class. 2. remove all <anywidgetclass>.addEvents() calls from the addEvents()=20 methods of the various classes. This way, events should be registered only once, and as a bonus, the code= =20 will most likely be easier to read also =3D) I'll start working on a patch that will fix all widget classes according=20 to my suggestion. If you have some better solution for this then I can tr= y=20 that as well :) - xkr47 |