use of jmri.ProgrammerManager 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();
}
Aggregations