1 18 package org.apache.batik.dom.events; 19 20 import org.w3c.dom.events.EventListener ; 21 22 28 public class EventListenerList { 29 30 33 protected int n = 0; 34 37 protected Entry first = null; 38 44 protected EventListener [] listeners = null; 45 46 49 public EventListener [] getEventListeners() { 50 if (first == null) return null; 51 if (listeners != null) return listeners; 52 53 listeners = new EventListener [n]; 54 Entry current = first; 55 for (int i=0; i < n; ++i, current = current.next) { 56 listeners[i] = current.listener; 57 } 58 return listeners; 59 } 60 61 65 public void add(EventListener listener) { 66 first = new Entry(listener, first); 67 listeners = null; n++; 69 } 70 71 75 public void remove(EventListener listener) { 76 if (first == null) return; 77 78 79 if (first.listener == listener) { 80 first = first.next; 81 listeners = null; --n; 83 } else { 84 Entry prev = first; 85 Entry e = first.next; 86 while (e != null) { 87 if (e.listener == listener) { 88 prev.next = e.next; 89 listeners = null; --n; 91 break; 92 } 93 prev = e; 94 e = e.next; 95 } 96 } 97 } 98 99 104 public boolean contains(EventListener listener) { 105 for (Entry e=first; e != null; e = e.next) { 106 if (listener == e.listener) 107 return true; 108 } 109 return false; 110 } 111 112 115 public int size() { 116 return n; 117 } 118 119 protected static class Entry { 121 EventListener listener; 122 Entry next; 123 124 public Entry(EventListener listener, Entry next) { 125 this.listener = listener; 126 this.next = next; 127 } 128 } 129 } 130 | Popular Tags |