All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.awt.MenuComponent
|
+----java.awt.MenuItem
|
+----jcsp.awt.ActiveMenuItem
________________
configure | | event
----->-----| ActiveMenuItem |--->---
|________________|
__________________________________________
| ____________ ____________________ |
configure | | | | | | event
----->-------| Configure | | ActionEventHandler |----->---
| |____________| |____________________| |
| |
| ActiveMenuItem |
|__________________________________________|
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).
| Input Channels | ||
|---|---|---|
| configure | String | Sets the label on the MenuItem to the string. |
| MenuShortcut | Sets the MenuShortcut for the item to the MenuShortcut | |
| Boolean |
|
|
| Output Channels | ||
| event | String | The label on the ActiveMenuItem |
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();
}
}
public ActiveMenuItem()
public ActiveMenuItem(String s)
public ActiveMenuItem(String s,
MenuShortcut ms)
public ActiveMenuItem(ChannelInput configure,
ChannelOutput event)
public ActiveMenuItem(ChannelInput configure,
ChannelOutput event,
String s)
public ActiveMenuItem(ChannelInput configure,
ChannelOutput event,
String s,
MenuShortcut ms)
public void run()
All Packages Class Hierarchy This Package Previous Next Index