aboutsummaryrefslogtreecommitdiff
path: root/Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java
diff options
context:
space:
mode:
authorCamil Staps2015-06-05 15:16:22 +0200
committerCamil Staps2015-06-05 15:16:22 +0200
commit324aa6d4b9dad0f993fd3ff2d766c7a2f4397793 (patch)
tree542fce08597b01a3b2a9b9f47ad88393a2c8ac17 /Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java
parentVersion with four swingworkers (diff)
Option for multiple (4) or single swingworker(s)
Diffstat (limited to 'Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java')
-rw-r--r--Week15 Mandelbrot/src/com/camilstaps/mandelbrot/Grid.java47
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);
}
}