1 package org.woehlke.computer.kurzweil.tabs.cca;
2
3
4 import lombok.EqualsAndHashCode;
5 import lombok.Getter;
6 import lombok.ToString;
7 import lombok.extern.log4j.Log4j2;
8 import org.woehlke.computer.kurzweil.tabs.ComputerKurzweilTabbedPane;
9 import org.woehlke.computer.kurzweil.tabs.TabPanel;
10 import org.woehlke.computer.kurzweil.tabs.Tab;
11 import org.woehlke.computer.kurzweil.tabs.TabType;
12
13 import java.awt.event.ActionEvent;
14
15 @Log4j2
16 @Getter
17 @ToString(callSuper = true, exclude = {"tabCtx"})
18 @EqualsAndHashCode(callSuper=true, exclude = {"tabCtx"})
19 public class CyclicCellularAutomatonTab extends TabPanel implements Tab, CyclicCellularAutomaton {
20
21 private final TabType tabType = TabType.CYCLIC_CELLULAR_AUTOMATON;
22 private final CyclicCellularAutomatonContext tabCtx;
23 private final CyclicCellularAutomatonCanvas canvas;
24 private final CyclicCellularAutomatonModel tabModel;
25
26 private final CyclicCellularAutomatonTabPane cyclicCellularAutomatonTabPane;
27
28 public CyclicCellularAutomatonTab(ComputerKurzweilTabbedPane tabbedPane) {
29 super(tabbedPane, TAB_TYPE);
30 this.tabCtx = new CyclicCellularAutomatonContext(this);
31 this.canvas = this.tabCtx.getCanvas();
32 this.tabModel = this.canvas.getCyclicCellularAutomatonModel();
33 this.cyclicCellularAutomatonTabPane = new CyclicCellularAutomatonTabPane(this);
34 this.add(this.panelSubtitle);
35 this.add(this.canvas);
36 this.add(this.cyclicCellularAutomatonTabPane);
37 this.ctx.getFrame().pack();
38 this.tabModel.stop();
39 this.cyclicCellularAutomatonTabPane.stop();
40 }
41
42 @Override
43 public void start() {
44 log.info("start");
45 this.tabModel.start();
46 this.cyclicCellularAutomatonTabPane.start();
47 this.getTabCtx().startController();
48 this.getTabCtx().getController().start();
49 this.ctx.getFrame().pack();
50 int x = this.canvas.getWidth();
51 int y = this.canvas.getHeight();
52 log.info("started with canvas x="+x+" y="+y);
53 }
54
55 @Override
56 public void stop() {
57 log.info("stop");
58 this.tabModel.stop();
59 this.cyclicCellularAutomatonTabPane.stop();
60 this.getTabCtx().stopController();
61 int x = this.canvas.getWidth();
62 int y = this.canvas.getHeight();
63 log.info("stopped with canvas x="+x+" y="+y);
64 }
65
66 @Override
67 public void actionPerformed(ActionEvent ae) {
68 if (ae.getSource() == this.cyclicCellularAutomatonTabPane.getButtonVonNeumann()) {
69 this.tabModel.startWithNeighbourhoodVonNeumann();
70 this.start();
71 } else if (ae.getSource() == this.cyclicCellularAutomatonTabPane.getButtonMoore()) {
72 this.tabModel.startWithNeighbourhoodMoore();
73 this.start();
74 } else if (ae.getSource() == this.cyclicCellularAutomatonTabPane.getButtonWoehlke()) {
75 this.tabModel.startWithNeighbourhoodWoehlke();
76 this.start();
77 }
78 if(ae.getSource() == this.cyclicCellularAutomatonTabPane.getStartButton()){
79 super.ctx.getFrame().start();
80 }
81 if(ae.getSource() == this.cyclicCellularAutomatonTabPane.getStopButton()){
82 super.ctx.getFrame().stop();
83 }
84 }
85 }