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