use of jmri.DccLocoAddress in project JMRI by JMRI.
the class ConsistToolFrame method addLocoButtonActionPerformed.
public void addLocoButtonActionPerformed(ActionEvent e) {
if (locoSelector.getAddress() == null) {
return;
}
if (_Consist_Type == Consist.ADVANCED_CONSIST && adrSelector.getAddress() == null) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("NoConsistSelectedError"));
return;
} else if (_Consist_Type == Consist.ADVANCED_CONSIST && adrSelector.getAddress().isLongAddress()) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("RequiresShortConsistError"));
return;
} else if (_Consist_Type == Consist.CS_CONSIST && adrSelector.getAddress() == null) {
if (ConsistMan.csConsistNeedsSeperateAddress()) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("NoConsistSelectedError"));
return;
} else {
// We need to set an identifier so we can recall the
// consist. We're going to use the lead locomotive number
// for this.
adrSelector.setAddress(locoSelector.getAddress());
}
}
DccLocoAddress address = adrSelector.getAddress();
/*
* Make sure the marked consist type matches the consist type stored for
* this consist
*/
if (_Consist_Type != ConsistMan.getConsist(address).getConsistType()) {
if (log.isDebugEnabled()) {
if (_Consist_Type == Consist.ADVANCED_CONSIST) {
log.debug("Setting Consist Type to Advanced Consist");
} else if (_Consist_Type == Consist.CS_CONSIST) {
log.debug("Setting Consist Type to Command Station Assisted Consist");
}
}
ConsistMan.getConsist(address).setConsistType(_Consist_Type);
}
DccLocoAddress locoaddress = locoSelector.getAddress();
// consist, and add it to the consist if it is
if (!ConsistMan.getConsist(address).isAddressAllowed(locoaddress)) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("AddressNotAllowedError"));
} else {
if (ConsistMan.getConsist(address).contains(locoaddress)) {
JOptionPane.showMessageDialog(this, Bundle.getMessage("AddressAlreadyInConsistError"));
} else {
Consist tempConsist = ConsistMan.getConsist(address);
tempConsist.add(locoaddress, locoDirectionNormal.isSelected());
if (locoRosterBox.getSelectedRosterEntries().length == 1) {
tempConsist.setRosterId(locoaddress, locoRosterBox.getSelectedRosterEntries()[0].titleString());
}
}
if (consistAdrBox.getSelectedItem() != adrSelector.getAddress()) {
initializeConsistBox();
}
consistModel.fireTableDataChanged();
resetLocoButtonActionPerformed(e);
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class DccLocoAddressXml method getAddress.
public DccLocoAddress getAddress(Element element) {
if (element.getAttribute("number").getValue().equals("")) {
return null;
}
int number = Integer.parseInt(element.getAttribute("number").getValue());
boolean longaddress = false;
Attribute a = element.getAttribute("longaddress");
if (a != null && a.getValue().equals("yes")) {
longaddress = true;
}
return new DccLocoAddress(number, longaddress);
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class AbstractRailComReporter method getLocoAddress.
// Methods to support PhysicalLocationReporter interface
/**
* getLocoAddress()
*
* get the locomotive address we're reporting about from the current report.
*
* Note: We ignore the string passed in, because RailCom Reporters don't send
* String type reports.
*/
@Override
public LocoAddress getLocoAddress(String rep) {
// For now, we assume the current report.
// IdTag.getTagID() is a system-name-ized version of the loco address. I think.
// Matcher.group(1) : loco address (I think)
IdTag cr = (IdTag) this.getCurrentReport();
ReporterManager rm = InstanceManager.getDefault(jmri.ReporterManager.class);
Pattern p = Pattern.compile("" + rm.getSystemPrefix() + rm.typeLetter() + "(\\d+)");
Matcher m = p.matcher(cr.getTagID());
if (m.find()) {
log.debug("Parsed address: " + m.group(1));
// so we'll default to DCC for now.
return (new DccLocoAddress(Integer.parseInt(m.group(1)), LocoAddress.Protocol.DCC));
} else {
return (null);
}
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class DccConsist method contains.
// does the consist contain the specified address?
@Override
public boolean contains(DccLocoAddress address) {
if (ConsistType == ADVANCED_CONSIST) {
//String Address = Integer.toString(address);
return (ConsistList.contains(address));
} else {
log.error("Consist Type Not Supported");
notifyConsistListeners(new DccLocoAddress(0, false), ConsistListener.NotImplemented);
}
return false;
}
use of jmri.DccLocoAddress in project JMRI by JMRI.
the class DccConsist method reverse.
/*
* Reverse the order of locomotives in the consist and flip
* the direction bits of each locomotive.
*/
@Override
public void reverse() {
// save the old lead locomotive direction.
Boolean oldDir = ConsistDir.get(ConsistList.get(0));
// reverse the direction of the list
java.util.Collections.reverse(ConsistList);
// and then save the new lead locomotive direction
Boolean newDir = ConsistDir.get(ConsistList.get(0));
// and itterate through the list to reverse the directions of the
// individual elements of the list.
java.util.Iterator<DccLocoAddress> i = ConsistList.iterator();
while (i.hasNext()) {
DccLocoAddress locoaddress = i.next();
if (oldDir.equals(newDir)) {
add(locoaddress, getLocoDirection(locoaddress));
} else {
add(locoaddress, !getLocoDirection(locoaddress));
}
if (ConsistPosition.containsKey(locoaddress)) {
if (getPosition(locoaddress) == Consist.POSITION_LEAD) {
setPosition(locoaddress, Consist.POSITION_TRAIL);
} else if (getPosition(locoaddress) == Consist.POSITION_TRAIL) {
setPosition(locoaddress, Consist.POSITION_LEAD);
} else {
setPosition(locoaddress, ConsistList.size() - getPosition(locoaddress));
}
}
}
// notify any listeners that the consist changed
this.notifyConsistListeners(ConsistAddress, ConsistListener.OK);
}
Aggregations