1 19 package org.netbeans.modules.javacore.internalapi; 20 21 import java.util.ArrayList ; 22 import java.util.Iterator ; 23 import org.openide.ErrorManager; 24 25 28 public final class ProgressSupport { 29 30 private transient ArrayList progressListenerList = null; 31 private int counter; 32 33 34 public ProgressSupport() { 35 progressListenerList = new ArrayList (); 36 } 37 public synchronized void addProgressListener(ProgressListener listener) { 38 progressListenerList.add(listener); 39 } 40 41 45 public synchronized void removeProgressListener(ProgressListener listener) { 46 progressListenerList.remove(listener); 47 } 48 49 55 public void fireProgressListenerStart(int type, int count) { 56 counter = -1; 57 ArrayList list; 58 ProgressEvent event = new ProgressEvent(this, ProgressEvent.START, type, count); 59 synchronized (this) { 60 list = (ArrayList ) progressListenerList.clone(); 61 } 62 for (Iterator it = list.iterator(); it.hasNext();) { 63 try { 64 ((ProgressListener) it.next()).start(event); 65 } catch (RuntimeException e) { 66 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 67 } 68 } 69 } 70 71 73 public void fireProgressListenerStep(int count) { 74 counter = count; 75 ArrayList list; 76 ProgressEvent event = new ProgressEvent(this, ProgressEvent.STEP, 0, count); 77 synchronized (this) { 78 list = (ArrayList ) progressListenerList.clone(); 79 } 80 for (Iterator it = list.iterator(); it.hasNext();) { 81 try { 82 ((ProgressListener) it.next()).step(event); 83 } catch (RuntimeException e) { 84 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 85 } 86 } 87 } 88 90 public void fireProgressListenerStep() { 91 fireProgressListenerStep(counter+1); 92 } 93 95 public void fireProgressListenerStop() { 96 ArrayList list; 97 ProgressEvent event = new ProgressEvent(this, ProgressEvent.STOP); 98 synchronized (this) { 99 list = (ArrayList ) progressListenerList.clone(); 100 } 101 for (Iterator it = list.iterator(); it.hasNext();) { 102 try { 103 ((ProgressListener) it.next()).stop(event); 104 } catch (RuntimeException e) { 105 ErrorManager.getDefault().notify(ErrorManager.INFORMATIONAL, e); 106 } 107 } 108 } 109 } 110 | Popular Tags |