FESI Event Processing
Author: Jean-MarcLugrin
Description: Describe the FESI EcmaScript extension for event processing
Keywords: EcmaScript, JavaScript, JScript, Java, extension

| Free EcmaScript Interpreter. A JavaScript interpreter written in Java.

Language extensions - Event processing

The event processing mechanism is very similar to the Netscape event processing by the syntax, but differ in its semantic. These differences are required because the goal is different. The `FESI` event processing capability is targeted to the processing of Java 1.1 events (as found in the `AWT`, `Beans` and Swing), and not to a specific browser environment. The event mechanism can be used both for beans and for non bean objects (as long as they follow the Java 1.1 event model).

The `FESI` event processing is capable to handle any Java 1.1 event, the event adaptor is built dynamically as needed.

If `FESI` is used as an embedded scripting capability in another product, the built-in event extension capability can be used or another set of capabilities can be developed, at the programmer choice.

Event procedures are of two kinds: functions (with the event as the parameter) or string to be evaluated. The parsing is done at the time of event establishement and parsing error are raised there. If a string if used, the variable `event` is bound to the first parameter of the handler method. The variable `this` is bound to the object for which the variable was registered. Only one event of a type can be registered on any object (that is on its wrapper). The event handler is unregistered by using `null` as event handler.

`// Common abreviations`
`Frame = java.awt.Frame;`
`Button = java.awt.Button;`

`// Create the GUI`
`f = new Frame("An EcmaScript Frame");`
`f.setSize(200,200)`
`b = new Button("FESI");`
`f.add("Center",b)`
`f.pack();`
`f.show()`

`// Example of using twice the same action - the first one will be`
`// overridden and only the second action will be processed`
`b.onAction = "writeln ('ES Action 1');";`
`b.onAction = "writeln ('ES Action 2');";`

`// The event variable contains the event`
`b.onKeyTyped = "writeln('KEY: ' + event);";`

`// Use of a function - this is the object (wrapper) for which the action was registered`
`function dispose(event) {`
`writeln();`
`writeln("Event received: " + event);`
`writeln("By: " + this);`
`this.dispose();`
`}`
`f.onWindowClosing = dispose;`
`writeln("ready");`
`}`

The event parameter is the Java event value (wrapped as an EcmaScript value), and can be used as any other Java value.
The name of the event is as follow:

1. For event listener which have a single function handler (as `ActionEvent`), either the name of the event or the name of the event handler (preceded by "on") can be used.
2. For event listener which have multiple event handlers (as `WindowEvent`), the name of the function must be used (preceded by "on").

Remarks:

- If there are conflict between these names or with properties or other functions of the same object, you are out of luck.
- When evaluating anything the evaluator locks itself - the same lock is required to process events. This can easily create deadlock!
- Using the Sun JDK, Ctrl-break on Win32, or Ctrl-/ on Solaris will dump out all the active threads and monitors of a running Java apps. That's the fastest way to find out what's causing deadlocks.

Return to the main page

Last update: 12 March 1998