001package jmri.jmrit.logix;
002
003import jmri.Throttle;
004
005/**
006 * A JInternalFrame that contains buttons for each decoder function.
007 *
008 * @author Pete Cressman Copyright 2020
009 */
010public class LearnFunctionPanel extends jmri.jmrit.throttle.FunctionPanel {
011
012    private final LearnThrottleFrame _throttleFrame;
013
014    LearnFunctionPanel(LearnThrottleFrame learnFrame) {
015        super();
016        _throttleFrame = learnFrame;
017    }
018
019    @Override
020    public void propertyChange(java.beans.PropertyChangeEvent e) {
021        super.propertyChange(e);
022
023        String functionName = e.getPropertyName();
024        if (!functionName.startsWith("F")) {
025            return;
026        }
027        boolean isSet = ((Boolean) e.getNewValue());
028        
029        for ( int i = 0; i< 29; i++ ) {
030            if (functionName.equals(Throttle.getFunctionString(i))) {
031                _throttleFrame.setFunctionState(functionName, isSet);
032            } else if (functionName.equals(Throttle.getFunctionMomentaryString(i))) {
033                functionName = "Lock" + Throttle.getFunctionString(i);
034                _throttleFrame.setFunctionLock(functionName, isSet);
035             }
036        }
037    }
038
039//    private final static Logger log = LoggerFactory.getLogger(LearnFunctionPanel.class);
040}