001package jmri.jmrit.beantable.routetable;
002
003import jmri.Route;
004import jmri.Sensor;
005import org.slf4j.Logger;
006import org.slf4j.LoggerFactory;
007
008/**
009 * Route Table RouteSensor Elements.
010 *
011 * Split from {@link jmri.jmrit.beantable.RouteTableAction}
012 *
013 * @author Dave Duchamp Copyright (C) 2004
014 * @author Bob Jacobsen Copyright (C) 2007
015 * @author Simon Reader Copyright (C) 2008
016 * @author Pete Cressman Copyright (C) 2009
017 * @author Egbert Broerse Copyright (C) 2016
018 * @author Paul Bender Copyright (C) 2020
019 */
020class RouteSensor extends RouteElement {
021    private static final String SET_TO_ACTIVE = Bundle.getMessage("Set") + " " + Bundle.getMessage("SensorStateActive");
022    private static final String SET_TO_INACTIVE = Bundle.getMessage("Set") + " " + Bundle.getMessage("SensorStateInactive");
023
024    private static final String SET_TO_TOGGLE = Bundle.getMessage("Set") + " " + Bundle.getMessage("Toggle");
025
026    RouteSensor(String sysName, String userName) {
027        super(sysName, userName);
028    }
029
030    @Override
031    String getSetToState() {
032        switch (_setToState) {
033            case Sensor.INACTIVE:
034                return SET_TO_INACTIVE;
035            case Sensor.ACTIVE:
036                return SET_TO_ACTIVE;
037            case Route.TOGGLE:
038                return SET_TO_TOGGLE;
039            default:
040                log.warn("Unhandled route state: {}", _setToState);
041                break;
042        }
043        return "";
044    }
045
046    @Override
047    void setSetToState(String state) {
048        if (SET_TO_INACTIVE.equals(state)) {
049            _setToState = Sensor.INACTIVE;
050        } else if (SET_TO_ACTIVE.equals(state)) {
051            _setToState = Sensor.ACTIVE;
052        } else if (SET_TO_TOGGLE.equals(state)) {
053            _setToState = Route.TOGGLE;
054        }
055    }
056
057    private static final Logger log = LoggerFactory.getLogger(RouteSensor.class);
058}