Methods | This Package | All Packages
Defines an event of a component.
MemberInfo
|
+--EventInfo
package com.ms.wfc.core
public final class EventInfo
extends MemberInfo
Remarks
Events allow you to get run-time notifications from a component. The EventInfo class is used within the component's ClassInfo inner class. When you create an EventInfo object, you specify the component class, the name of the event, the associated delegate, and the various attributes of the event. (Attributes can be specified using the classes that extend MemberAttribute.)
The following example shows a portion of the ClassInfo of the Control class:
public static class ClassInfo extends Component.ClassInfo {
public static final EventInfo click = new EventInfo(
Control.class, "click", EventHandler.class,
CategoryAttribute.Action,
new DescriptionAttribute("Occurs when the control is clicked."));
public static final EventInfo keyDown = new EventInfo(
Control.class, "keyDown", KeyEventHandler.class,
CategoryAttribute.Key,
new DescriptionAttribute("Occurs when a key is first pressed."));
public void getEvents(IEvents events) {
super.getEvents(events);
events.add(click);
events.add(keyDown);
}
}
Every event has a structure through which it passes its information. The base structure is the Event class, from which all other event structures derive. To handle the event, you define a method that takes a source object (the object that triggered the event) and a structure particular to that event. This handler is assigned to the event through a delegate. The following code shows a simple example:
class MyClass {
Button button1 = new Button();
// Define the handler for the click event.
void button1_click(Object sender, Event e) {
... // Handle the event.
}
public MyClass() {
// Assign the handler to the event through a delegate.
button1.addOnClick(new EventHandler(this.button1_click));
}
}
For each event defined through EventInfo, the component class must implement the following methods, which add and remove delegates and trigger the event, respectively:
public void addOn<EventName>( <EventStructure>Handler handler )
public void removeOn<EventName>( <EventStructure>Handler handler )
protected void on<EventName>( <EventStructure> e )
The <EventStructure>Handler parameter is a delegate, which is typically declared as follows:
public multicast delegate void <EventStructure>Handler( Object sender, <EventStructure> e );
The syntax of the delegate specifies the syntax of the handler method. Note that if the delegate is declared as multicast, multiple handlers can be added. For more information about delegates and the WFC event model, see Handling Events in WFC.
Note An event name typically begins with a lowercase letter, while the case of the associated methods is mixed. For example, an event named doubleClick is associated with addOnDoubleClick, removeOnDoubleClick, and onDoubleClick methods.
An EventInfo object can be obtained programmatically through the ComponentManager class.
See Also PropertyInfo, ExtenderInfo