Created
February 24, 2012 16:31
-
-
Save rhiguchi/1901885 to your computer and use it in GitHub Desktop.
Scala で PropertyChangeEvent の発行とかを実装するミックスイン用トレイト ref: http://qiita.com/items/2791
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
import java.beans.{PropertyChangeListener, PropertyChangeSupport, PropertyChangeEvent} | |
trait PropertyChangePublisher { | |
private lazy val propertyChangeSupport = new PropertyChangeSupport(this) | |
def addPropertyChangeListener(listener: PropertyChangeListener) = | |
propertyChangeSupport.addPropertyChangeListener(listener) | |
def removePropertyChangeListener(listener: PropertyChangeListener) = | |
propertyChangeSupport.removePropertyChangeListener(listener) | |
protected def firePropertyChange(propertyName: String, oldValue: Any, newValue: Any) = | |
propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue) | |
protected def firePropertyChange(event: PropertyChangeEvent) = | |
propertyChangeSupport.firePropertyChange(event) | |
protected def fireIndexedPropertyChange( | |
propertyName: String, index: Int, oldValue: Any, newValue: Any) = | |
propertyChangeSupport.fireIndexedPropertyChange(propertyName, index, oldValue, newValue) | |
} |
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
class BeanClass extends PropertyChangePublisher { | |
private var _name = "" | |
def name = _name | |
def name_=(newName: String) { | |
val oldValue = _name | |
_name = newName | |
firePropertyChange("name", oldValue, newName) | |
} | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment