Re: [java-gnome-hackers] event code
Brought to you by:
afcowie
|
From: Philip A. C. <pc...@td...> - 2002-08-13 16:14:05
|
Jeff,
Thanks for this reference implementation.
I do not belive the removeFocusListener will work because a
WeakReference was added into the Vector, but a listener is being
removed. I've checked in a few changes that should take care of this
issue. However, the code changes I've made *should* work as well. I
like the idea of using Vector rather than WeakHashMap as the Vector
should be thread-safe without extra work Perhaps we need a WeakVector
(subclass of Vector) so that the findFocusListener code does not have to
be implemented for every single listener Vector we use?
What do you think of creating a FocusEvent with a type property. That
way, the listener could implement a single method and tell what kind of
focus event it received by the type property of the FocusEvent.
interface FocusListener
{
public void focusEventFired(FocusEvent event);
}
class MyFocusListener
extends FocusListener
{
public void focusEventFired(FocusEvent event)
{
if (FocusEvent.getType() =3D=3D FocusEventType.GOT_FOCUS()) {
// Do Something
else if (FocusEvent.getType() =3D=3D FocusEventType.LOST_FOCUS()) {
// Do Something different
} // Else, I don't want to handle it.
}
}
For this example, it doesn't change much; maybe it even huts some.=20
However, for a "class" of events which have a lot of different types,
this may be easier to work with than a lot of different method calls.
On Tue, 2002-08-13 at 10:07, Jeffrey Morgan wrote:
> I have just checked very basic code for event handling
> into cvs. If you check the gtk.Widget class you can
> see very simple handling for the focus events. This
> can serve the basis of our dicussion.
>=20
> -Jeff
--=20
Philip A. Chapman
|