1 19 package org.netbeans.modules.javacore; 20 21 import java.lang.ref.WeakReference ; 22 import org.openide.util.RequestProcessor; 23 import org.openide.util.Task; 24 import org.openide.util.TaskListener; 25 26 30 public class RequestPoster { 31 32 private RequestProcessor rp; 33 private WeakReference queuedTask; 34 35 public RequestPoster() { 36 } 37 38 41 public RequestPoster(RequestProcessor rp) { 42 this.rp = rp; 43 } 44 45 public synchronized void post(Runnable runnable) { 46 RequestProcessor.Task task = queuedTask == null ? null : (RequestProcessor.Task) queuedTask.get(); 47 if (task != null) { 48 task.cancel(); 49 } 50 if (rp == null) rp = new RequestProcessor("Implicit RequestPoster's RP-" + hashCode()); queuedTask = new WeakReference (rp.post(runnable)); 52 } 53 } 54 | Popular Tags |