All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.event.MouseEventHandler

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

public class MouseEventHandler
extends Object
implements CSProcess, MouseListener

Process Diagram

   ___________________
  |                   | event
  | MouseEventHandler |--->---
  |___________________|
 

Description

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

The MouseEventHandler class implements the MouseListener interface and can be used for any Component which allows the addition of a MouseListener. When the Component is created a new instance of the MouseEventHandler should be created and added as a MouseListener 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 mouseClicked(), mousePressed(), mouseReleased(), mouseEntered() or mouseExited() methods. The process then wakes up and sends the MouseEvent object down the event Channel. Any further calls to the methods 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 MouseEvent The MouseEvent generated by the Component.

Example

Extending an Existing Component

 import java.awt.*;
 import jcsp.lang.*;
 import jcsp.awt.event.*;
 public class ChannelComponent extends Component implements CSProcess {
   ComponentEventHanlder handler;
   public ChannelComponent() {
   }
   public void addMouseEventChannel(ChannelOutput event) {
     if (event !=null) {
       handler = new MouseEventHanlder(event);
       addMouseListener(handler);
     }
   }
   public void run() {
     if (handler != null) {
       handler.run();
     }
   }
 }
 
NOTE: This is in fact how the jcsp awt components add Channels for other event types.

Listening to a Component

 import java.awt.*;
 import jcsp.awt.event.*;
 import jcsp.lang.*;
        :
        :
   {
     final Channel event = new One2OneChannel();
     Component c = new Button("Active");
     add(c);
     MouseEventHanlder handler = new MouseEventHanlder(event);
     c.addMouseListener(handler);
     new Parallel(new CSProcess[] {
       c,
       handler,
       new CSProcess() {
         public void run() {
           while (true) {
             Object o = event.read();
             System.out.println("MouseEvent '" + o);
           }
         }
       }
     }).run();
   }
 }
 

Author:
P.D.Austin

Constructor Index

 o MouseEventHandler(ChannelOutput)
constructs a new MouseEventHandler with the specified output Channel.

Method Index

 o mouseClicked(MouseEvent)
Invoked when the Component the event handler is listening to has a mouse pressed then released.
 o mouseEntered(MouseEvent)
Invoked when the Component the event handler is listening to has a mouse moved into the component.
 o mouseExited(MouseEvent)
Invoked when the Component the event handler is listening to has a mouse move out of the component.
 o mousePressed(MouseEvent)
Invoked when the Component the event handler is listening to has a mouse pressed.
 o mouseReleased(MouseEvent)
Invoked when the Component the event handler is listening to has a mouse released.
 o run()
The main body of the process.

Constructors

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

Parameters:
event - The Channel to send the event notification down

Methods

 o mouseClicked
 public void mouseClicked(MouseEvent e)
Invoked when the Component the event handler is listening to has a mouse pressed then released. Notifies the event process that a MouseEvent has occurred by sending the MouseEvent Object. 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 mousePressed
 public void mousePressed(MouseEvent e)
Invoked when the Component the event handler is listening to has a mouse pressed. Notifies the event process that a MouseEvent has occurred by sending the MouseEvent Object. 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 mouseReleased
 public void mouseReleased(MouseEvent e)
Invoked when the Component the event handler is listening to has a mouse released. Notifies the event process that a MouseEvent has occurred by sending the MouseEvent Object. 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 mouseEntered
 public void mouseEntered(MouseEvent e)
Invoked when the Component the event handler is listening to has a mouse moved into the component. Notifies the event process that a MouseEvent has occurred by sending the MouseEvent Object. 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 mouseExited
 public void mouseExited(MouseEvent e)
Invoked when the Component the event handler is listening to has a mouse move out of the component. Notifies the event process that a MouseEvent has occurred by sending the MouseEvent Object. 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