diff --git a/src/main/java/de/hsfulda/onses/models/Card.java b/src/main/java/de/hsfulda/onses/models/Card.java index aaa408a..91cab36 100644 --- a/src/main/java/de/hsfulda/onses/models/Card.java +++ b/src/main/java/de/hsfulda/onses/models/Card.java @@ -1,6 +1,14 @@ package de.hsfulda.onses.models; +import java.beans.PropertyChangeSupport; + public class Card { + + public final static String PROPERTY_COLOR = "color"; + public final static String PROPERTY_VALUE = "value"; + + protected PropertyChangeSupport listeners; + private Color color; private Value value; @@ -12,12 +20,16 @@ public class Card { }; public Card setColor(Color color) { + final Card.Color oldColor = this.color; this.color = color; + this.firePropertyChange(PROPERTY_COLOR, oldColor, color); return this; } public Card setValue(Value value) { + final Card.Value oldValue = this.value; this.value = value; + this.firePropertyChange(PROPERTY_VALUE, oldValue, value); return this; } @@ -28,4 +40,19 @@ public class Card { public Value getValue() { return this.value; } + + public PropertyChangeSupport listeners() { + if(this.listeners == null) { + this.listeners = new PropertyChangeSupport(this); + } + return this.listeners; + } + + public boolean firePropertyChange(String propertyName, Object oldValue, Object newValue) { + if (this.listeners != null) { + this.listeners.firePropertyChange(propertyName, oldValue, newValue); + return true; + } + return false; + } }