All Packages  Class Hierarchy  This Package  Previous  Next  Index

Class jcsp.awt.ActiveMenuItem

java.lang.Object
   |
   +----java.awt.MenuComponent
           |
           +----java.awt.MenuItem
                   |
                   +----jcsp.awt.ActiveMenuItem

public class ActiveMenuItem
extends MenuItem
implements CSProcess

Process Diagram

External View

             ________________
  configure |                | event
 ----->-----| ActiveMenuItem |--->---
            |________________|
 

Internal View

             __________________________________________
            |  ____________      ____________________  |
  configure | |            |    |                    | | event
 ----->-------|  Configure |    | ActionEventHandler |----->---
            | |____________|    |____________________| |
            |                                          |
            |                           ActiveMenuItem |
            |__________________________________________|
 

Description

An ActiveMenuItem is a sub class of MenuItem which uses Channels for event notification and configuration.

If the event Channel is not a null reference an new ActionEventHandler is created with the Channel and is registered as ActionListener with the ActiveMenuItem and has its actionPerformed() method invoked when ActionEvents are generated. Any events generated when the ActionEventHandler is blocked writing to the event Channel are ignored so that the main Java Event Thread is not blocked. The output from the ActionEventHanlder is connected to the event Channel causing an Object to be sent down the Channel when the MenuItem is selected.

To configure the MenuItem 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 Sets the label on the MenuItem to 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 message is discarded
Output Channels
event String The label on the ActiveMenuItem

Example

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

Author:
P.D.Austin
See Also:
ActionEventHandler

Constructor Index

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

Method Index

 o run()
The main body of this process.

Constructors

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

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

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

Parameters:
s - The label on the menu item
ms - The MenuShortcut for the MenuItem
 o ActiveMenuItem
 public ActiveMenuItem(ChannelInput configure,
                       ChannelOutput event)
Constructs a MenuItem with no label, no MenuShortcut 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 ActiveMenuItem
 public ActiveMenuItem(ChannelInput configure,
                       ChannelOutput event,
                       String s)
Constructs a MenuItem with the label s, no MenuShortcut 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 ActiveMenuItem
 public ActiveMenuItem(ChannelInput configure,
                       ChannelOutput event,
                       String s,
                       MenuShortcut ms)
Constructs a MenuItem with the label s, the MenuShortcut ms 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
ms - The MenuShortcut for the MenuItem

Methods

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


All Packages  Class Hierarchy  This Package  Previous  Next  Index