~ubuntu-branches/ubuntu/precise/jcsp/precise

« back to all changes in this revision

Viewing changes to src/jcsp-demos/doc-ex/jcsp/awt/ActiveCheckboxExample.java

  • Committer: Bazaar Package Importer
  • Author(s): Miguel Landaeta
  • Date: 2010-06-20 18:12:26 UTC
  • Revision ID: james.westby@ubuntu.com-20100620181226-8yg8d9rjjjiuy7oz
Tags: upstream-1.1-rc4
ImportĀ upstreamĀ versionĀ 1.1-rc4

Show diffs side-by-side

added added

removed removed

Lines of Context:
 
1
import java.awt.*;
 
2
import java.awt.event.*;
 
3
import org.jcsp.lang.*;
 
4
import org.jcsp.util.*;
 
5
import org.jcsp.awt.*;
 
6
 
 
7
public class ActiveCheckboxExample {
 
8
 
 
9
  public static void main (String argv[]) {
 
10
 
 
11
    final Frame root = new Frame ("ActiveCheckbox Example");
 
12
 
 
13
    final String[] box = {"Hello World", "Rocket Science", "CSP",
 
14
                          "Monitors", "Ignore Me", "Goodbye World"};
 
15
 
 
16
    final Any2OneChannel event = Channel.any2one (new OverWriteOldestBuffer (10));
 
17
 
 
18
    final ActiveCheckbox[] check = new ActiveCheckbox[box.length];
 
19
    for (int i = 0; i < box.length; i++) {
 
20
      check[i] = new ActiveCheckbox (null, event.out (), box[i]);
 
21
    }
 
22
 
 
23
    root.setSize (300, 200);
 
24
    root.setLayout (new GridLayout (box.length, 1));
 
25
    for (int i = 0; i < box.length; i++) {
 
26
     root.add (check[i]);
 
27
    }
 
28
    root.setVisible (true);
 
29
 
 
30
    new Parallel (
 
31
      new CSProcess[] {
 
32
        new Parallel (check),
 
33
        new CSProcess () {
 
34
          public void run () {
 
35
            boolean running = true;
 
36
            while (running) {
 
37
              final ItemEvent e = (ItemEvent) event.in ().read ();
 
38
              final String item = (String) e.getItem ();
 
39
              if (e.getStateChange () == ItemEvent.SELECTED) {
 
40
                System.out.println ("Checked ==> `" + item + "'");
 
41
                running = (item != box[box.length - 1]);
 
42
              } else {
 
43
                System.out.println ("Unchecked ==> `" + item + "'");
 
44
              }
 
45
            }
 
46
            root.setVisible (false);
 
47
            System.exit (0);
 
48
          }
 
49
        }
 
50
      }
 
51
    ).run ();
 
52
 
 
53
  }
 
54
 
 
55
}