Search in sources :

Example 1 with AccessoryOpsModeProgrammerFacade

use of jmri.implementation.AccessoryOpsModeProgrammerFacade in project JMRI by JMRI.

the class ProgOpsModePane method getProgrammer.

/**
     * Get the selected programmer
     */
@Override
public Programmer getProgrammer() {
    log.debug("getProgrammer mLongAddrCheck.isSelected()={}, oldLongAddr={}, mAddrField.getValue()={}, oldAddrValue={}, opsAccyMode={}, oldOpsAccyMode={})", longAddrButton.isSelected(), oldLongAddr, mAddrField.getValue(), oldAddrValue, opsAccyMode, oldOpsAccyMode);
    if ((longAddrButton.isSelected() == oldLongAddr) && mAddrField.getValue().equals(oldAddrValue) && opsAccyMode == oldOpsAccyMode) {
        log.debug("getProgrammer hasn't changed");
        // hasn't changed
        if (opsAccyMode) {
            return facadeProgrammer;
        } else {
            return programmer;
        }
    }
    // here values have changed, try to create a new one
    AddressedProgrammerManager pm = ((AddressedProgrammerManager) progBox.getSelectedItem());
    oldLongAddr = longAddrButton.isSelected();
    oldAddrValue = (Integer) mAddrField.getValue();
    oldOpsAccyMode = opsAccyMode;
    setAddrParams();
    if (pm != null) {
        int address = 3;
        try {
            address = (Integer) mAddrField.getValue();
        } catch (java.lang.NumberFormatException e) {
            log.error("loco address \"{}\" not correct", mAddrField.getValue());
            programmer = null;
        }
        boolean longAddr = longAddrButton.isSelected();
        log.debug("ops programmer for address " + address + ", long address " + longAddr);
        programmer = pm.getAddressedProgrammer(longAddr, address);
        log.debug("   programmer: {}", programmer);
        // whole point is to get mode...
        setProgrammerFromGui(programmer);
    } else {
        log.warn("request for ops mode programmer with no ProgrammerManager configured");
        programmer = null;
    }
    if (opsAccyMode) {
        log.debug("   getting AccessoryOpsModeProgrammerFacade");
        facadeProgrammer = new AccessoryOpsModeProgrammerFacade(programmer, longAddrButton.isSelected() ? "accessory" : "decoder");
        return facadeProgrammer;
    }
    return programmer;
}
Also used : AddressedProgrammerManager(jmri.AddressedProgrammerManager) AccessoryOpsModeProgrammerFacade(jmri.implementation.AccessoryOpsModeProgrammerFacade)

Aggregations

AddressedProgrammerManager (jmri.AddressedProgrammerManager)1 AccessoryOpsModeProgrammerFacade (jmri.implementation.AccessoryOpsModeProgrammerFacade)1