1 package org.woehlke.computer.kurzweil.tabs.mandelbrot2julia;
2
3 import org.woehlke.computer.kurzweil.commons.tabs.TabController;
4
5
6
7
8
9
10
11
12
13
14
15 public class MandelbrotController extends Thread implements TabController, Mandelbrot {
16
17 private volatile MandelbrotModel mandelbrotModel;
18 private volatile MandelbrotTab tab;
19
20 private final int THREAD_SLEEP_TIME = 1;
21
22 private volatile Boolean goOn;
23
24 public MandelbrotController(MandelbrotModel model, MandelbrotTab tab) {
25 this.tab = tab;
26 this.mandelbrotModel = model;
27 goOn = Boolean.TRUE;
28 }
29
30 public void run() {
31 boolean doIt;
32 do {
33 synchronized (goOn) {
34 doIt = goOn.booleanValue();
35 }
36 if(this.mandelbrotModel.step()){
37 this.tab.getCanvas().repaint();
38 }
39 try { sleep(THREAD_SLEEP_TIME); }
40 catch (InterruptedException e) { }
41 }
42 while (doIt);
43 }
44
45 public void exit() {
46 synchronized (goOn) {
47 goOn = Boolean.FALSE;
48 }
49 }
50
51 }