diff options
Diffstat (limited to 'Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java')
-rw-r--r-- | Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java | 47 |
1 files changed, 29 insertions, 18 deletions
diff --git a/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java b/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java index 3d05b14..9fca89a 100644 --- a/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java +++ b/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java @@ -69,6 +69,8 @@ public class Grid extends JPanel implements Observer, MouseListener, MouseMotion private ProgressView progressView; + private boolean useMultipleSwingWorkers = false; + public Grid(FractalModel fractalModel) { this.fractalModel = fractalModel; fractalModel.addObserver(this); @@ -108,6 +110,10 @@ public class Grid extends JPanel implements Observer, MouseListener, MouseMotion public int getHeight() { return height; } + + public void setUseMultipleSwingWorkers(boolean value) { + useMultipleSwingWorkers = value; + } @Override public final synchronized void update(Observable o, Object o1) { @@ -120,19 +126,25 @@ public class Grid extends JPanel implements Observer, MouseListener, MouseMotion } } synchronized (updaters) { - updaters.clear(); - Updater u1 = new Updater(0, width / 2, 0, height / 2); - u1.execute(); - updaters.add(u1); - Updater u2 = new Updater(width / 2, width, 0, height / 2); - u2.execute(); - updaters.add(u2); - Updater u3 = new Updater(0, width / 2, height / 2, height); - u3.execute(); - updaters.add(u3); - Updater u4 = new Updater(width / 2, width, height / 2, height); - u4.execute(); - updaters.add(u4); + updaters.clear(); + if (useMultipleSwingWorkers) { + Updater u1 = new Updater(0, width / 2, 0, height / 2); + u1.execute(); + updaters.add(u1); + Updater u2 = new Updater(width / 2, width, 0, height / 2); + u2.execute(); + updaters.add(u2); + Updater u3 = new Updater(0, width / 2, height / 2, height); + u3.execute(); + updaters.add(u3); + Updater u4 = new Updater(width / 2, width, height / 2, height); + u4.execute(); + updaters.add(u4); + } else { + Updater u = new Updater(0, width, 0, height); + u.execute(); + updaters.add(u); + } } } @@ -383,13 +395,12 @@ public class Grid extends JPanel implements Observer, MouseListener, MouseMotion } public void setValue() { - int value = 100; + int sum = 0, count = 0; for (Updater updater : updaters) { - if (updater.getProgress() < value) { - value = updater.getProgress(); - } + sum += updater.getProgress(); + count++; } - setValue(value); + setValue(sum / count); } } |