All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.ActiveCheckbox

java.lang.Object
   |
   +----java.awt.Component
           |
           +----java.awt.Checkbox
                   |
                   +----jcsp.awt.ActiveCheckbox

public class ActiveCheckbox
extends Checkbox
implements CSProcess

Process Diagram

External View

             ________________
  configure |                | event
 ----->-----| ActiveCheckbox |--->---
            |________________|
 

Internal View

             ________________________________________
            |  ____________      __________________  |
  configure | |            |    |                  | | event
 ----->-------|  Configure |    | ItemEventHandler |----->---
            | |____________|    |__________________| |
            |                                        |
            |                         ActiveCheckbox |
            |________________________________________|
 

Description

An ActiveCheckbox is a sub class of Checkbox which uses Channels for event notification and configuration.

If the event Channel is not a null reference an new ItemEventHandler is created with the Channel and registered as ItemListener with the ActiveCheckbox and has its itemStateChanged() method invoked when ItemEvents are generated. Any events generated when the ItemEventHandler is blocked writing to the event Channel are ignored so that the main Java Event Thread is not blocked. The output from the ItemEventHanlder is connected to the event Channel causing an Object to be sent down the Channel when the Checkbox is selected.

NOTE: As the component generates two Objects for each event the event Channel must be a One2OneChannel.

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

To configure the Checkbox messages can be sent down the configure channel. If the configure Channel is not a null reference a new Configure is created. The configure process sits in an infinite loop which reads from the configure Channel and configures the component based on the Object received (see table below for details).

Channel Protocols

Input Channels
configure String Change the label for the Checkbox to the value of the String
Boolean
  1. If the Boolean Object refers to the Boolean.TRUE instance the button is made active
  2. If the Boolean Object refers to the Boolean.FALSE instance the button is made inactive
  3. If the Boolean Object refers to any other Boolean instance the state of the Checkbox is set to the value of the Object
Output Channels
event Boolean followed by Integer This component sends two Objects for each event. The first is a Boolean which will be true if the event was for selection false if it was for deselection. The second is an Object representing the item that changed.

Example

 import java.awt.*;
 import jcsp.lang.*;
 import jcsp.awt.*;
 public class CheckboxExample extends Frame {
   public CheckboxExample() {
     super("Checkbox Example");
     final Channel close = new One2OneChannel();
     ActiveCheckbox c = new ActiveCheckbox(null, close, "Close");
     add(c);
     setVisible(true);
     new Parallel(new CSProcess[] {
       c,
       new CSProcess() {
         public void run() {
           close.read();
           close.read();
           setVisible(false);
           System.exit(0);
         }
       }
     }).run();
   }
   public static void main(String argv[]) {
     new CheckboxExample();
   }
 }
 

Author:
P.D.Austin
See Also:
ItemEventHandler

Constructor Index

 o ActiveCheckbox()
Constructs a Checkbox with no label, initial state of false, no configuration Channel and no event Channel.
 o ActiveCheckbox(ChannelInput, ChannelOutput)
Constructs a Checkbox with no label, initial state of false, the configuration Channel configure and the event Channel event.
 o ActiveCheckbox(ChannelInput, ChannelOutput, String)
Constructs a Checkbox with the label s, initial state of false, the configuration Channel configure and the event Channel event.
 o ActiveCheckbox(ChannelInput, ChannelOutput, String, boolean)
Constructs a Checkbox with the label s, initial state of state, the configuration Channel configure and the event Channel event.
 o ActiveCheckbox(ChannelInput, ChannelOutput, String, boolean, CheckboxGroup)
Constructs a Checkbox with the label s, initial state of state, the configuration Channel configure and the event Channel event in the CheckboxGroup group.
 o ActiveCheckbox(String)
Constructs a Checkbox with the label s, initial state of false, no configuration Channel and no event Channel.
 o ActiveCheckbox(String, boolean)
Constructs a Checkbox with the label s, initial state of state, no configuration Channel and no event Channel.
 o ActiveCheckbox(String, boolean, CheckboxGroup)
Constructs a Checkbox with the label s, initial state of state, no configuration Channel and no event Channel.

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.

Constructors

 o ActiveCheckbox
 public ActiveCheckbox()
Constructs a Checkbox with no label, initial state of false, no configuration Channel and no event Channel.

 o ActiveCheckbox
 public ActiveCheckbox(String s)
Constructs a Checkbox with the label s, initial state of false, no configuration Channel and no event Channel.

Parameters:
s - The label displayed on the ActiveCheckbox
 o ActiveCheckbox
 public ActiveCheckbox(String s,
                       boolean state)
Constructs a Checkbox with the label s, initial state of state, no configuration Channel and no event Channel.

Parameters:
s - The label displayed on the ActiveCheckbox
state - the initial state of the checkbox, where true indicates "on" and false indicates "off."
 o ActiveCheckbox
 public ActiveCheckbox(String s,
                       boolean state,
                       CheckboxGroup group)
Constructs a Checkbox with the label s, initial state of state, no configuration Channel and no event Channel. in the CheckboxGroup group.

Parameters:
s - The label displayed on the ActiveCheckbox
state - the initial state of the checkbox, where true indicates "on" and false indicates "off."
group - The CheckboxGroup the Checkbox is in
 o ActiveCheckbox
 public ActiveCheckbox(ChannelInput configure,
                       ChannelOutput event)
Constructs a Checkbox with no label, initial state of false, the configuration Channel configure and the event Channel event.

Parameters:
configure - The Channel configuration events should be sent down. Can be null if no configuration is required.
event - The Channel events will be notified down when the button is pressed. Can be null if events are going to be ignored.
 o ActiveCheckbox
 public ActiveCheckbox(ChannelInput configure,
                       ChannelOutput event,
                       String s)
Constructs a Checkbox with the label s, initial state of false, the configuration Channel configure and the event Channel event.

Parameters:
configure - The Channel configuration events should be sent down. Can be null if no configuration is required.
event - The Channel events will be notified down when the button is pressed. Can be null if events are going to be ignored.
s - The label displayed on the ActiveCheckbox
 o ActiveCheckbox
 public ActiveCheckbox(ChannelInput configure,
                       ChannelOutput event,
                       String s,
                       boolean state)
Constructs a Checkbox with the label s, initial state of state, the configuration Channel configure and the event Channel event.

Parameters:
configure - The Channel configuration events should be sent down. Can be null if no configuration is required.
event - The Channel events will be notified down when the button is pressed. Can be null if events are going to be ignored.
s - The label displayed on the ActiveCheckbox
state - the initial state of the checkbox, where true indicates "on" and false indicates "off."
 o ActiveCheckbox
 public ActiveCheckbox(ChannelInput configure,
                       ChannelOutput event,
                       String s,
                       boolean state,
                       CheckboxGroup group)
Constructs a Checkbox with the label s, initial state of state, the configuration Channel configure and the event Channel event in the CheckboxGroup group.

Parameters:
configure - The Channel configuration events should be sent down. Can be null if no configuration is required.
event - The Channel events will be notified down when the button is pressed. Can be null if events are going to be ignored.
s - The label displayed on the ActiveCheckbox
state - the initial state of the checkbox, where true indicates "on" and false indicates "off."
group - The CheckboxGroup the Checkbox is in

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