All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.event.TextEventHandler

java.lang.Object
   |
   +----jcsp.awt.event.TextEventHandler

public class TextEventHandler
extends Object
implements CSProcess, TextListener

Process Diagram

   __________________
  |                  | event
  | TextEventHandler |--->---
  |__________________|
 

Description

The TextEventHandler class is not intended to be used by software constructors, instead it is used in the construction of new Active AWT components that generate TextEvents (i.e. ActiveTexField, ActiveTexArea).

The TextEventHandler class implements the TextListener interface and can be used for any component which allows the addition of TextListeners. When the component is created a new instance of the TextEventHandler should be created and added as an TextListener to the component. The process must be set running (either asynchronously using ProcessNetwork or as part of a Parallel construct).

The main body of this process waits to be notified by a component invoking the textValueChanged() method. The process then wakes up and sends the String representing the Text down the event Channel. Any further calls to textValueChanged() while the process is writing will be discarded so as not to block the main Java event Thread. When another process reads from the Channel this process loops round and waits to be notified again.

Channel Protocols

Input Channels
Output Channels
event String The String representing the TextEvent from the component that generated the event.

Example

Extending an Existing Component

 import java.awt.*;
 import jcsp.lang.*;
 import jcsp.awt.event.*;
 public class ChannelTextField extends TextField implements CSProcess {
   private TextEventHanlder handler;
   public ChannelTextField(ChannelOutput event, String label) {
     super(s);
     if (event !=null) {
       handler = new TextEventHandler(event);
       addTextListener(handler);
     }
   }
   public void run() {
     if (handler != null) {
       handler.run();
     }
   }
 }
 
NOTE: This is in fact how the ActiveTextField and ActiveTextArea classes are implemented. Except they include an extra CSProcess and Channel for configuring the Component.

Listening to a Component

 import java.awt.*;
 import jcsp.awt.event.*;
 import jcsp.lang.*;
        :
        :
   {
     final Channel event = new One2OneChannel();
     TextField text = new TextField("Active");
     add(text);
     TextEventHandler handler = new TextEventHandler(event);
     text.addTextListener(handler);
     new Parallel(new CSProcess[] {
       text,
       handler,
       new CSProcess() {
         public void run() {
           while (true) {
             Object o = event.read();
             System.out println("TextField '" + o + "' Changed");
           }
         }
       }
     }).run();
   }
 }
 

Author:
P.D.Austin

Constructor Index

 o TextEventHandler(ChannelOutput)
constructs a new TextEventHandler with the specified event Channel.

Method Index

 o run()
The main body of the process.
 o textValueChanged(TextEvent)
Invoked when an Text change occurs on the component the event handler is listening to.

Constructors

 o TextEventHandler
 public TextEventHandler(ChannelOutput event)
constructs a new TextEventHandler with the specified event Channel.

Parameters:
event - The Channel TextEvent notifications are sent down.

Methods

 o textValueChanged
 public void textValueChanged(TextEvent e)
Invoked when an Text change occurs on the component the event handler is listening to. Notifies the event process that an TextEvent has occurred. Some notifications will be lost so there are no guarantees that all events generated will be processed.

Parameters:
e - The parameters associated with this event
 o run
 public void run()
The main body of the process. Executes the functionality described above.


All Packages  Class Hierarchy  This Package  Previous  Next  Index