/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.micromanager.utils;

import java.util.concurrent.atomic.AtomicBoolean;
import java.util.concurrent.atomic.AtomicReference;
import javax.swing.SwingUtilities;

/**
 *
 * @author arthur
 */
public class GUIUpdater {
   AtomicBoolean readyForNewPost = new AtomicBoolean();
   AtomicReference<Runnable> latestTask = new AtomicReference<Runnable>();

   public GUIUpdater() {
      readyForNewPost.set(true);
   }

   /*
    * Post a task for running on the EDT thread. If multiple
    * tasks pile up, only the most recent will run.
    */
   public void post(Runnable task) {
      latestTask.set(task);
      if (readyForNewPost.getAndSet(false)) {
         SwingUtilities.invokeLater(new Runnable() {
            public void run() {
               readyForNewPost.set(true);
               final Runnable taskToRun = latestTask.getAndSet(null);
               if (taskToRun != null) {
                  taskToRun.run();
               } else {
                  System.err.println("Null task in GUIUpdater!");
               }
            }
         });
      }
   }
}

@@ -93,17 +93,16 @@
 or.%0A */%0A
-%0A
 package 
@@ -130,58 +130,8 @@
 s;%0A%0A
-import java.util.concurrent.atomic.AtomicBoolean;%0A
 impo
@@ -238,16 +238,26 @@
 r arthur
+ and henry
 %0A */%0Apub
@@ -283,63 +283,8 @@
 r %7B%0A
-   AtomicBoolean readyForNewPost = new AtomicBoolean();
 %0A   
@@ -360,72 +360,8 @@
 );%0A%0A
-   public GUIUpdater() %7B%0A      readyForNewPost.set(true);%0A   %7D%0A%0A
    /
@@ -551,57 +551,8 @@
 k);%0A
-      if (readyForNewPost.getAndSet(false)) %7B%0A   
     
@@ -606,19 +606,16 @@
         
-   
 public v
@@ -630,53 +630,8 @@
 ) %7B%0A
-               readyForNewPost.set(true);%0A   
     
@@ -705,19 +705,16 @@
         
-  
- 
 if (task
@@ -745,19 +745,16 @@
         
-   
 taskToRu
@@ -778,120 +778,21 @@
     
-  
- %7D else %7B%0A                  System.err.println(%22Null task in GUIUpdater!%22);%0A               %7D%0A            %7D%0A   
+%7D%0A         %7D%0A
     
@@ -797,23 +797,15 @@
     %7D);%0A
-      %7D%0A
    %7D%0A%7D%0A

Simplify GUIUpdater. The previous model wasn't quite correct in any case.