use of jmri.GlobalProgrammerManager 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();
}
use of jmri.GlobalProgrammerManager in project JMRI by JMRI.
the class DeferringProgrammerManager method getGlobalProgrammer.
@Override
public Programmer getGlobalProgrammer() {
GlobalProgrammerManager gp = InstanceManager.getNullableDefault(GlobalProgrammerManager.class);
if (gp == null) {
log.debug("no defaultGlobal ProgrammerManager, getGlobalProgrammer returns null");
return null;
}
Programmer p = gp.getGlobalProgrammer();
log.debug("getGlobalProgrammer returns default service-mode programmer of type {} from {}", (p != null ? p.getClass() : "(null)"), gp.getClass());
return p;
}
use of jmri.GlobalProgrammerManager in project JMRI by JMRI.
the class DeferringProgrammerManager method releaseGlobalProgrammer.
@Override
public void releaseGlobalProgrammer(Programmer p) {
GlobalProgrammerManager gp = InstanceManager.getNullableDefault(GlobalProgrammerManager.class);
if (gp == null) {
return;
}
gp.releaseGlobalProgrammer(p);
}
use of jmri.GlobalProgrammerManager in project JMRI by JMRI.
the class RosterFrame method updateProgrammerStatus.
/*
* Handle setting up and updating the GUI for the types of progDebugger
* available.
*/
protected void updateProgrammerStatus() {
log.debug("Updating Programmer Status");
ConnectionConfig oldServMode = serModeProCon;
ConnectionConfig oldOpsMode = opsModeProCon;
// Find the connection that goes with the global programmer
GlobalProgrammerManager gpm = InstanceManager.getNullableDefault(GlobalProgrammerManager.class);
if (gpm != null) {
String serviceModeProgrammerName = gpm.getUserName();
log.debug("GlobalProgrammerManager found of class {} name {} ", gpm.getClass(), serviceModeProgrammerName);
for (ConnectionConfig connection : InstanceManager.getDefault(ConnectionConfigManager.class)) {
log.debug("Checking connection name {}", connection.getConnectionName());
if (connection.getConnectionName() != null && connection.getConnectionName().equals(serviceModeProgrammerName)) {
log.debug("Connection found for GlobalProgrammermanager");
serModeProCon = connection;
}
}
}
// Find the connection that goes with the addressed programmer
AddressedProgrammerManager apm = InstanceManager.getNullableDefault(AddressedProgrammerManager.class);
if (apm != null) {
String opsModeProgrammerName = apm.getUserName();
log.debug("AddressedProgrammerManager found of class {} name {} ", apm.getClass(), opsModeProgrammerName);
for (ConnectionConfig connection : InstanceManager.getDefault(ConnectionConfigManager.class)) {
log.debug("Checking connection name {}", connection.getConnectionName());
if (connection.getConnectionName() != null && connection.getConnectionName().equals(opsModeProgrammerName)) {
log.debug("Connection found for AddressedProgrammermanager");
opsModeProCon = connection;
}
}
}
if (serModeProCon != null && gpm.isGlobalProgrammerAvailable()) {
if (ConnectionStatus.instance().isConnectionOk(serModeProCon.getConnectionName(), serModeProCon.getInfo())) {
log.debug("GPM Connection online");
serviceModeProgrammerLabel.setText(Bundle.getMessage("ServiceModeProgOnline", serModeProCon.getConnectionName()));
serviceModeProgrammerLabel.setForeground(new Color(0, 128, 0));
} else {
log.debug("GPM Connection onffline");
serviceModeProgrammerLabel.setText(Bundle.getMessage("ServiceModeProgOffline", serModeProCon.getConnectionName()));
serviceModeProgrammerLabel.setForeground(Color.red);
}
if (oldServMode == null) {
contextService.setEnabled(true);
contextService.setVisible(true);
service.setEnabled(true);
service.setVisible(true);
firePropertyChange("setprogservice", "setEnabled", true);
}
} else if (gpm != null && gpm.isGlobalProgrammerAvailable()) {
if (ConnectionStatus.instance().isSystemOk(gpm.getUserName())) {
log.debug("GPM Connection online");
serviceModeProgrammerLabel.setText(Bundle.getMessage("ServiceModeProgOnline", gpm.getUserName()));
serviceModeProgrammerLabel.setForeground(new Color(0, 128, 0));
} else {
log.debug("GPM Connection onffline");
serviceModeProgrammerLabel.setText(Bundle.getMessage("ServiceModeProgOffline", gpm.getUserName()));
serviceModeProgrammerLabel.setForeground(Color.red);
}
if (oldServMode == null) {
contextService.setEnabled(true);
contextService.setVisible(true);
service.setEnabled(true);
service.setVisible(true);
firePropertyChange("setprogservice", "setEnabled", true);
}
} else {
// No service programmer available, disable interface sections not available
serviceModeProgrammerLabel.setText(Bundle.getMessage("NoServiceProgrammerAvailable"));
serviceModeProgrammerLabel.setForeground(Color.red);
if (oldServMode != null) {
contextService.setEnabled(false);
contextService.setVisible(false);
service.setEnabled(false);
service.setVisible(false);
firePropertyChange("setprogservice", "setEnabled", false);
}
// Disable Identify in toolBar
// This relies on it being the 2nd item in the tool bar, as defined in xml//config/parts/jmri/jmrit/roster/swing/RosterFrameToolBar.xml
// Because of I18N, we don't look for a particular Action name here
getToolBar().getComponents()[1].setEnabled(false);
}
if (opsModeProCon != null && apm.isAddressedModePossible()) {
if (ConnectionStatus.instance().isConnectionOk(opsModeProCon.getConnectionName(), opsModeProCon.getInfo())) {
log.debug("Ops Mode Connection online");
operationsModeProgrammerLabel.setText(Bundle.getMessage("OpsModeProgOnline", opsModeProCon.getConnectionName()));
operationsModeProgrammerLabel.setForeground(new Color(0, 128, 0));
} else {
log.debug("Ops Mode Connection offline");
operationsModeProgrammerLabel.setText(Bundle.getMessage("OpsModeProgOffline", opsModeProCon.getConnectionName()));
operationsModeProgrammerLabel.setForeground(Color.red);
}
if (oldOpsMode == null) {
contextOps.setEnabled(true);
contextOps.setVisible(true);
ops.setEnabled(true);
ops.setVisible(true);
firePropertyChange("setprogops", "setEnabled", true);
}
} else if (apm != null && apm.isAddressedModePossible()) {
if (ConnectionStatus.instance().isSystemOk(apm.getUserName())) {
log.debug("Ops Mode Connection online");
operationsModeProgrammerLabel.setText(Bundle.getMessage("OpsModeProgOnline", apm.getUserName()));
operationsModeProgrammerLabel.setForeground(new Color(0, 128, 0));
} else {
log.debug("Ops Mode Connection offline");
operationsModeProgrammerLabel.setText(Bundle.getMessage("OpsModeProgOffline", apm.getUserName()));
operationsModeProgrammerLabel.setForeground(Color.red);
}
if (oldOpsMode == null) {
contextOps.setEnabled(true);
contextOps.setVisible(true);
ops.setEnabled(true);
ops.setVisible(true);
firePropertyChange("setprogops", "setEnabled", true);
}
} else {
operationsModeProgrammerLabel.setText(Bundle.getMessage("NoOpsProgrammerAvailable"));
operationsModeProgrammerLabel.setForeground(Color.red);
if (oldOpsMode != null) {
contextOps.setEnabled(false);
contextOps.setVisible(false);
ops.setEnabled(false);
ops.setVisible(false);
firePropertyChange("setprogops", "setEnabled", false);
}
}
String strProgMode;
if (service.isEnabled()) {
contextService.setSelected(true);
service.setSelected(true);
strProgMode = "setprogservice";
modePanel.setVisible(true);
} else if (ops.isEnabled()) {
contextOps.setSelected(true);
ops.setSelected(true);
strProgMode = "setprogops";
modePanel.setVisible(false);
} else {
contextEdit.setSelected(true);
edit.setSelected(true);
modePanel.setVisible(false);
strProgMode = "setprogedit";
}
firePropertyChange(strProgMode, "setSelected", true);
}
Aggregations