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

« back to all changes in this revision

Viewing changes to src/jcsp-demos/doc-ex/jcsp/awt/ActiveContainerExample.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.util.*;
 
4
import org.jcsp.lang.*;
 
5
import org.jcsp.awt.*;
 
6
 
 
7
public class ActiveContainerExample {
 
8
 
 
9
  public static void main (String argv[]) {
 
10
 
 
11
    final Frame root = new Frame ("ActiveContainer Example");
 
12
 
 
13
    final One2OneChannel mouseEvent = Channel.one2one (new OverWriteOldestBuffer (10));
 
14
 
 
15
    final ActiveContainer container = new ActiveContainer ();
 
16
    container.addMouseEventChannel (mouseEvent.out ());
 
17
 
 
18
    root.add (container);
 
19
    root.setSize (400, 400);
 
20
    root.setVisible (true);
 
21
 
 
22
    new Parallel (
 
23
      new CSProcess[] {
 
24
        container,
 
25
        new CSProcess () {
 
26
          public void run () {
 
27
            boolean running = true;
 
28
            while (running) {
 
29
              final MouseEvent event = (MouseEvent) mouseEvent.in ().read ();
 
30
              switch (event.getID ()) {
 
31
                case MouseEvent.MOUSE_ENTERED:
 
32
                  System.out.println ("MOUSE_ENTERED");
 
33
                break;
 
34
                case MouseEvent.MOUSE_EXITED:
 
35
                  System.out.println ("MOUSE_EXITED");
 
36
                break;
 
37
                case MouseEvent.MOUSE_PRESSED:
 
38
                  System.out.println ("MOUSE_PRESSED");
 
39
                break;
 
40
                case MouseEvent.MOUSE_RELEASED:
 
41
                  System.out.println ("MOUSE_RELEASED");
 
42
                break;
 
43
                case MouseEvent.MOUSE_CLICKED:
 
44
                  if (event.getClickCount() > 1) {
 
45
                    System.out.println ("MOUSE_DOUBLE_CLICKED ... goodbye!");
 
46
                    running = false;
 
47
                  } else {
 
48
                    System.out.println ("MOUSE_CLICKED ... *double* click to quit!");
 
49
                  }
 
50
                break;
 
51
              }
 
52
            }
 
53
            root.setVisible (false);
 
54
            System.exit (0);
 
55
          }
 
56
        }
 
57
      }
 
58
    ).run ();
 
59
  }
 
60
 
 
61
}