All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.ActiveCanvas

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Canvas
                   |
                   +----jcsp.awt.ActiveCanvas

public class ActiveCanvas
extends Canvas
implements CSProcess

Process Diagram

  ________________
 |                |
 |  ActiveCanvas  |
 |________________|
 

Description

An ActiveCanvas is a sub class of Canvas which uses Channels for event notification.

It is possible to register Channels to be used to notify the occurrence of other types of Event that the Canvas generates. This can be done by calling one of the addXXXXEventChannel() methods.

Channel Protocols

Input Channels
Output Channels

Example

 import java.awt.*;
 import jcsp.lang.*;
 import jcsp.awt.*;
 public class CanvasExample extends Frame {
   public CanvasExample() {
     super("Canvas Example");
     final Channel event = new One2OneChannel();
     final Channel id = new One2OneChannel();
     ActiveCanvas c = new ActiveCanvas();
     c.addMouseEventChannel(event);
     add(c);
     setVisible(true);
     new Parallel(new CSProcess[] {
       c,
       new EventIDFilter(event, id),
       new CSProcess() {
         public void run() {
           Integer i = (Integer)id.read();
           if (i.intValue() == MouseEvent.MOUSE_CLICKED) {
             setVisible(false);
             System.exit(0);
           }
         }
       }
     }).run();
   }
   public static void main(String argv[]) {
     new CanvasExample();
   }
 }
 

Author:
P.D.Austin

Variable Index

 o par
The Parallel construct containing the processes to be executed by this CSProcess.

Constructor Index

 o ActiveCanvas()
Constructs a new ActiveCanvas.

Method Index

 o addComponentEventChannel(ChannelOutput)
Add a new Channel to the Component which will be used to notify that a ComponentEvent has occurred on the component.
 o addFocusEventChannel(ChannelOutput)
Add a new Channel to the Component which will be used to notify that a FocusEvent has occurred on the component.
 o addKeyEventChannel(ChannelOutput)
Add a new Channel to the Component which will be used to notify that a KeyEvent has occurred on the component.
 o addMouseEventChannel(ChannelOutput)
Add a new Channel to the Component which will be used to notify that a MouseEvent has occurred on the component.
 o addMouseMotionEventChannel(ChannelOutput)
Add a new Channel to the Component which will be used to notify that a MouseMotionEvent has occurred on the component.
 o run()
The main body of this process.

Variables

 o par
 protected Parallel par
The Parallel construct containing the processes to be executed by this CSProcess.

Constructors

 o ActiveCanvas
 public ActiveCanvas()
Constructs a new ActiveCanvas.

Methods

 o addComponentEventChannel
 public void addComponentEventChannel(ChannelOutput componentEvent)
Add a new Channel to the Component which will be used to notify that a ComponentEvent has occurred on the component. This should be used instead of registering a ComponentListener with the component. It is possible to add more than one Channel by calling this method multiple times If the reference passed is null no action will be taken. Otherwise a new ComponentEventHanlder will be generated for the Channel so that each Channel operates independently of the others.

NOTE: This method must be called before this process is run otherwise it will not function correctly.

Parameters:
componentEvent - The channel to send component events down. If the Channel is to be shared with other events it should be a Many2OneChannel.
See Also:
ComponentEventHandler
 o addFocusEventChannel
 public void addFocusEventChannel(ChannelOutput focusEvent)
Add a new Channel to the Component which will be used to notify that a FocusEvent has occurred on the component. This should be used instead of registering a FocusListener with the component. It is possible to add more than one Channel by calling this method multiple times If the reference passed is null no action will be taken. Otherwise a new FocusEventHanlder will be generated for the Channel so that each Channel operates independently of the others.

NOTE: This method must be called before this process is run otherwise it will not function correctly.

Parameters:
focusEvent - The channel to send focus events down. If the Channel is to be shared with other events it should be a Many2OneChannel.
See Also:
FocusEventHandler
 o addKeyEventChannel
 public void addKeyEventChannel(ChannelOutput keyEvent)
Add a new Channel to the Component which will be used to notify that a KeyEvent has occurred on the component. This should be used instead of registering a KeyListener with the component. It is possible to add more than one Channel by calling this method multiple times If the reference passed is null no action will be taken. Otherwise a new KeyEventHanlder will be generated for the Channel so that each Channel operates independently of the others.

NOTE: This method must be called before this process is run otherwise it will not function correctly.

Parameters:
keyEvent - The channel to send key events down. If the Channel is to be shared with other events it should be a Many2OneChannel.
See Also:
KeyEventHandler
 o addMouseEventChannel
 public void addMouseEventChannel(ChannelOutput mouseEvent)
Add a new Channel to the Component which will be used to notify that a MouseEvent has occurred on the component. This should be used instead of registering a MouseListener with the component. It is possible to add more than one Channel by calling this method multiple times If the reference passed is null no action will be taken. Otherwise a new MouseEventHanlder will be generated for the Channel so that each Channel operates independently of the others.

NOTE: This method must be called before this process is run otherwise it will not function correctly.

Parameters:
mouseEvent - The channel to send key events down. If the Channel is to be shared with other events it should be a Many2OneChannel.
See Also:
MouseEventHandler
 o addMouseMotionEventChannel
 public void addMouseMotionEventChannel(ChannelOutput mouseMotionEvent)
Add a new Channel to the Component which will be used to notify that a MouseMotionEvent has occurred on the component. This should be used instead of registering a MouseMotionListener with the component. It is possible to add more than one Channel by calling this method multiple times If the reference passed is null no action will be taken. Otherwise a new MouseMotionEventHanlder will be generated for the Channel so that each Channel operates independently of the others.

NOTE: This method must be called before this process is run otherwise it will not function correctly.

Parameters:
mouseMotionEvent - The channel to send key events down. If the Channel is to be shared with other events it should be a Many2OneChannel.
See Also:
MouseMotionEventHandler
 o run
 public void run()
The main body of this process.


All Packages  Class Hierarchy  This Package  Previous  Next  Index