From: Bill Kuker Date: Wed, 1 Jul 2009 18:45:22 +0000 (+0000) Subject: stop old update early if things have changed X-Git-Url: https://git.gag.com/?a=commitdiff_plain;h=8cf21dcb100dc173552624da192a48fd74159f4a;p=sw%2Fmotorsim stop old update early if things have changed --- diff --git a/src/com/billkuker/rocketry/motorsim/visual/Chart.java b/src/com/billkuker/rocketry/motorsim/visual/Chart.java index f033a7b..9b5ae21 100644 --- a/src/com/billkuker/rocketry/motorsim/visual/Chart.java +++ b/src/com/billkuker/rocketry/motorsim/visual/Chart.java @@ -35,6 +35,7 @@ public class Chart extends JPanel { private static ExecutorService fast = Executors.newFixedThreadPool(2) ; private static ExecutorService slow = Executors.newFixedThreadPool(2); + private boolean stop = false; public class IntervalDomain implements Iterable>{ @@ -131,13 +132,16 @@ public class Chart extends JPanel { public void setDomain(final Iterable> d) { series.clear(); + stop = true; fill(d, 100); fast.submit(new Thread(){ public void run(){ - fill(d, 10); + if ( !stop ) + fill(d, 10); slow.submit(new Thread(){ public void run(){ - fill(d, 1); + if ( !stop ) + fill(d, 1); } }); } @@ -145,7 +149,8 @@ public class Chart extends JPanel { } @SuppressWarnings("unchecked") - private void fill(Iterable> d, int skip) { + private synchronized void fill(Iterable> d, int skip) { + stop = false; int sz = 0; if (d instanceof Collection) { sz = ((Collection) d).size(); @@ -159,6 +164,10 @@ public class Chart extends JPanel { try { Amount last = null; for (Amount ax : d) { + if ( stop ){ + System.out.println("Stopping early " + skip); + return; + } last = ax; if (cnt % skip == 0) { Amount y = (Amount) f.invoke(source, ax);