1 package org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.model;
2
3 import lombok.Getter;
4 import lombok.extern.java.Log;
5 import org.woehlke.computer.kurzweil.application.ComputerKurzweilProperties;
6 import org.woehlke.computer.kurzweil.commons.tabs.TabModel;
7 import org.woehlke.computer.kurzweil.commons.model.fractal.GaussianNumberPlane;
8 import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.MandelbrotTab;
9 import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.model.state.MandelbrotTabStateMachine;
10 import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.model.turing.MandelbrotTuringMachine;
11 import org.woehlke.computer.kurzweil.tabs.mandelbrot2julia.model.turing.Point;
12
13 import java.util.concurrent.ForkJoinTask;
14
15
16
17
18
19
20
21
22
23
24 @Log
25 @Getter
26 public class MandelbrotModel extends ForkJoinTask<Void> implements TabModel {
27
28 private static final long serialVersionUID = 7526471155622776147L;
29
30 private final GaussianNumberPlane gaussianNumberPlane;
31 private final MandelbrotTuringMachine mandelbrotTuringMachine;
32 private final MandelbrotTabStateMachine mandelbrotTabStateMachine;
33
34 private final ComputerKurzweilProperties properties;
35 private final MandelbrotTab tab;
36
37 public MandelbrotModel(ComputerKurzweilProperties properties, MandelbrotTab tab) {
38 this.properties = properties;
39 this.tab = tab;
40 this.gaussianNumberPlane = new GaussianNumberPlane(this);
41 this.mandelbrotTuringMachine = new MandelbrotTuringMachine(this);
42 this.mandelbrotTabStateMachine = new MandelbrotTabStateMachine();
43 }
44
45 public synchronized boolean click(Point c) {
46 mandelbrotTabStateMachine.click();
47 boolean repaint = true;
48 switch (mandelbrotTabStateMachine.getMandelbrotTabState()) {
49 case MANDELBROT:
50 mandelbrotTuringMachine.start();
51 repaint = false;
52 break;
53 case JULIA_SET:
54 gaussianNumberPlane.computeTheJuliaSetFor(c);
55 break;
56 case MANDELBROT_ZOOM:
57 gaussianNumberPlane.zoomIntoTheMandelbrotSet(c);
58 break;
59 case JULIA_SET_ZOOM:
60 gaussianNumberPlane.zoomIntoTheJuliaSetFor(c);
61 break;
62 }
63 return repaint;
64 }
65
66 public synchronized boolean step() {
67 boolean repaint = false;
68 switch (mandelbrotTabStateMachine.getMandelbrotTabState()) {
69 case MANDELBROT:
70 repaint = mandelbrotTuringMachine.step();
71 break;
72 case JULIA_SET:
73 case MANDELBROT_ZOOM:
74 case JULIA_SET_ZOOM:
75 break;
76 }
77 return repaint;
78 }
79
80 public synchronized int getCellStatusFor(int x, int y) {
81 return gaussianNumberPlane.getCellStatusFor(x, y);
82 }
83
84 public Point getWorldDimensions() {
85 int width = properties.getAllinone().getLattice().getWidth();
86 int height = properties.getAllinone().getLattice().getHeight();
87 return new Point(width, height);
88 }
89
90 public void setModeSwitch() {
91 this.mandelbrotTabStateMachine.setModeSwitch();
92
93 }
94
95 public void setModeZoom() {
96 this.gaussianNumberPlane.setModeZoom();
97 this.mandelbrotTabStateMachine.setModeZoom();
98
99 }
100
101 public GaussianNumberPlane getGaussianNumberPlane() {
102 return gaussianNumberPlane;
103 }
104
105 public MandelbrotTab getTab() {
106 return tab;
107 }
108
109 public void zoomOut() {
110 switch (mandelbrotTabStateMachine.getMandelbrotTabState()) {
111 case MANDELBROT:
112 case JULIA_SET:
113 break;
114 case MANDELBROT_ZOOM:
115 gaussianNumberPlane.zoomOutOfTheMandelbrotSet();
116 break;
117 case JULIA_SET_ZOOM:
118 gaussianNumberPlane.zoomOutOfTheJuliaSet();
119 break;
120 }
121 }
122
123 @Override
124 public Void getRawResult() {
125 return null;
126 }
127
128 @Override
129 protected void setRawResult(Void value) {
130
131 }
132
133 @Override
134 protected boolean exec() {
135 return false;
136 }
137
138 @Override
139 public void start() {
140
141 }
142
143 @Override
144 public void stop() {
145
146 }
147 }