1 22 package org.netbeans.lib.cvsclient.event; 23 24 import org.netbeans.lib.cvsclient.ClientServices; 25 26 import java.io.File ; 27 28 35 public class EventManager { 36 41 private CVSListener[] listeners; 42 43 48 private boolean fireEnhancedEventSet = true; 49 50 private final ClientServices services; 51 52 55 public EventManager(ClientServices services) { 56 this.services = services; 57 } 58 59 64 public ClientServices getClientServices() { 65 return services; 66 } 67 68 72 public synchronized void addCVSListener(CVSListener listener) { 73 if (listeners == null || listeners.length == 0) { 74 listeners = new CVSListener[1]; 75 } 76 else { 77 CVSListener[] l = new CVSListener[listeners.length + 1]; 79 for (int i = 0; i < listeners.length; i++) { 80 l[i] = listeners[i]; 81 } 82 listeners = l; 83 } 84 listeners[listeners.length - 1] = listener; 85 } 86 87 91 public synchronized void removeCVSListener(CVSListener listener) { 92 if (listeners.length == 1) { 94 listeners = null; 95 } 96 else { 97 CVSListener[] l = new CVSListener[listeners.length - 1]; 98 int i = 0; 99 while (i < l.length) { 100 if (listeners[i] == listener) { 101 for (int j = i + 1; j < listeners.length; j++) { 102 l[j - 1] = listeners[j]; 103 } 104 break; 105 } 106 else { 107 l[i] = listeners[i]; 108 } 109 i++; 110 } 111 listeners = l; 112 } 113 } 114 115 119 public void fireCVSEvent(CVSEvent e) { 120 if (listeners == null || listeners.length == 0) 122 return; 123 if (e instanceof FileInfoEvent) { 124 File file = ((FileInfoEvent) e).getInfoContainer().getFile(); 125 if (services.getGlobalOptions().isExcluded(file)) return; 126 } 127 CVSListener[] l = null; 128 synchronized (listeners) { 129 l = new CVSListener[listeners.length]; 130 System.arraycopy(listeners, 0, l, 0, l.length); 131 } 132 133 for (int i = 0; i < l.length; i++) { 134 e.fireEvent(l[i]); 135 } 136 } 137 138 141 public boolean isFireEnhancedEventSet() { 142 return fireEnhancedEventSet; 143 } 144 145 148 public void setFireEnhancedEventSet(boolean fireEnhancedEventSet) { 149 this.fireEnhancedEventSet = fireEnhancedEventSet; 150 } 151 152 } 153 | Popular Tags |