Search in sources :

Example 71 with DccLocoAddress

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

Example 72 with DccLocoAddress

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

Example 73 with DccLocoAddress

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

Example 74 with DccLocoAddress

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

Example 75 with DccLocoAddress

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