+ WeakListeners
class got variants of propertyChange()
+ and vetoableChange()
methods, which take the property name.
+ They are to be used as an argument to
+ addPropertyChangeListener(String propertyName, PropertyChangeListener listener)
+ and addVetoableChangeListener(String propertyName, PropertyChangeListener listener)
+ methods respectively, and will call the appropriate remove methods with the provided
+ property name.
+
l
must be an instance of
+ * listenerClass
+ */
+ protected WeakListenerImpl(Class> listenerClass, java.util.EventListener l, String name) {
this.listenerClass = listenerClass;
- ref = new ListenerReference(l, this);
+ ref = new ListenerReference(l, name, this);
}
/** Setter for the source field. If a WeakReference to an underlying listener is
@@ -185,6 +194,15 @@
PropertyChange(Class> clazz, PropertyChangeListener l) {
super(clazz, l);
}
+
+ /** Constructor.
+ * @param clazz required class
+ * @param l listener to delegate to
+ * @param propertyName the associated property name
+ */
+ PropertyChange(PropertyChangeListener l, String propertyName) {
+ super(PropertyChangeListener.class, l, propertyName);
+ }
/** Tests if the object we reference to still exists and
* if so, delegate to it. Otherwise remove from the source
@@ -217,6 +235,14 @@
super(VetoableChangeListener.class, l);
}
+ /** Constructor.
+ * @param l listener to delegate to
+ * @param propertyName the associated property name
+ */
+ VetoableChange(VetoableChangeListener l, String propertyName) {
+ super(VetoableChangeListener.class, l, propertyName);
+ }
+
/** Tests if the object we reference to still exists and
* if so, delegate to it. Otherwise remove from the source
* if it has removePropertyChangeListener method.
@@ -513,12 +539,15 @@
private static Class> lastClass;
private static String lastMethodName;
private static Method lastRemove;
+ private static Method lastNamedRemove;
private static final Object LOCK = new Object();
WeakListenerImpl weakListener;
+ private String name;
- ListenerReference(Object ref, WeakListenerImpl weakListener) {
+ ListenerReference(Object ref, String name, WeakListenerImpl weakListener) {
super(ref, Utilities.activeReferenceQueue());
this.weakListener = weakListener;
+ this.name = name;
}
/** Requestes cleanup of the listener with a provided source.
@@ -534,7 +563,7 @@
// plan new cleanup into the activeReferenceQueue with this listener and
// provided source
weakListener.source = new WeakReference