All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.ActiveCheckboxMenuItem

java.lang.Object
   |
   +----java.awt.MenuComponent
           |
           +----java.awt.MenuItem
                   |
                   +----java.awt.CheckboxMenuItem
                           |
                           +----jcsp.awt.ActiveCheckboxMenuItem

public class ActiveCheckboxMenuItem
extends CheckboxMenuItem
implements CSProcess

Process Diagram

External View

             ________________________
  configure |                        | event
 ----->-----| ActiveCheckboxMenuItem |--->---
            |________________________|
 

Internal View

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

Description

An ActiveCheckboxMenuItem is a sub class of CheckboxMenuItem 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 ActiveCheckboxMenuItem 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 CheckboxMenuItem is selected.

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

To configure the CheckboxMenuItem 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 CheckboxMenuItem to the value of the String
MenuShortcut Sets the MenuShortcut for the item to the MenuShortcut
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 CheckboxMenuItem is set to the value of the Object
Output Channels
event Boolean followed by String 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 String representing the item that changed.

Example

 import java.awt.*;
 import jcsp.lang.*;
 import jcsp.awt.*;
 public class CheckboxMenuItemExample extends Frame {
   public CheckboxMenuItemExample() {
     super("Checkbox Menu Item Example");
     final Channel close = new One2OneChannel();
     MenuBar mb = new MenuBar();
     setMenuBar(mb);
     Menu fileMenu = new Menu("File");
     mb.add(fileMenu);
     ActiveCheckboxMenuItem b = new ActiveCheckboxMenuItem(null, close, "Close", true);
     fileMenu.add(b);
     setVisible(true);
     new Parallel(new CSProcess[] {
       b,
       new CSProcess() {
         public void run() {
           Boolean state = (Boolean)close.read();
           String item = (String)close.read();
           if (state.booleanValue()) {
             setVisible(false);
             System.exit(0);
           }
         }
       }
     }).run();
   }
   public static void main(String argv[]) {
     new CheckboxMenuItemExample();
   }
 }
 

Author:
P.D.Austin
See Also:
ActionEventHandler

Constructor Index

 o ActiveCheckboxMenuItem()
Constructs a MenuItem with no label and no configuration Channel and the event Channel event.
 o ActiveCheckboxMenuItem(ChannelInput, ChannelOutput)
Constructs a MenuItem with no label and the configuration Channel configure and the event Channel event.
 o ActiveCheckboxMenuItem(ChannelInput, ChannelOutput, String)
Constructs a MenuItem with the label s and the configuration Channel configure and the event Channel event.
 o ActiveCheckboxMenuItem(ChannelInput, ChannelOutput, String, boolean)
Constructs a MenuItem with the label s and the configuration Channel configure and the event Channel event.
 o ActiveCheckboxMenuItem(String)
Constructs a MenuItem with the label s and no configuration Channel and the event Channel event.
 o ActiveCheckboxMenuItem(String, boolean)
Constructs a MenuItem with the label s and no configuration Channel and the event Channel event.

Method Index

 o run()
The main body of this process.

Constructors

 o ActiveCheckboxMenuItem
 public ActiveCheckboxMenuItem()
Constructs a MenuItem with no label and no configuration Channel and the event Channel event.

 o ActiveCheckboxMenuItem
 public ActiveCheckboxMenuItem(String s)
Constructs a MenuItem with the label s and no configuration Channel and the event Channel event.

Parameters:
s - The label on the menu item
 o ActiveCheckboxMenuItem
 public ActiveCheckboxMenuItem(String s,
                               boolean state)
Constructs a MenuItem with the label s and no configuration Channel and the event Channel event.

Parameters:
s - The label on the menu item
state - the initial state of the menu item, where true indicates "on" and false indicates "off."
 o ActiveCheckboxMenuItem
 public ActiveCheckboxMenuItem(ChannelInput configure,
                               ChannelOutput event)
Constructs a MenuItem with no label and 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 ActiveCheckboxMenuItem
 public ActiveCheckboxMenuItem(ChannelInput configure,
                               ChannelOutput event,
                               String s)
Constructs a MenuItem with the label s and 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 on the menu item
 o ActiveCheckboxMenuItem
 public ActiveCheckboxMenuItem(ChannelInput configure,
                               ChannelOutput event,
                               String s,
                               boolean state)
Constructs a MenuItem with the label s and 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 on the menu item
state - the initial state of the menu item, where true indicates "on" and false indicates "off."

Methods

 o run
 public void run()
The main body of this process.


All Packages  Class Hierarchy  This Package  Previous  Next  Index