Re: [Xswt-developer] event handlers
Brought to you by:
dvorme
|
From: <ha...@id...> - 2006-06-21 07:23:26
|
> -----Original Message----- > Date: Mon, 19 Jun 2006 22:03:46 -0500 > From: "David J. Orme" <dj...@co...> > Subject: Re: [Xswt-developer] event handlers > To: xsw...@li... > > So it's basically an elegant way to get closures for Java > code defined in pnuts, right? Yes, there's two kinds of script-based listeners that may be attached to an SWT control: 1) When the value (an IDREF) of an xxxListener attribute refers to a script as a whole, the installed proxy looks up the method name and calls that Function, if it exists. This makes it easy to make a script covering all methods in an interface. 2) When the value (an IDREF) of an xxxListener attribute refers to a Function (in a script), the installed proxy calls that Function directly, which only makes sense for single-method interfaces or interfaces where the arguments are the same for all methods and the arguments contain enough information about the event. This is usually the case for GUI event handlers, which makes it easy to write a long script with functions for handling all the related controls in a form. This is used in the calculator example: There's one script for basic math functions (just to test modularisation), there's one script for the calculator "model" and one for the event handlers. This technique should work for any scripting language, not just pnuts, as long as the script functions may be wrapped in a Function. I.e. the Function interface is the bridge and each scripting language should have a corresponding wrapper, like PnutsFunctionFunction (pnuts' function class is PnutsFunction, hence the wrapper is called PnutsFunctionFunction instead of just PnutsFunction :-). Hallvard |