All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.event.AdjustmentEventHandler

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

public class AdjustmentEventHandler
extends Object
implements CSProcess, AdjustmentListener

Process Diagram

   ________________________
  |                        | event
  | AdjustmentEventHandler |--->---
  |________________________|
 

Description

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

The AdjustmentEventHandler class implements the AdjustmentListener interface and can be used for any component which allows the addition of AdjustmentListeners. When the component is created a new instance of the AdjustmentEventHandler should be created and added as an AdjustmentListeners 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 adjustmentValueChanged() method. The process then wakes up and sends a new Integer set to the current value of the component down the event Channel. Any further calls to adjustmentValueChanged() 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 Integer The Integer representing the current value of the Adjustable component that generated the event.

Example

Extending an Existing Component

 import java.awt.*;
 import jcsp.lang.*;
 import jcsp.awt.event.*;
 public class ChannelScrollbar extends Scrollbar implements CSProcess {
   private AdjustmentEventHandler handler;
   public ChannelScrollbar(ChannelOutput event) {
     super();
     if (event !=null) {
       handler = new AdjustmentEventHandler(event);
       addAdjustmentListener(handler);
     }
   }
   public void run() {
     if (handler != null) {
       handler.run();
     }
   }
 }
 
NOTE: This is in fact how the ActiveScrollbar class is implemented. Except it includes 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();
     Scrollbar scrollbar = new Scrollbar();
     add(scrollbar);
     AdjustmentEventHandler handler = new AdjustmentEventHandler(event);
     scrollbar.addAdjustmentListener(handler);
     new Parallel(new CSProcess[] {
       scrollbar,
       handler,
       new CSProcess() {
         public void run() {
           while (true) {
             Object o = event.read();
             System.out.println("Scrollbar value='" + o);
           }
         }
       }
     }).run();
   }
 }
 

Author:
P.D.Austin

Constructor Index

 o AdjustmentEventHandler(Channel)
Constructs a new AdjustmentEventHandler with the specified event Channel.

Method Index

 o adjustmentValueChanged(AdjustmentEvent)
Invoked when an adjustment occurs on the component the event handler is listening to.
 o run()
The main body of the process.

Constructors

 o AdjustmentEventHandler
 public AdjustmentEventHandler(Channel event)
Constructs a new AdjustmentEventHandler with the specified event Channel.

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

Methods

 o adjustmentValueChanged
 public void adjustmentValueChanged(AdjustmentEvent e)
Invoked when an adjustment occurs on the component the event handler is listening to. Notifies the event process that an AdjustmentEvent has occurred. Some notifications will be lost so there are no guarantees that all events generated will be processed. Sets the value to the current value of the component.

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