1 package org.woehlke.computer.kurzweil.tabs.cca.control;
2
3 import org.woehlke.computer.kurzweil.tabs.cca.config.ObjectRegistry;
4
5 import java.io.Serializable;
6
7
8
9
10
11
12
13
14
15
16
17 public class CyclicCellularAutomatonController extends Thread
18 implements Runnable, Serializable {
19
20 private static final int THREAD_SLEEP_TIME = 100;
21
22 private static final long serialVersionUID = 3642865135701767557L;
23
24 private Boolean goOn;
25
26 private final ObjectRegistry ctx;
27
28 public CyclicCellularAutomatonController(ObjectRegistry ctx) {
29 this.ctx = ctx;
30 goOn = Boolean.TRUE;
31 }
32
33 public void run() {
34 boolean doIt;
35 do {
36 synchronized (goOn) {
37 doIt = goOn.booleanValue();
38 }
39 ctx.getLattice().step();
40 ctx.getCanvas().repaint();
41 try { sleep(THREAD_SLEEP_TIME); }
42 catch (InterruptedException e) { e.printStackTrace(); }
43 }
44 while (doIt);
45 }
46
47 public void exit() {
48 synchronized (goOn) {
49 goOn = Boolean.FALSE;
50 }
51 }
52
53
54 public void pushButtonVonNeumann() {
55 ctx.getLattice().startVonNeumann();
56 }
57
58 public void pushButtonMoore() {
59 ctx.getLattice().startMoore();
60 }
61
62 public void pushButtonWoehlke() {
63 ctx.getLattice().startWoehlke();
64 }
65 }