use of jmri.LocoAddress in project JMRI by JMRI.
the class LocoAddressXml method store.
/**
* Default implementation for storing the contents of a LocoAddress
*
* @param o Object to store, of type LocoAddress
* @return Element containing the complete info
*/
@Override
public Element store(Object o) {
LocoAddress p = (LocoAddress) o;
Element element = new Element("locoaddress");
// include contents, we shall also store the old format for backward compatability
DccLocoAddressXml adapter = new DccLocoAddressXml();
element.addContent(adapter.store(p));
if (p != null) {
element.addContent(new Element("number").addContent("" + p.getNumber()));
element.addContent(new Element("protocol").addContent(p.getProtocol().getShortName()));
} else {
element.addContent(new Element("number").addContent(""));
element.addContent(new Element("protocol").addContent(""));
}
return element;
}
use of jmri.LocoAddress in project JMRI by JMRI.
the class LnReporterTest method testLnReporterGetLocoAddress.
public void testLnReporterGetLocoAddress() {
LnReporter r = new LnReporter(3, tc, "L");
LocoAddress t = r.getLocoAddress("7413 enter");
assertEquals("getLocoAddress", t.getNumber(), 7413);
}
use of jmri.LocoAddress in project JMRI by JMRI.
the class VSDecoder method propertyChange.
/**
* Respond to property change events from this VSDecoder's GUI
*
* @param evt (PropertyChangeEvent) event to respond to
*/
@SuppressWarnings("cast")
@Override
public void propertyChange(PropertyChangeEvent evt) {
String property = evt.getPropertyName();
// Respond to events from the new GUI.
if (evt.getSource() instanceof VSDControl) {
if (property.equals(VSDControl.PCIDMap.get(VSDControl.PropertyChangeID.OPTION_CHANGE))) {
Train selected_train = TrainManager.instance().getTrainByName((String) evt.getNewValue());
if (selected_train != null) {
selected_train.addPropertyChangeListener(this);
}
}
return;
}
// Respond to events from the old GUI.
if ((property.equals(VSDManagerFrame.PCIDMap.get(VSDManagerFrame.PropertyChangeID.MUTE))) || (property.equals(VSDecoderPane.PCIDMap.get(VSDecoderPane.PropertyChangeID.MUTE)))) {
// Either GUI Mute button
log.debug("VSD: Mute change. value = " + evt.getNewValue());
Boolean b = (Boolean) evt.getNewValue();
this.mute(b.booleanValue());
} else if ((property.equals(VSDManagerFrame.PCIDMap.get(VSDManagerFrame.PropertyChangeID.VOLUME_CHANGE))) || (property.equals(VSDecoderPane.PCIDMap.get(VSDecoderPane.PropertyChangeID.VOLUME_CHANGE)))) {
// Either GUI Volume slider
log.debug("VSD: Volume change. value = " + evt.getNewValue());
// Slider gives integer 0-100. Need to change that to a float 0.0-1.0
this.setMasterVolume((1.0f * (Integer) evt.getNewValue()) / 100.0f);
} else if (property.equals(VSDecoderPane.PCIDMap.get(VSDecoderPane.PropertyChangeID.ADDRESS_CHANGE))) {
// OLD GUI Address Change
log.debug("Decoder set address = " + (LocoAddress) evt.getNewValue());
this.setAddress((LocoAddress) evt.getNewValue());
this.enable();
} else if (property.equals(Train.TRAIN_LOCATION_CHANGED_PROPERTY)) {
// Train Location Move (either GUI)
PhysicalLocation p = getTrainPosition((Train) evt.getSource());
if (p != null) {
this.setPosition(getTrainPosition((Train) evt.getSource()));
} else {
log.debug("Train has null position");
this.setPosition(new PhysicalLocation());
}
} else if (property.equals(Train.STATUS_CHANGED_PROPERTY)) {
// Train Status change (either GUI)
String status = (String) evt.getNewValue();
log.debug("Train status changed: " + status);
log.debug("New Location: " + getTrainPosition((Train) evt.getSource()));
if ((status.startsWith(Train.BUILT)) || (status.startsWith(Train.PARTIAL_BUILT))) {
log.debug("Train built. status = " + status);
PhysicalLocation p = getTrainPosition((Train) evt.getSource());
if (p != null) {
this.setPosition(getTrainPosition((Train) evt.getSource()));
} else {
log.debug("Train has null position");
this.setPosition(new PhysicalLocation());
}
}
}
}
use of jmri.LocoAddress in project JMRI by JMRI.
the class VSDecoderManager method setDecoderPositionByAddr.
public void setDecoderPositionByAddr(LocoAddress a, PhysicalLocation l) {
// OK, this whole LocoAddress vs. DccLocoAddress thing has rendered this SUPER HOKEY.
if (a == null) {
log.warn("Decoder Address is Null");
return;
}
if (l == null) {
log.warn("PhysicalLocation is Null");
return;
}
if (l.equals(PhysicalLocation.Origin)) {
log.debug("Location : " + l.toString() + " ... ignoring.");
// Physical location at origin means it hasn't been set.
return;
}
log.debug("Decoder Address: " + a.getNumber());
for (VSDecoder d : decodertable.values()) {
// since the LnReprter can't tell the difference and will always report "DCC".
if (d == null) {
log.debug("VSdecoder null pointer!");
return;
}
LocoAddress pa = d.getAddress();
if (pa == null) {
log.debug("Vsdecoder" + d + " address null!");
return;
}
LocoAddress.Protocol p = d.getAddress().getProtocol();
if (p == null) {
log.debug("Vsdecoder" + d + " address = " + pa + " protocol null!");
return;
}
if ((p == LocoAddress.Protocol.DCC_LONG) || (p == LocoAddress.Protocol.DCC_SHORT)) {
p = LocoAddress.Protocol.DCC;
}
if ((d.getAddress().getNumber() == a.getNumber()) && (p == a.getProtocol())) {
d.setPosition(l);
// Loop through all the decoders (assumes N will be "small"), in case
// there are multiple decoders with the same address. This will be somewhat broken
// if there's a DCC_SHORT and a DCC_LONG decoder with the same address number.
//return;
}
}
// decoder not found. Do nothing.
return;
}
Aggregations