View Javadoc
1   package org.woehlke.computer.kurzweil.cyclic.cellular.automaton.control;
2   
3   import org.woehlke.computer.kurzweil.cyclic.cellular.automaton.config.ObjectRegistry;
4   
5   import java.io.Serializable;
6   
7   /**
8    * Cyclic Cellular Automaton.
9    * <p>
10   * (C) 2006 - 2022 Thomas Woehlke.
11   * @see <a href="https://java.woehlke.org/cyclic-cellular-automaton">Maven Project Page</a>
12   *
13   * @author Thomas Woehlke
14   * <p>
15   * Date: 05.02.2006
16   * Time: 00:36:20
17   */
18  public class CyclicCellularAutomatonController extends Thread
19      implements Runnable, Serializable {
20  
21      private static final int THREAD_SLEEP_TIME = 100;
22  
23      private static final long serialVersionUID = 3642865135701767557L;
24  
25      private Boolean goOn;
26  
27      private final ObjectRegistry ctx;
28  
29      public CyclicCellularAutomatonController(ObjectRegistry ctx) {
30          this.ctx = ctx;
31          goOn = Boolean.TRUE;
32      }
33  
34      public void run() {
35          boolean doIt;
36          do {
37              synchronized (goOn) {
38                  doIt = goOn.booleanValue();
39              }
40              ctx.getLattice().step();
41              ctx.getCanvas().repaint();
42              try {
43                  sleep(THREAD_SLEEP_TIME);
44              } catch (InterruptedException e) {
45                  e.printStackTrace();
46              }
47          }
48          while (doIt);
49      }
50  
51      public void exit() {
52          synchronized (goOn) {
53              goOn = Boolean.FALSE;
54          }
55      }
56  
57  
58      public void pushButtonVonNeumann() {
59          ctx.getLattice().startVonNeumann();
60      }
61  
62      public void pushButtonMoore() {
63          ctx.getLattice().startMoore();
64      }
65  
66      public void pushButtonWoehlke() {
67          ctx.getLattice().startWoehlke();
68      }
69  }