Scripting the techexplorer Hypermedia Browser

Event monitor


The feature described is only available in the Professional Edition of techexplorer.

This section describes the EventMonitor Java applet. This applet provides a dynamic textual representation of events triggered by techexplorer instances, as well as a mechanism for toggling such events.

The EventMonitor applet displays events fired by two techexplorer instances in a Java text area. The EventMonitor also provides Java checkboxes for registering/removing techexplorer event listeners, as well as for enabling/disabling event flow to either techexplorer instance.

This example expands on the concepts learned through the development of the GraphIT application since it makes use of every form of event available in the techexplorer Java API.

This section is divided into the four essential components that a Java applet must implement for handling techexplorer events. First, we detail the statements for importing the appropriate techexplorer classes. Second, we put forth the code declaring that the EventMonitor class implements a particular listener interface. Third, we explain the statements that register an instance of the EventMonitor class with techexplorer. Fourth, we describe the implementation of the methods in the listener interface.

When we are finished with the above, we can experiment with techexplorer events!

Importing the appropriate techexplorer classes

The import statement makes Java classes available to the current class under an abbreviated name. The * (star) form of the import statement makes all classes in a package available by their class name.
import java.awt.*;
import java.applet.Applet;
import ibm.techexplorer.techexplorer;
import ibm.techexplorer.control.techexplorerControl;
import ibm.techexplorer.axtchexp.AxTchExpRaw;
import ibm.techexplorer.event.InstanceEvent;
import ibm.techexplorer.event.InstanceListener;
import ibm.techexplorer.awt.AWTEvent;
import ibm.techexplorer.awt.event.KeyListener;
import ibm.techexplorer.awt.event.KeyEvent;
import ibm.techexplorer.awt.event.FocusListener;
import ibm.techexplorer.awt.event.FocusEvent;
import ibm.techexplorer.awt.event.MouseEvent;
import ibm.techexplorer.awt.event.MouseListener;
import ibm.techexplorer.awt.event.MouseMotionListener;
The EventMonitor implements the InstanceListener, MouseListener, MouseMotionListener, KeyListener, and FocusListener interfaces, as well as uses the InstanceEvent, MouseEvent, KeyEvent, FocusEvent, and AWTEvent events. The ibm.techexplorer.techexplorer class provides a crowss web browser interface between Java applets, JavaScript, HTML Elements and techexplorer.

Declaring the EventMonitor class

In Java, a class can inherit implementations from only one superclass. Java provides a form of "multiple inheritance" through interfaces in that a Java class can inherit additional abstract methods from interfaces so long as the class provides an implementation. In order for the EventMonitor to implement an interface, it declares the interfaces in an Implements clause.
public class EventMonitor extends java.applet.Applet implements 
   InstanceListener, KeyListener, FocusListener, MouseListener, MouseMotionListener   {

  techexplorer       EventMonitorObject1  = null;
  techexplorer       EventMonitorObject2  = null;
  ...
}
This fragment shows how the EventMonitor is defined as a class that extends java.applet.Applet and implements the InstanceListener, MouseListener, MouseMotionListener, KeyListener and FocusListener interfaces. EventMonitorObject1 and EventMonitorObject2 are Java objects that represent the two different techexplorer instances.

Register an instance of the EventMonitor class with techexplorer

For a Java applet to receive notification of techexplorer events, the applet must register a listener with techexplorer. The ibm.techexplorer.techexplorer class provides methods for listener management. See the GraphIT application and the AWTEvent annotated reference for more information about techexplorer listeners and events.

The init() method creates and initializes the graphical user interface. A user of this applet can toggle techexplorer event listeners and event flow via Java checkboxes. The EventMonitor uses the start() method to register as a listener to all techexplorer events fired by EventMonitorObject1 and EventMonitorObject2 techexplorer instances, as well as to initialize each listener checkbox. EventMonitorObject1 and EventMonitorObject2 correspond to two techexplorer instances that have been embedded in the HTML source and given the HTML object names "TEEventAreaControl1" and "TEEventAreaControl2" or TEEventAreaPlugin1" and "TEEventAreaPlugin2", respectively. The actual name will depend on whether the ActiveX control or plug-in version of techexplorer is being used.

The following HTML embeds the techexplorer event areas in a browser window.

    <OBJECT NAME="TEEventAreaControl1" CLASSID="clsid:5AFAB315-AD87-11D3-98BB-002035EFB1A4" WIDTH=290 HEIGHT=150>
       <PARAM NAME="DataType" VALUE="0">
       <PARAM NAME="Data" VALUE="\sf\pagecolor{white}\huge\color{black}IBM techexplorer\newline Event area 1">
       <EMBED NAME="TEEventAreaPlugin1" TYPE="application/x-techexplorer"
          TEXDATA="\sf\pagecolor{white}\huge\color{black}IBM techexplorer\newline Event area 1"
          WIDTH=290 HEIGHT=150>
       </EMBED>
    </OBJECT>
    ...
    <OBJECT NAME="TEEventAreaControl2" CLASSID="clsid:5AFAB315-AD87-11D3-98BB-002035EFB1A4" WIDTH=290 HEIGHT=150>
       <PARAM NAME="DataType" VALUE="0">
       <PARAM NAME="Data" VALUE="\sf\pagecolor{white}\huge\color{black}IBM techexplorer\newline Event area 2">
       <EMBED NAME="TEEventAreaPlugin2" TYPE="application/x-techexplorer"
          TEXDATA="\sf\pagecolor{white}\huge\color{black}IBM techexplorer\newline Event area 2"
          WIDTH=290 HEIGHT=150>
       </EMBED>
    </OBJECT>

For information about obtaining cross web browser handles to the ibm.techexplorer.techexplorer instance revisit our discussion, of the Java Editor applet. The stop() method is employed to remove any remaining listeners from both the EvenMonitorPlugin1 and EvenMonitorPlugin2 event listener list.

Implementation of the methods in the listener interface

The EventMonitor provides implementations for all of the methods in InstanceListener, MouseListener, MouseMotionListener, KeyListener, and FocusListener interfaces, namley focusGained, focusLost, instanceDelete, keyPressed, keyReleased, keyTyped, mouseClicked, mouseDragged, mouseEntered, mouseExited, mouseMoved, mousePressed, and mouseRelease. Listener interface methods are called as a result of particular events triggered by a techexplorer instance. Each listener interface method obtains the HTML object name of the techexplorer instance that fired the event and displays an informative message in a Java text area. Here is a sample session:

For each techexplorer event area, the EventMonitor applet provides Java checkboxes for registering/removing techexplorer event listeners, as well as for enabling/disabling event flow to a particular techexplorer instance.

This sample display indicates that focus and mouse motion events from both event areas are not propagated to the EventMonitor applet. Note that enabling or disabling the flow of events to a particular techexplorer instance does not effect the event flow to techexplorer listeners. Click here for the whole program. Note that since some browsers do not support Java 1.1, the EventMonitor applet is Java 1.0 compliant.

Now it's time to experiment with techexplorer events!

Click to try the EventMonitor.


Click here to to view the previous section. Click here to to view the next section.

IBM techexplorer Hypermedia Browser is a trademark of the IBM Corporation. Send comments and questions to techexpl@us.ibm.com.