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