3. The events framework

introduction

The event framework permits script writers to respond to events that happen inside an applet.

the life of an event

 

event framework

 

event listeners

An event listener is a mapping between an event and a handler to execute when this event occurs.
The listeners table is a Map with events as keys and methods as values (duplicate keys are however allowed).

diputree has three types of listeners:

listeners are single shot by default

A listener will remove himself from the listeners map after he has responded to an event he listened for but before he has executed the handler.

The design rationale for this behavior is that most handlers are single shot and that it would be to cumbersome to force the programmer to remove every listener after it was being used.

You can re-register a listener during the execution of his handler, effectively removing the single shot behavior, or use permanent listeners.

permanent listeners

If you prefix the key of the handler in the listeners table with two plus signs "++", then the listener will not remove its self from the listeners table.

selected

selected is the listeners map that listens for mouse click events on tree entries.

expanded

expanded is the listeners map that listens for mouse click events or keyboard actions that expands containers (nodes).

contracted

contracted is the listeners map that listens for mouse click events or keyboard actions that contract container(nodes).

event handlers

precedence rules

If both internal and external event handlers are defined, then the external event handlers have precedence over internal event handlers. This rule makes it easy to provide for 'fall through' event handling, when external handlers are not available.

internal handlers

Internal handlers are predefined in diputree. There is no external intervention necessary to execute this handlers. The applet just invokes the method with the parameters defined in the internal handler record.

These type of handlers are ALWAYS possible, because the applet takes care of them. So you can always count on them to occur.

external handlers

In scripting you saw how the applet's methods could be invoked from scripting languages. Now we'll see how the applet can invoke script methods through external handlers.

Think of them as call back function from the applet back to the script.

browser support

There are some conditions that must be met before external handlers can take place.