Re: [Xswt-developer] event handlers
Brought to you by:
dvorme
|
From: David J. O. <dj...@co...> - 2006-06-20 03:04:10
|
So it's basically an elegant way to get closures for Java code defined=20
in pnuts, right?
Best regards,
Dave Orme
Hallvard Tr=E6tteberg wrote:
> David,
>
> =20
>>> I've never liked anonymous classes used for creating listeners (new=20
>>> <interface>{ ... }), as they remind me to much of closures without=20
>>> their elegance.
>>> =20
>> Agreed.
>> =20
>>> I'd rather automatically create a wrapper using Proxy which calls a=20
>>> function. E.g. define a Function interface, with (scripting) language=
=20
>>> specific implementations (MethodFunction, PnutsFunction, ...), and=20
>>> IDataParsers for them. Then write a generic IDataParser for listener=20
>>> interfaces, that uses parse(source, Function.class) and wraps it usin=
g=20
>>> Proxy/InvokationHandler. Sounds like a nice hack, doesn't it?
>>> =20
>>> =20
>> I'm not quite following you here. Could you provide a quick=20
>> example of the kind of code this would let you write?
>> =20
>
> The code for this is already checked in. It consists of several parts:
> 1) A Function interface, with IDataParsers for Java methods (and pnuts
> functions in the pnuts extension).
> 2) A generic IDataParser for ANY interface, which reads the source as a
> Function and then returns a Proxy for the desired interface which calls=
the
> Function for the interface's methods. This is used in the example I sen=
t
> some days ago:
>
> <button text=3D"0" selectionListener=3D"handlers.digit"/>
> <script x:id=3D"handlers" lang=3D"pnuts">
> function digit(event)
> calc::appendDigit(event.widget.text);
> </script>
>
> In this example, the pnuts script defines the digit(event) function, wh=
ich
> may be referred to and parsed as a Function by "handlers.digit" ("handl=
ers"
> refers to the script and "digit" to the digit function). The button get=
s a
> selectionListener that is a proxy for the appropriate class, that calls=
the
> digit function, since the generic IDataParser for interfaces knows how =
to
> wrap a Function by a Proxy, so it in effect may implement any specific
> interface. Since the digit function takes one argument, is may handle t=
he
> single method in the SelectionListener interface. BTW, the generic
> IDataParser for interfaces may also wrap a Bindings object (Script
> implements Bindings) and call the function of the same name as the inte=
rface
> method that is invoked.
>
> I'll try to explain this more completely, once it works as I want it to.
>
> Hallvard
>
>
>
> _______________________________________________
> Xswt-developer mailing list
> Xsw...@li...
> https://lists.sourceforge.net/lists/listinfo/xswt-developer
> =20
|