Search in sources :

Example 11 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalGroupTableAction method propertyChange.

@Override
public void propertyChange(java.beans.PropertyChangeEvent e) {
    if (e.getPropertyName().equals("UpdateCondition")) {
        for (int i = _signalHeadsList.size() - 1; i >= 0; i--) {
            SignalGroupSignalHead signalHead = _signalHeadsList.get(i);
            SignalHead sigBean = signalHead.getBean();
            if (curSignalGroup.isHeadIncluded(sigBean)) {
                signalHead.setIncluded(true);
                signalHead.setOnState(curSignalGroup.getHeadOnState(sigBean));
                signalHead.setOffState(curSignalGroup.getHeadOffState(sigBean));
            } else {
                signalHead.setIncluded(false);
            }
        }
    }
}
Also used : SignalHead(jmri.SignalHead)

Example 12 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class IconAdder method makeIconMap.

void makeIconMap(NamedBean bean) {
    if (bean != null && _type != null && _type.equals("SignalHead")) {
        _order = new ArrayList<>();
        _iconMap = new HashMap<>(12);
        int k = 0;
        ArrayList<CatalogTreeLeaf> list = _defaultIcons.getLeaves();
        String[] states = ((SignalHead) bean).getValidStateNames();
        for (int i = 0; i < list.size(); i++) {
            CatalogTreeLeaf leaf = list.get(i);
            String name = leaf.getName();
            try {
                name = Bundle.getMessage(leaf.getName());
            } catch (java.util.MissingResourceException mre) {
            }
            if (log.isDebugEnabled()) {
                log.debug("makeIconMap: leafName= " + leaf.getName() + ", name= " + name);
            }
            for (String state : states) {
                if (name.equals(state) || leaf.getName().equals(Bundle.getMessage("SignalHeadStateDark")) || leaf.getName().equals(Bundle.getMessage("SignalHeadStateHeld"))) {
                    String path = leaf.getPath();
                    this.setIcon(k++, leaf.getName(), new NamedIcon(path, path));
                    break;
                }
            }
        }
    } else {
        makeIcons(_defaultIcons);
    }
    if (log.isDebugEnabled()) {
        log.debug("makeIconMap: _iconMap.size()= " + _iconMap.size());
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) CatalogTreeLeaf(jmri.jmrit.catalog.CatalogTreeLeaf) SignalHead(jmri.SignalHead)

Example 13 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalHeadSignalMast method setAppearances.

//taken out of the defaultsignalappearancemap
public void setAppearances(String aspect) {
    if (map == null) {
        log.error("No appearance map defined, unable to set appearance " + getDisplayName());
        return;
    }
    if (map.getSignalSystem() != null && map.getSignalSystem().checkAspect(aspect) && map.getAspectSettings(aspect) != null) {
        log.warn("Attempt to set " + getSystemName() + " to undefined aspect: " + aspect);
    } else if ((map.getAspectSettings(aspect) != null) && (heads.size() > map.getAspectSettings(aspect).length)) {
        log.warn("setAppearance to \"" + aspect + "\" finds " + heads.size() + " heads but only " + map.getAspectSettings(aspect).length + " settings");
    }
    int delay = 0;
    try {
        if (map.getProperty(aspect, "delay") != null) {
            delay = Integer.parseInt(map.getProperty(aspect, "delay"));
        }
    } catch (Exception e) {
        log.debug("No delay set");
    //can be considered normal if does not exists or is invalid
    }
    HashMap<SignalHead, Integer> delayedSet = new HashMap<SignalHead, Integer>(heads.size());
    for (int i = 0; i < heads.size(); i++) {
        // some extensive checking
        boolean error = false;
        if (heads.get(i) == null) {
            log.error("Head {} unexpectedly null in setAppearances while setting aspect \"{}\" for {}", i, aspect, getSystemName());
            error = true;
        }
        if (heads.get(i).getBean() == null) {
            log.error("Head {} getBean() unexpectedly null in setAppearances while setting aspect \"{}\" for {}", i, aspect, getSystemName());
            error = true;
        }
        if (map.getAspectSettings(aspect) == null) {
            log.error("Couldn't get table array for aspect \"{}\" in setAppearances for {}", aspect, getSystemName());
            error = true;
        }
        if (!error) {
            SignalHead head = heads.get(i).getBean();
            int toSet = map.getAspectSettings(aspect)[i];
            if (delay == 0) {
                head.setAppearance(toSet);
                if (log.isDebugEnabled()) {
                    log.debug("Setting " + head.getSystemName() + " to " + head.getAppearanceName(toSet));
                }
            } else {
                delayedSet.put(head, toSet);
            }
        } else {
            log.error("     head appearance not set due to above error");
        }
    }
    if (delay != 0) {
        //If a delay is required we will fire this off into a seperate thread and let it get on with it.
        final HashMap<SignalHead, Integer> thrDelayedSet = delayedSet;
        final int thrDelay = delay;
        Runnable r = new Runnable() {

            @Override
            public void run() {
                setDelayedAppearances(thrDelayedSet, thrDelay);
            }
        };
        Thread thr = new Thread(r);
        thr.setName(getDisplayName() + " delayed set appearance");
        thr.setDaemon(true);
        try {
            thr.start();
        } catch (java.lang.IllegalThreadStateException ex) {
            log.error(ex.toString());
        }
    }
    return;
}
Also used : HashMap(java.util.HashMap) SignalHead(jmri.SignalHead)

Example 14 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class AbstractSignalHeadServer method setSignalHeadAppearance.

protected void setSignalHeadAppearance(String signalHeadName, int signalHeadState) {
    SignalHead signalHead;
    try {
        addSignalHeadToList(signalHeadName);
        signalHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(signalHeadName);
        if (signalHead == null) {
            // only log, since this may be from a remote system
            log.error("SignalHead " + signalHeadName + " is not available.");
        } else {
            if (signalHead.getAppearance() != signalHeadState || signalHead.getHeld()) {
                if (signalHeadState == SignalHead.HELD) {
                    signalHead.setHeld(true);
                } else {
                    if (signalHead.getHeld())
                        signalHead.setHeld(false);
                    signalHead.setAppearance(signalHeadState);
                }
            } else {
                try {
                    sendStatus(signalHeadName, signalHeadState);
                } catch (IOException ex) {
                    log.error("Error sending appearance", ex);
                }
            }
        }
    } catch (Exception ex) {
        log.error("Exception setting signalHead " + signalHeadName + " appearance:", ex);
    }
}
Also used : SignalHead(jmri.SignalHead) IOException(java.io.IOException) JmriException(jmri.JmriException) IOException(java.io.IOException) JsonException(jmri.server.json.JsonException)

Example 15 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SimpleSignalHeadServer method parseStatus.

@Override
public void parseStatus(String statusString) throws JmriException, IOException {
    String[] status = statusString.split("\\s+");
    if (status.length == 3) {
        this.setSignalHeadAppearance(status[1], status[2]);
    } else {
        SignalHead signalHead = InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(status[1]);
        this.sendStatus(signalHead.getSystemName(), signalHead.getAppearance());
    }
}
Also used : SignalHead(jmri.SignalHead)

Aggregations

SignalHead (jmri.SignalHead)73 Turnout (jmri.Turnout)20 Element (org.jdom2.Element)13 SignalMast (jmri.SignalMast)12 Sensor (jmri.Sensor)11 JsonException (jmri.server.json.JsonException)8 Test (org.junit.Test)7 NamedBean (jmri.NamedBean)6 DoubleTurnoutSignalHead (jmri.implementation.DoubleTurnoutSignalHead)6 QuadOutputSignalHead (jmri.implementation.QuadOutputSignalHead)6 SingleTurnoutSignalHead (jmri.implementation.SingleTurnoutSignalHead)6 TripleOutputSignalHead (jmri.implementation.TripleOutputSignalHead)6 TripleTurnoutSignalHead (jmri.implementation.TripleTurnoutSignalHead)6 SignalHeadManager (jmri.SignalHeadManager)5 DccSignalHead (jmri.implementation.DccSignalHead)5 JsonNode (com.fasterxml.jackson.databind.JsonNode)4 JmriException (jmri.JmriException)4 Light (jmri.Light)4 SuppressFBWarnings (edu.umd.cs.findbugs.annotations.SuppressFBWarnings)3 ActionEvent (java.awt.event.ActionEvent)3