All Packages Class Hierarchy This Package Previous Next Index
java.lang.Object
|
+----java.awt.MenuComponent
|
+----java.awt.MenuItem
|
+----java.awt.CheckboxMenuItem
|
+----jcsp.awt.ActiveCheckboxMenuItem
________________________
configure | | event
----->-----| ActiveCheckboxMenuItem |--->---
|________________________|
________________________________________
| ____________ __________________ |
configure | | | | | | event
----->-------| Configure | | ItemEventHandler |----->---
| |____________| |__________________| |
| |
| ActiveCheckboxMenuItem |
|________________________________________|
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).
| 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 |
|
|
| 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. |
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();
}
}
public ActiveCheckboxMenuItem()
public ActiveCheckboxMenuItem(String s)
public ActiveCheckboxMenuItem(String s,
boolean state)
public ActiveCheckboxMenuItem(ChannelInput configure,
ChannelOutput event)
public ActiveCheckboxMenuItem(ChannelInput configure,
ChannelOutput event,
String s)
public ActiveCheckboxMenuItem(ChannelInput configure,
ChannelOutput event,
String s,
boolean state)
public void run()
All Packages Class Hierarchy This Package Previous Next Index