1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59
| public class MyObject {
/** This object's property ID.
*/
public static final String MY_PROPERTY_PROPERTY = "myProperty";
/** This object's property value.
*/
private Whatever myProperty;
/** Change support delegate.
*/
private PropertyChangeSupport changeSupport = new PropertyChangeSupport(this);
/** Getter for myProperty.
* @return The property's value.
*/
public Whatever getMyProperty() {
return myProperty;
}
/** Setter for myProperty.
* @param value The new value.
*/
public void setMyProperty(Whatever value) {
Whatever oldValue = myProperty;
myProperty = value;
changeSupport.firePropertyChange(MY_PROPERTY_PROPERTY, oldValue, value);
}
/** Register listener.
* @param Listener The listener to be added.
*/
public void addPropertyChangeListener(PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(listener);
}
/** Register listener.
* @param propertyName The target property
* @param Listener The listener to be added.
*/
public void addPropertyChangeListener(String propertyName, PropertyChangeListener listener) {
changeSupport.addPropertyChangeListener(propertyName, listener);
}
/** Unregister listener.
* @param Listener The listener to be removed.
*/
public void removePropertyChangeListener(PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(listener);
}
/** Unregister listener.
* @param propertyName The target property
* @param Listener The listener to be removed.
*/
public void removePropertyChangeListener(String propertyName, PropertyChangeListener listener) {
changeSupport.removePropertyChangeListener(propertyName, listener);
}
} |
Partager