001package jmri.implementation;
002
003import java.beans.PropertyChangeEvent;
004import jmri.Conditional;
005import jmri.NamedBeanHandle;
006import org.slf4j.Logger;
007import org.slf4j.LoggerFactory;
008
009/**
010 * A service class for monitoring a bound property in one of the JMRI Named
011 * beans (Turnout, Sensor, etc). For use where only two states are possible,
012 * ACTIVE/INACTIVE, THROWN/CLOSED etc.
013 * <p>
014 * This file is part of JMRI.
015 * <p>
016 * JMRI is free software; you can redistribute it and/or modify it under the
017 * terms of version 2 of the GNU General Public License as published by the Free
018 * Software Foundation. See the "COPYING" file for a copy of this license.
019 * <p>
020 * JMRI is distributed in the hope that it will be useful, but WITHOUT ANY
021 * WARRANTY; without even the implied warranty of MERCHANTABILITY or FITNESS FOR
022 * A PARTICULAR PURPOSE. See the GNU General Public License for more details.
023 *
024 * @author Pete Cressman Copyright (C) 2009
025 * @since 2.5.1
026 */
027public class JmriTwoStatePropertyListener extends JmriSimplePropertyListener {
028
029    JmriTwoStatePropertyListener(String propName, int type, String name, Conditional.Type varType,
030            Conditional client) {
031        super(propName, type, name, varType, client);
032    }
033
034    JmriTwoStatePropertyListener(String propName, int type, NamedBeanHandle<?> namedBean, Conditional.Type varType,
035            Conditional client) {
036        super(propName, type, namedBean, varType, client);
037    }
038
039    @Override
040    public void propertyChange(PropertyChangeEvent evt) {
041        if (log.isDebugEnabled()) {
042            log.debug("\"{}\" sent PropertyChangeEvent \"{}\", old value =\"{}\", new value =\"{}, enabled = {}", _varName, evt.getPropertyName(), evt.getOldValue(), evt.getNewValue(), _enabled);
043        }
044        if (getPropertyName().equals(evt.getPropertyName())) {
045            super.propertyChange(evt);
046        }
047        /*
048         int newState = ((Number) evt.getNewValue()).intValue();
049         int oldState = ((Number) evt.getOldValue()).intValue();
050         if (newState != oldState)  {
051         // property has changed to/from the watched state, calculate
052         super.propertyChange(evt);
053         }
054         */
055    }
056
057    private final static Logger log = LoggerFactory.getLogger(JmriTwoStatePropertyListener.class);
058}