1 19 package org.openide.util; 20 21 import java.awt.event.FocusListener ; 22 23 import java.beans.PropertyChangeListener ; 24 import java.beans.VetoableChangeListener ; 25 26 import java.util.EventListener ; 27 28 import javax.swing.event.ChangeListener ; 29 import javax.swing.event.DocumentListener ; 30 31 32 176 public final class WeakListeners { 177 179 private WeakListeners() { 180 } 181 182 194 public static <T extends EventListener > T create(Class <T> lType, T l, Object source) { 195 if (!lType.isInterface()) { 196 throw new IllegalArgumentException ("Not interface: " + lType); 197 } 198 199 return WeakListenerImpl.create(lType, lType, l, source); 200 } 201 202 237 public static <T extends EventListener > T create(Class <T> lType, Class <? super T> apiType, T l, Object source) { 238 if (!lType.isInterface()) { 239 throw new IllegalArgumentException ("Not interface: " + lType); 240 } 241 242 if (!apiType.isInterface()) { 243 throw new IllegalArgumentException ("Not interface: " + apiType); 244 } 245 246 if (!apiType.isAssignableFrom(lType)) { 247 throw new IllegalArgumentException (apiType + " has to be assignableFrom " + lType); } 249 250 return WeakListenerImpl.create(lType, apiType, l, source); 251 } 252 253 260 public static PropertyChangeListener propertyChange(PropertyChangeListener l, Object source) { 261 WeakListenerImpl.PropertyChange wl = new WeakListenerImpl.PropertyChange(l); 262 wl.setSource(source); 263 264 return wl; 265 } 266 267 274 public static VetoableChangeListener vetoableChange(VetoableChangeListener l, Object source) { 275 WeakListenerImpl.VetoableChange wl = new WeakListenerImpl.VetoableChange(l); 276 wl.setSource(source); 277 278 return wl; 279 } 280 281 288 public static DocumentListener document(DocumentListener l, Object source) { 289 WeakListenerImpl.Document wl = new WeakListenerImpl.Document(l); 290 wl.setSource(source); 291 292 return wl; 293 } 294 295 302 public static ChangeListener change(ChangeListener l, Object source) { 303 WeakListenerImpl.Change wl = new WeakListenerImpl.Change(l); 304 wl.setSource(source); 305 306 return wl; 307 } 308 } 309 | Popular Tags |