use of jmri.DccLocoAddress in project JMRI by JMRI.
the class AddressPanel method destroy.
public void destroy() {
// Handle disposing of the throttle
if (throttle != null) {
DccLocoAddress l = (DccLocoAddress) throttle.getLocoAddress();
throttle.removePropertyChangeListener(this);
InstanceManager.throttleManagerInstance().cancelThrottleRequest(l.getNumber(), this);
InstanceManager.throttleManagerInstance().releaseThrottle(throttle, this);
notifyListenersOfThrottleRelease();
throttle = null;
}
if (consistThrottle != null) {
InstanceManager.throttleManagerInstance().releaseThrottle(consistThrottle, this);
notifyListenersOfThrottleRelease();
consistThrottle = null;
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class AddressPanel method setXml.
/**
* Use the Element passed to initialize based on user prefs.
*
* @param e The Element containing prefs as defined in DTD/throttle-config
*/
@SuppressWarnings("unchecked")
public void setXml(Element e) {
Element window = e.getChild("window");
WindowPreferences.setPreferences(this, window);
Element addressElement = e.getChild("address");
if ((addressElement != null) && (this.getRosterEntry() == null)) {
String address = addressElement.getAttribute("value").getValue();
addrSelector.setAddress(new DccLocoAddress(Integer.parseInt(address), // guess at the short/long
false));
consistAddress = null;
changeOfAddress();
}
List<Element> elementList = e.getChildren("locoaddress");
if ((elementList.size() > 0) && (getThrottle() == null)) {
log.debug("found " + elementList.size() + " locoaddress");
addrSelector.setAddress((DccLocoAddress) (new jmri.configurexml.LocoAddressXml()).getAddress(elementList.get(0)));
consistAddress = null;
// if there are two locoaddress, the second is the consist address
if (elementList.size() > 1) {
consistAddress = ((DccLocoAddress) (new jmri.configurexml.LocoAddressXml()).getAddress(elementList.get(1)));
}
changeOfAddress();
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class AddressPanel method consistRosterSelected.
private void consistRosterSelected() {
if (!(conRosterBox.getSelectedItem().equals(Bundle.getMessage("NoConsistSelected")))) {
String rosterEntryTitle = conRosterBox.getSelectedItem().toString();
NceConsistRosterEntry cre = NceConsistRoster.instance().entryFromTitle(rosterEntryTitle);
DccLocoAddress a = new DccLocoAddress(Integer.parseInt(cre.getLoco1DccAddress()), cre.isLoco1LongAddress());
addrSelector.setAddress(a);
consistAddress = null;
int cA = 0;
try {
cA = Integer.parseInt(cre.getConsistNumber());
} catch (NumberFormatException e) {
}
if (0 < cA && cA < 128) {
consistAddress = new DccLocoAddress(cA, false);
} else {
log.warn("consist number missing " + cre.getLoco1DccAddress());
JOptionPane.showMessageDialog(mainPanel, Bundle.getMessage("ConsistNumberHasNotBeenAssigned"), Bundle.getMessage("NeedsConsistNumber"), JOptionPane.ERROR_MESSAGE);
return;
}
if (JOptionPane.showConfirmDialog(mainPanel, Bundle.getMessage("SendFunctionToLead"), Bundle.getMessage("NCEconsistThrottle"), JOptionPane.YES_NO_OPTION) != JOptionPane.YES_OPTION) {
addrSelector.setAddress(consistAddress);
consistAddress = null;
}
changeOfAddress();
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ThrottlesTableModel method notifyAddressReleased.
@Override
public void notifyAddressReleased(LocoAddress addr) {
DccLocoAddress la = (DccLocoAddress) addr;
fireTableDataChanged();
jmri.InstanceManager.throttleManagerInstance().removeListener(la, this);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class AbstractThrottle method removePropertyChangeListener.
// register for notification if any of the properties change
@Override
public void removePropertyChangeListener(PropertyChangeListener l) {
log.debug("Removing property change " + l);
if (listeners.contains(l)) {
listeners.removeElement(l);
}
log.debug("remove listeners size is " + listeners.size());
if ((listeners.isEmpty())) {
log.debug("No listeners so will call the dispose in the InstanceManger with an empty throttleListenr null value");
InstanceManager.throttleManagerInstance().disposeThrottle(this, new ThrottleListener() {
@Override
public void notifyFailedThrottleRequest(DccLocoAddress address, String reason) {
}
@Override
public void notifyThrottleFound(DccThrottle t) {
}
});
}
}
Aggregations