View Javadoc
1   package org.woehlke.computer.kurzweil.tabs.cca;
2   
3   import lombok.EqualsAndHashCode;
4   import lombok.Getter;
5   import lombok.ToString;
6   import lombok.extern.log4j.Log4j2;
7   import org.woehlke.computer.kurzweil.application.ComputerKurzweilContext;
8   import org.woehlke.computer.kurzweil.commons.tabs.TabContext;
9   
10  import java.util.concurrent.ForkJoinTask;
11  
12  import static java.lang.Thread.State.NEW;
13  
14  @Log4j2
15  @Getter
16  @ToString(callSuper = true, exclude = {"tab"})
17  @EqualsAndHashCode(exclude = {"tab"},callSuper = false)
18  public class CyclicCellularAutomatonContext extends ForkJoinTask<Void> implements TabContext, CyclicCellularAutomaton {
19  
20      private final ComputerKurzweilContext ctx;
21      private final CyclicCellularAutomatonCanvas canvas;
22      private final CyclicCellularAutomatonTab tab;
23      private final CyclicCellularAutomatonModel tabModel;
24      private CyclicCellularAutomatonController controller;
25  
26      public CyclicCellularAutomatonContext(
27          CyclicCellularAutomatonTab tab
28      ) {
29          this.tab = tab;
30          this.ctx = tab.getCtx();
31          this.canvas = new CyclicCellularAutomatonCanvas( this);
32          this.tabModel = this.canvas.getCyclicCellularAutomatonModel();
33          this.controller = new CyclicCellularAutomatonController(this);
34      }
35  
36      @Override
37      public void stopController() {
38          this.controller.exit();
39          this.controller = new CyclicCellularAutomatonController(this);
40      }
41  
42      @Override
43      public void startController() {
44          if(this.controller == null){
45              this.controller = new CyclicCellularAutomatonController(this);
46          } else {
47              if(this.controller.getState() != NEW){
48                  this.stopController();
49              }
50          }
51      }
52  
53      @Override
54      public Void getRawResult() {
55          return null;
56      }
57  
58      @Override
59      protected void setRawResult(Void value) {
60  
61      }
62  
63      @Override
64      protected boolean exec() {
65          this.tab.repaint();
66          return true;
67      }
68  }