Search in sources :

Example 1 with IdentifyLoco

use of jmri.jmrit.roster.IdentifyLoco in project JMRI by JMRI.

the class KnownLocoSelPane method startIdentify.

private void startIdentify() {
    // start identifying a loco
    final KnownLocoSelPane me = this;
    Programmer p = null;
    if (selector != null && selector.isSelected())
        p = selector.getProgrammer();
    if (p == null) {
        log.warn("Selector did not provide a programmer, use default");
        p = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
    }
    IdentifyLoco id = new IdentifyLoco(p) {

        private KnownLocoSelPane who = me;

        @Override
        protected void done(int dccAddress) {
            // if Done, updated the selected decoder
            who.selectLoco(dccAddress);
        }

        @Override
        protected void message(String m) {
            if (mStatusLabel != null) {
                mStatusLabel.setText(m);
            }
        }

        @Override
        public void error() {
        }
    };
    id.start();
}
Also used : Programmer(jmri.Programmer) IdentifyLoco(jmri.jmrit.roster.IdentifyLoco)

Example 2 with IdentifyLoco

use of jmri.jmrit.roster.IdentifyLoco in project JMRI by JMRI.

the class RosterFrame method startIdentifyLoco.

/**
     * Start the identify operation after [Identify Loco] button pressed.
     * <p>
     * This defines what happens when the identify is done.
     */
//taken out of CombinedLocoSelPane
protected void startIdentifyLoco() {
    final RosterFrame me = this;
    Programmer programmer = null;
    if (modePanel.isSelected()) {
        programmer = modePanel.getProgrammer();
    }
    if (programmer == null) {
        GlobalProgrammerManager gpm = InstanceManager.getNullableDefault(GlobalProgrammerManager.class);
        if (gpm != null) {
            programmer = gpm.getGlobalProgrammer();
            log.warn("Selector did not provide a programmer, attempt to use GlobalProgrammerManager default: {}", programmer);
        } else {
            ProgrammerManager dpm = InstanceManager.getNullableDefault(jmri.ProgrammerManager.class);
            if (dpm != null) {
                programmer = dpm.getGlobalProgrammer();
                log.warn("Selector did not provide a programmer, attempt to use InstanceManager default: {}", programmer);
            } else {
                log.warn("Selector did not provide a programmer, and no ProgramManager found in InstanceManager");
            }
        }
    }
    // if failed to get programmer, tell user and stop
    if (programmer == null) {
        log.error("Identify loco called when no service mode programmer is available; button should have been disabled");
        JOptionPane.showMessageDialog(null, Bundle.getMessage("IdentifyError"));
        return;
    }
    // and now do the work
    IdentifyLoco ident = new IdentifyLoco(programmer) {

        private final RosterFrame who = me;

        @Override
        protected void done(int dccAddress) {
            // if Done, updated the selected decoder
            // on the GUI thread, right now
            jmri.util.ThreadingUtil.runOnGUI(() -> {
                who.selectLoco(dccAddress, !shortAddr, cv8val, cv7val);
            });
        }

        @Override
        protected void message(String m) {
            // on the GUI thread, right now
            jmri.util.ThreadingUtil.runOnGUI(() -> {
                statusField.setText(m);
            });
        }

        @Override
        protected void error() {
        // raise the button again
        //idloco.setSelected(false);
        }
    };
    ident.start();
}
Also used : Programmer(jmri.Programmer) ProgrammerManager(jmri.ProgrammerManager) GlobalProgrammerManager(jmri.GlobalProgrammerManager) AddressedProgrammerManager(jmri.AddressedProgrammerManager) IdentifyLoco(jmri.jmrit.roster.IdentifyLoco) GlobalProgrammerManager(jmri.GlobalProgrammerManager)

Example 3 with IdentifyLoco

use of jmri.jmrit.roster.IdentifyLoco in project JMRI by JMRI.

the class CombinedLocoSelPane method startIdentifyLoco.

/**
     * Identify loco button pressed, start the identify operation This defines
     * what happens when the identify is done.
     */
protected void startIdentifyLoco() {
    // start identifying a loco
    final CombinedLocoSelPane me = this;
    Programmer p = null;
    if (selector != null && selector.isSelected()) {
        p = selector.getProgrammer();
    }
    if (p == null) {
        log.warn("Selector did not provide a programmer, use default");
        p = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
    }
    IdentifyLoco id = new IdentifyLoco(p) {

        private CombinedLocoSelPane who = me;

        @Override
        protected void done(int dccAddress) {
            // if Done, updated the selected decoder
            who.selectLoco(dccAddress);
        }

        @Override
        protected void message(String m) {
            if (_statusLabel != null) {
                _statusLabel.setText(m);
            }
        }

        @Override
        protected void error() {
            // raise the button again
            idloco.setSelected(false);
        }
    };
    id.start();
}
Also used : Programmer(jmri.Programmer) IdentifyLoco(jmri.jmrit.roster.IdentifyLoco)

Aggregations

Programmer (jmri.Programmer)3 IdentifyLoco (jmri.jmrit.roster.IdentifyLoco)3 AddressedProgrammerManager (jmri.AddressedProgrammerManager)1 GlobalProgrammerManager (jmri.GlobalProgrammerManager)1 ProgrammerManager (jmri.ProgrammerManager)1