![JAR search and dependency download from the Maven repository](/logo.png)
net.sourceforge.jdatepicker.AbstractDateModel Maven / Gradle / Ivy
/**
Copyright 2004 Juan Heyns. All rights reserved.
Redistribution and use in source and binary forms, with or without modification, are
permitted provided that the following conditions are met:
1. Redistributions of source code must retain the above copyright notice, this list of
conditions and the following disclaimer.
2. Redistributions in binary form must reproduce the above copyright notice, this list
of conditions and the following disclaimer in the documentation and/or other materials
provided with the distribution.
THIS SOFTWARE IS PROVIDED BY JUAN HEYNS ``AS IS'' AND ANY EXPRESS OR IMPLIED
WARRANTIES, INCLUDING, BUT NOT LIMITED TO, THE IMPLIED WARRANTIES OF MERCHANTABILITY AND
FITNESS FOR A PARTICULAR PURPOSE ARE DISCLAIMED. IN NO EVENT SHALL JUAN HEYNS OR
CONTRIBUTORS BE LIABLE FOR ANY DIRECT, INDIRECT, INCIDENTAL, SPECIAL, EXEMPLARY, OR
CONSEQUENTIAL DAMAGES (INCLUDING, BUT NOT LIMITED TO, PROCUREMENT OF SUBSTITUTE GOODS OR
SERVICES; LOSS OF USE, DATA, OR PROFITS; OR BUSINESS INTERRUPTION) HOWEVER CAUSED AND ON
ANY THEORY OF LIABILITY, WHETHER IN CONTRACT, STRICT LIABILITY, OR TORT (INCLUDING
NEGLIGENCE OR OTHERWISE) ARISING IN ANY WAY OUT OF THE USE OF THIS SOFTWARE, EVEN IF
ADVISED OF THE POSSIBILITY OF SUCH DAMAGE.
The views and conclusions contained in the software and documentation are those of the
authors and should not be interpreted as representing official policies, either expressed
or implied, of Juan Heyns.
*/
package net.sourceforge.jdatepicker;
import java.beans.PropertyChangeEvent;
import java.beans.PropertyChangeListener;
import java.util.HashSet;
import javax.swing.event.ChangeEvent;
import javax.swing.event.ChangeListener;
/**
* Created 18 April 2010
*
* @author Juan Heyns
*
* @param
*/
public abstract class AbstractDateModel implements DateModel {
private HashSet changeListeners;
private HashSet propertyChangeListeners;
protected AbstractDateModel() {
changeListeners = new HashSet();
propertyChangeListeners = new HashSet();
}
public synchronized void addChangeListener(ChangeListener changeListener) {
changeListeners.add(changeListener);
}
public synchronized void removeChangeListener(ChangeListener changeListener) {
changeListeners.remove(changeListener);
}
/**
* Called internally when changeListeners should be notified.
*/
protected synchronized void fireChangeEvent() {
for (ChangeListener changeListener : changeListeners) {
changeListener.stateChanged(new ChangeEvent(this));
}
}
public synchronized void addPropertyChangeListener(PropertyChangeListener listener) {
propertyChangeListeners.add(listener);
}
public synchronized void removePropertyChangeListener(PropertyChangeListener listener) {
propertyChangeListeners.remove(listener);
}
/**
* Called internally pass an PropertyChangeEvent to any registered
* listeners. No event is fired if the given event's old and new values are
* equal and non-null.
*/
protected synchronized void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
if (oldValue != null && newValue != null && oldValue.equals(newValue)) {
return;
}
for (PropertyChangeListener listener : propertyChangeListeners) {
listener.propertyChange(new PropertyChangeEvent(this, propertyName, oldValue, newValue));
}
}
}
© 2015 - 2025 Weber Informatics LLC | Privacy Policy