1 11 package org.eclipse.help.internal.workingset; 12 13 import java.util.*; 14 15 18 public class PropertyChange { 19 20 49 public interface IPropertyChangeListener extends EventListener { 50 51 62 public void propertyChange(PropertyChangeEvent event); 63 } 64 65 81 public static class PropertyChangeEvent extends EventObject { 82 83 86 private String propertyName; 87 88 92 private Object oldValue; 93 94 98 private Object newValue; 99 100 115 PropertyChangeEvent(Object source, String property, Object oldValue, 116 Object newValue) { 117 118 super(source); 119 if (property == null) { 120 throw new IllegalArgumentException (); 121 } 122 this.propertyName = property; 123 this.oldValue = oldValue; 124 this.newValue = newValue; 125 } 126 127 137 public String getProperty() { 138 return propertyName; 139 } 140 141 147 public Object getNewValue() { 148 return newValue; 149 } 150 151 157 public Object getOldValue() { 158 return oldValue; 159 } 160 } 161 162 186 public static class ListenerList { 187 190 private int capacity; 191 192 196 private int size; 197 198 203 private Object [] listeners = null; 204 205 209 private static final Object [] EmptyArray = new Object [0]; 210 211 214 public ListenerList() { 215 this(3); 216 } 217 218 226 public ListenerList(int capacity) { 227 if (capacity < 1) { 228 throw new IllegalArgumentException (); 229 } 230 this.capacity = capacity; 231 } 232 233 240 public void add(Object listener) { 241 if (listener == null) { 242 throw new IllegalArgumentException (); 243 } 244 if (size == 0) { 245 listeners = new Object [capacity]; 246 } else { 247 for (int i = 0; i < size; ++i) { 249 if (listeners[i] == listener) { 250 return; 251 } 252 } 253 if (size == listeners.length) { 255 System.arraycopy(listeners, 0, 256 listeners = new Object [size * 2 + 1], 0, size); 257 } 258 } 259 listeners[size++] = listener; 260 } 261 262 272 public Object [] getListeners() { 273 if (size == 0) 274 return EmptyArray; 275 Object [] result = new Object [size]; 276 System.arraycopy(listeners, 0, result, 0, size); 277 return result; 278 } 279 280 286 public boolean isEmpty() { 287 return size == 0; 288 } 289 290 297 public void remove(Object listener) { 298 if (listener == null) { 299 throw new IllegalArgumentException (); 300 } 301 for (int i = 0; i < size; ++i) { 302 if (listeners[i] == listener) { 303 if (size == 1) { 304 listeners = null; 305 size = 0; 306 } else { 307 System.arraycopy(listeners, i + 1, listeners, i, --size 308 - i); 309 listeners[size] = null; 310 } 311 return; 312 } 313 } 314 } 315 316 321 public int size() { 322 return size; 323 } 324 } 325 } 326 | Popular Tags |