Search in sources :

Example 46 with DccLocoAddress

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);
    }
}
Also used : Consist(jmri.Consist) DccLocoAddress(jmri.DccLocoAddress)

Example 47 with DccLocoAddress

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);
}
Also used : Attribute(org.jdom2.Attribute) DccLocoAddress(jmri.DccLocoAddress)

Example 48 with DccLocoAddress

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);
    }
}
Also used : Pattern(java.util.regex.Pattern) ReporterManager(jmri.ReporterManager) Matcher(java.util.regex.Matcher) IdTag(jmri.IdTag) DccLocoAddress(jmri.DccLocoAddress)

Example 49 with DccLocoAddress

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;
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Example 50 with DccLocoAddress

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);
}
Also used : DccLocoAddress(jmri.DccLocoAddress)

Aggregations

DccLocoAddress (jmri.DccLocoAddress)96 Consist (jmri.Consist)12 ThrottleManager (jmri.ThrottleManager)7 IOException (java.io.IOException)6 Element (org.jdom2.Element)6 Test (org.junit.Test)6 Matcher (java.util.regex.Matcher)5 DccThrottle (jmri.DccThrottle)5 SystemConnectionMemo (jmri.jmrix.SystemConnectionMemo)5 JsonException (jmri.server.json.JsonException)5 Pattern (java.util.regex.Pattern)4 IdTag (jmri.IdTag)3 JsonNode (com.fasterxml.jackson.databind.JsonNode)2 ArrayNode (com.fasterxml.jackson.databind.node.ArrayNode)2 ObjectNode (com.fasterxml.jackson.databind.node.ObjectNode)2 ArrayList (java.util.ArrayList)2 Locale (java.util.Locale)2 JTextField (javax.swing.JTextField)2 CommandStation (jmri.CommandStation)2 ProgrammerException (jmri.ProgrammerException)2