Search in sources :

Example 6 with ProgrammingMode

use of jmri.ProgrammingMode in project JMRI by JMRI.

the class ProgOpsModePane method setProgrammerFromGui.

/**
     * Change the programmer (mode).
     *
     * @param programmer The type of programmer (i.e. Byte Mode)
     */
void setProgrammerFromGui(Programmer programmer) {
    for (ProgrammingMode mode : buttonMap.keySet()) {
        if (buttonMap.get(mode).isSelected()) {
            if (mode == DefaultProgrammerManager.OPSACCBYTEMODE) {
                log.debug("OPS ACCY was selected in setProgrammerFromGui");
                opsAccyMode = true;
            } else {
                opsAccyMode = false;
                getProgrammer().setMode(mode);
            }
        }
    }
}
Also used : ProgrammingMode(jmri.ProgrammingMode)

Example 7 with ProgrammingMode

use of jmri.ProgrammingMode in project JMRI by JMRI.

the class PaneProgFrame method pickProgrammerMode.

protected void pickProgrammerMode(@Nonnull Element programming) {
    log.debug("pickProgrammerMode starts");
    boolean paged = true;
    boolean directbit = true;
    boolean directbyte = true;
    boolean register = true;
    Attribute a;
    // set the programming attributes for DCC
    if ((a = programming.getAttribute("paged")) != null) {
        if (a.getValue().equals("no")) {
            paged = false;
        }
    }
    if ((a = programming.getAttribute("direct")) != null) {
        if (a.getValue().equals("no")) {
            directbit = false;
            directbyte = false;
        } else if (a.getValue().equals("bitOnly")) {
            directbit = true;
            directbyte = false;
        } else if (a.getValue().equals("byteOnly")) {
            directbit = false;
            directbyte = true;
        } else {
            directbit = true;
            directbyte = true;
        }
    }
    if ((a = programming.getAttribute("register")) != null) {
        if (a.getValue().equals("no")) {
            register = false;
        }
    }
    // find an accepted mode to set it to
    List<ProgrammingMode> modes = mProgrammer.getSupportedModes();
    if (log.isDebugEnabled()) {
        log.debug("XML specifies modes: P " + paged + " DBi " + directbit + " Dby " + directbyte + " R " + register + " now " + mProgrammer.getMode());
        log.debug("Programmer supports:");
        for (ProgrammingMode m : modes) {
            log.debug("   {} {}", m.getStandardName(), m.toString());
        }
    }
    // first try specified modes
    for (Element el1 : programming.getChildren("mode")) {
        String name = el1.getText();
        if (log.isDebugEnabled())
            log.debug(" mode {} was specified", name);
        for (ProgrammingMode m : modes) {
            if (name.equals(m.getStandardName())) {
                log.info("Programming mode selected: {} ({})", m.toString(), m.getStandardName());
                mProgrammer.setMode(m);
                return;
            }
        }
    }
    if (modes.contains(DefaultProgrammerManager.DIRECTMODE) && directbit && directbyte) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTMODE);
        log.debug("Set to DIRECTMODE");
    } else if (modes.contains(DefaultProgrammerManager.DIRECTBITMODE) && directbit) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTBITMODE);
        log.debug("Set to DIRECTBITMODE");
    } else if (modes.contains(DefaultProgrammerManager.DIRECTBYTEMODE) && directbyte) {
        mProgrammer.setMode(DefaultProgrammerManager.DIRECTBYTEMODE);
        log.debug("Set to DIRECTBYTEMODE");
    } else if (modes.contains(DefaultProgrammerManager.PAGEMODE) && paged) {
        mProgrammer.setMode(DefaultProgrammerManager.PAGEMODE);
        log.debug("Set to PAGEMODE");
    } else if (modes.contains(DefaultProgrammerManager.REGISTERMODE) && register) {
        mProgrammer.setMode(DefaultProgrammerManager.REGISTERMODE);
        log.debug("Set to REGISTERMODE");
    } else {
        log.warn("No acceptable mode found, leave as found");
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ProgrammingMode(jmri.ProgrammingMode)

Example 8 with ProgrammingMode

use of jmri.ProgrammingMode in project JMRI by JMRI.

the class PaneOpsProgFrame method pickProgrammerMode.

@Override
protected void pickProgrammerMode(@Nonnull Element programming) {
    // find an accepted mode to set it to
    List<ProgrammingMode> modes = mProgrammer.getSupportedModes();
    if (log.isDebugEnabled()) {
        log.debug("Programmer supports:");
        for (ProgrammingMode m : modes) {
            log.debug("   {} {}", m.getStandardName(), m.toString());
        }
    }
    // first try specified modes
    for (Element el1 : programming.getChildren("mode")) {
        String name = el1.getText();
        if (log.isDebugEnabled())
            log.debug(" mode {} was specified", name);
        for (ProgrammingMode m : modes) {
            if (name.equals(m.getStandardName())) {
                log.info("Programming mode selected: {} ({})", m.toString(), m.getStandardName());
                mProgrammer.setMode(m);
                return;
            }
        }
    }
    // else leave as it is
    log.debug("Leaving mode as is, supposed to be ops mode");
}
Also used : Element(org.jdom2.Element) ProgrammingMode(jmri.ProgrammingMode)

Example 9 with ProgrammingMode

use of jmri.ProgrammingMode in project JMRI by JMRI.

the class AbstractProgrammer method setMode.

@Override
public final void setMode(ProgrammingMode m) {
    List<ProgrammingMode> validModes = getSupportedModes();
    if (m == null) {
        if (validModes.size() > 0) {
            // null can only be set if there are no valid modes
            throw new IllegalArgumentException("Cannot set null mode when modes are present");
        } else {
            mode = null;
        }
    }
    if (validModes.contains(m)) {
        ProgrammingMode oldMode = mode;
        mode = m;
        notifyPropertyChange("Mode", oldMode, m);
    } else {
        throw new IllegalArgumentException("Invalid requested mode: " + m);
    }
}
Also used : ProgrammingMode(jmri.ProgrammingMode)

Example 10 with ProgrammingMode

use of jmri.ProgrammingMode in project JMRI by JMRI.

the class ProgOpsModePane method actionPerformed.

/**
     * Listen to buttons for mode changes.
     *
     * @param e ActionEvent heard
     */
@Override
public void actionPerformed(java.awt.event.ActionEvent e) {
    // find selected button
    log.debug("Selected button: {}", e.getActionCommand());
    for (ProgrammingMode mode : buttonMap.keySet()) {
        if (mode.toString().equals(e.getActionCommand())) {
            log.debug("      setting mode {} on {}", mode.toString(), getProgrammer());
            if (getProgrammer() != null) {
                log.debug("getProgrammer() != null");
                if (mode == DefaultProgrammerManager.OPSACCBYTEMODE) {
                    log.debug("OPS ACCY was selected in actionPerformed");
                    opsAccyMode = true;
                } else {
                    opsAccyMode = false;
                    getProgrammer().setMode(mode);
                }
            }
            setAddrParams();
            // 1st match
            return;
        }
    }
}
Also used : ProgrammingMode(jmri.ProgrammingMode)

Aggregations

ProgrammingMode (jmri.ProgrammingMode)13 JRadioButton (javax.swing.JRadioButton)4 Element (org.jdom2.Element)2 DefaultComboBoxModel (javax.swing.DefaultComboBoxModel)1 Programmer (jmri.Programmer)1 Attribute (org.jdom2.Attribute)1