title logo

Handling new personalized events

Addition of new listeners

By default, the class XBMapper which assures the mapping between Java Beans components and a XML document implements BeanEditListener, ActionListener, PropertyChangeListener, ContainerListener and CaretListener. To be able to handle other kind of events, one needs to specialize XBMapper in a new class implementing new listeners. The methods activated when an event is received have simply to call reflectBeanUpdate with the originator of the event as parameter. The example below presents a class which handle key events :

public class myXBMapper extends XBMapper implements KeyListener {
  /**
   * called when a key has been typed
   *
   *  @param e            the fired event
   **/
  void keyTyped(KeyEvent e) {
    // call the method to reflect the modifications
    // made on the source bean
    reflectBeanUpdate(e.getSource());
  }

  /**
   * called when a key has been pressed
   *
   *  @param e            the fired event
   **/
  void keyPressed(KeyEvent e) {
    // nothing to do, we reacts only when a key is pressed
  }

  /**
   * called when a key has been released
   *
   *  @param e            the fired event
   **/
  void keyReleased(KeyEvent e) {
    // nothing to do, we reacts only when a key is pressed
  }
}

Association of a script to a new event

In a Bean Markup description, it is possible to associate a script to certain events as below:

<event-binding name="action">
  <script>
    <fire-event type="end"/>
  </script>
</event-binding>

To be able to execute the script when the event is fired, one need to define a class implemening the event listener. The methods activated when an event is received must delegate the processing to the method processEvent of the class fr.inria.ketuk.ScriptEventProcessor. Below is the code of the class ScriptActionHandler which call the execution of a script when an action event is received

package fr.inria.ketuk.scriptEventHandler;

import fr.inria.ketuk.*;
import java.awt.event.*;

/**
 * A listener class which handle action events
 *
 * @author Claude Pasquier
 */
  
public class ScriptActionHandler implements ActionListener {
      
  public void actionPerformed(ActionEvent event) {
    ScriptEventProcessor p = new ScriptEventProcessor();
    p.processEvent(event, "actionPerformed");
  }
}

The class used to handle event associated with scripts must be declared in the configuration file as below:

<register type="eventHandler" name="action"
          class="fr.inria.ketuk.scriptEventHandler.ScriptActionHandler"/>
blank horizontal line
Made with CSS Valid XHTML 1.0! Valid CSS! Copyright © 2000 INRIA, Dyade, Bull
Created by Claude Pasquier