001package jmri.beans;
002
003import java.beans.PropertyChangeEvent;
004import java.beans.PropertyChangeListener;
005import javax.annotation.CheckForNull;
006import javax.annotation.concurrent.ThreadSafe;
007
008/**
009 * Implementation of {@link java.beans.PropertyChangeSupport} that can be
010 * extended by classes that would normally need to implement the methods of
011 * PropertyChangeSupport independently.
012 * <p>
013 * This class is designed to support retrofitting an existing class with the
014 * PropertyChangeProvider and PropertyChangeFirer interfaces without introducing
015 * the complexity of the other implementations of PropertyChangeProvider in this
016 * package. When designing new classes, it would be preferable to subclass
017 * {@link ArbitraryBean}, {@link Bean}, or {@link ConstrainedBean} depending on
018 * the design requirements of the new class.
019 * <p>
020 * This class is thread safe.
021 *
022 * @author Randall Wood Copyright 2020
023 */
024@ThreadSafe
025public class PropertyChangeSupport implements PropertyChangeProvider, PropertyChangeFirer {
026
027    /**
028     * Provide a {@link java.beans.PropertyChangeSupport} helper.
029     */
030    protected final java.beans.PropertyChangeSupport propertyChangeSupport = new java.beans.PropertyChangeSupport(this);
031
032    /** {@inheritDoc} */
033    @Override
034    public void addPropertyChangeListener(@CheckForNull PropertyChangeListener listener) {
035        propertyChangeSupport.addPropertyChangeListener(listener);
036    }
037
038    /** {@inheritDoc} */
039    @Override
040    public void addPropertyChangeListener(@CheckForNull String propertyName,
041            @CheckForNull PropertyChangeListener listener) {
042        propertyChangeSupport.addPropertyChangeListener(propertyName, listener);
043    }
044
045    /** {@inheritDoc} */
046    @Override
047    public PropertyChangeListener[] getPropertyChangeListeners() {
048        return propertyChangeSupport.getPropertyChangeListeners();
049    }
050
051    /** {@inheritDoc} */
052    @Override
053    public PropertyChangeListener[] getPropertyChangeListeners(@CheckForNull String propertyName) {
054        return propertyChangeSupport.getPropertyChangeListeners(propertyName);
055    }
056
057    /** {@inheritDoc} */
058    @Override
059    public void removePropertyChangeListener(@CheckForNull PropertyChangeListener listener) {
060        propertyChangeSupport.removePropertyChangeListener(listener);
061    }
062
063    /** {@inheritDoc} */
064    @Override
065    public void removePropertyChangeListener(@CheckForNull String propertyName,
066            @CheckForNull PropertyChangeListener listener) {
067        propertyChangeSupport.removePropertyChangeListener(propertyName, listener);
068    }
069
070    /**
071     * {@inheritDoc}
072     */
073    @Override
074    public void fireIndexedPropertyChange(String propertyName, int index, boolean oldValue, boolean newValue) {
075        propertyChangeSupport.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
076    }
077
078    /**
079     * {@inheritDoc}
080     */
081    @Override
082    public void fireIndexedPropertyChange(String propertyName, int index, int oldValue, int newValue) {
083        propertyChangeSupport.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
084    }
085
086    /**
087     * {@inheritDoc}
088     */
089    @Override
090    public void fireIndexedPropertyChange(String propertyName, int index, Object oldValue, Object newValue) {
091        propertyChangeSupport.fireIndexedPropertyChange(propertyName, index, oldValue, newValue);
092    }
093
094    /**
095     * {@inheritDoc}
096     */
097    @Override
098    public void firePropertyChange(String propertyName, boolean oldValue, boolean newValue) {
099        propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
100    }
101
102    /**
103     * {@inheritDoc}
104     */
105    @Override
106    public void firePropertyChange(PropertyChangeEvent event) {
107        propertyChangeSupport.firePropertyChange(event);
108    }
109
110    /**
111     * {@inheritDoc}
112     */
113    @Override
114    public void firePropertyChange(String propertyName, int oldValue, int newValue) {
115        propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
116    }
117
118    /**
119     * {@inheritDoc}
120     */
121    @Override
122    public void firePropertyChange(String propertyName, Object oldValue, Object newValue) {
123        propertyChangeSupport.firePropertyChange(propertyName, oldValue, newValue);
124    }
125
126}