1 19 package org.netbeans.tax.event; 20 21 import java.util.*; 22 23 28 public final class TreeEventManager { 29 30 31 33 34 public static final short FIRE_NOW = 1; 35 36 37 public static final short FIRE_LATER = 2; 38 39 40 41 private short firePolicy; 42 43 46 private Set cachedSupports = new HashSet (); 47 48 52 53 public TreeEventManager (short policy) { 54 firePolicy = policy; 55 } 56 57 58 public TreeEventManager () { 59 this (FIRE_NOW); 60 } 61 62 63 public TreeEventManager (TreeEventManager eventManager) { 64 this.firePolicy = eventManager.firePolicy; 65 } 66 67 68 72 75 public final short getFirePolicy () { 76 return firePolicy; 77 } 78 79 82 public final void setFirePolicy (short firePolicy) { 83 if (this.firePolicy == firePolicy) 84 return; 85 this.firePolicy = firePolicy; 86 if (firePolicy == FIRE_NOW) 87 fireCached (); 88 89 } 90 91 94 private void fireCached () { 95 Iterator it = cachedSupports.iterator (); 96 while (it.hasNext ()) { 97 TreeEventChangeSupport next = (TreeEventChangeSupport) it.next (); 98 next.firePropertyChangeCache (); 99 it.remove (); 100 } 101 } 102 103 107 private void addToCache (TreeEventChangeSupport support) { 108 cachedSupports.add (support); 109 } 110 111 113 public final void firePropertyChange (TreeEventChangeSupport eventChangeSupport, TreeEvent evt) { 114 if (firePolicy == FIRE_NOW) { 119 eventChangeSupport.firePropertyChangeCache (); 120 eventChangeSupport.firePropertyChangeNow (evt); 121 return; 122 } 123 if (firePolicy == FIRE_LATER) { 124 eventChangeSupport.firePropertyChangeLater (evt); 125 addToCache (eventChangeSupport); 126 return; 127 } 128 } 129 130 131 133 147 148 } 149 | Popular Tags |