Search in sources :

Example 46 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class AddSignalMastPanel method refreshHeadComboBox.

protected void refreshHeadComboBox() {
    if (!Bundle.getMessage("HeadCtlMast").equals(signalMastDriver.getSelectedItem())) {
        return;
    }
    if (includeUsed.isSelected()) {
        alreadyUsed = new ArrayList<NamedBean>();
    } else {
        List<SignalHead> alreadyUsedHeads = SignalHeadSignalMast.getSignalHeadsUsed();
        alreadyUsed = new ArrayList<NamedBean>();
        for (SignalHead head : alreadyUsedHeads) {
            alreadyUsed.add(head);
        }
    }
    for (JmriBeanComboBox head : headList) {
        head.excludeItems(alreadyUsed);
    }
}
Also used : JmriBeanComboBox(jmri.util.swing.JmriBeanComboBox) NamedBean(jmri.NamedBean) SignalHead(jmri.SignalHead)

Example 47 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class SignalHeadIconXml method load.

/**
     * Create a PositionableLabel, then add to a target JLayeredPane
     *
     * @param element Top level Element to unpack.
     * @param o       an Editor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    Editor ed = (Editor) o;
    SignalHeadIcon l = new SignalHeadIcon(ed);
    String name;
    Attribute attr = element.getAttribute("signalhead");
    if (attr == null) {
        log.error("incorrect information for signal head; must use signalhead name");
        ed.loadFailed();
        return;
    } else {
        name = attr.getValue();
    }
    SignalHead sh = jmri.InstanceManager.getDefault(jmri.SignalHeadManager.class).getSignalHead(name);
    if (sh != null) {
        l.setSignalHead(name);
    } else {
        log.error("SignalHead named '" + attr.getValue() + "' not found.");
        //    ed.loadFailed();
        return;
    }
    int rotation = 0;
    try {
        attr = element.getAttribute("rotate");
        rotation = attr.getIntValue();
    } catch (org.jdom2.DataConversionException e) {
    } catch (NullPointerException e) {
    // considered normal if the attributes are not present
    }
    List<Element> aspects = element.getChildren();
    if (aspects.size() > 0) {
        Element icons = element.getChild("icons");
        Element elem = element;
        if (icons != null) {
            List<Element> c = icons.getChildren();
            aspects = c;
            elem = icons;
        }
        for (int i = 0; i < aspects.size(); i++) {
            String aspect = aspects.get(i).getName();
            NamedIcon icon = loadIcon(l, aspect, elem, "SignalHead \"" + name + "\": icon \"" + aspect + "\" ", ed);
            if (icon != null) {
                l.setIcon(_nameMap.get(aspect), icon);
            } else {
                log.info("SignalHead \"" + name + "\": icon \"" + aspect + "\" removed");
            }
        }
        log.debug(aspects.size() + " icons loaded for " + l.getNameString());
    } else {
        // old style as attributes - somewhere around pre 2.5.4
        NamedIcon icon = loadSignalIcon("red", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateRed"), icon);
        }
        icon = loadSignalIcon("yellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateYellow"), icon);
        }
        icon = loadSignalIcon("green", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateGreen"), icon);
        }
        icon = loadSignalIcon("lunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateLunar"), icon);
        }
        icon = loadSignalIcon("held", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateHeld"), icon);
        }
        icon = loadSignalIcon("dark", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateDark"), icon);
        }
        icon = loadSignalIcon("flashred", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingRed"), icon);
        }
        icon = loadSignalIcon("flashyellow", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingYellow"), icon);
        }
        icon = loadSignalIcon("flashgreen", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingGreen"), icon);
        }
        icon = loadSignalIcon("flashlunar", rotation, l, element, name, ed);
        if (icon != null) {
            l.setIcon(rbean.getString("SignalHeadStateFlashingLunar"), icon);
        }
    }
    Element elem = element.getChild("iconmaps");
    if (elem != null) {
        attr = elem.getAttribute("family");
        if (attr != null) {
            l.setFamily(attr.getValue());
        }
    }
    try {
        attr = element.getAttribute("clickmode");
        if (attr != null) {
            l.setClickMode(attr.getIntValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on clickmode attribute: " + e);
    }
    try {
        attr = element.getAttribute("litmode");
        if (attr != null) {
            l.setLitMode(attr.getBooleanValue());
        }
    } catch (org.jdom2.DataConversionException e) {
        log.error("Failed on litmode attribute: " + e);
    }
    ed.putItem(l);
    // load individual item's option settings after editor has set its global settings
    loadCommonAttributes(l, Editor.SIGNALS, element);
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) SignalHead(jmri.SignalHead) SignalHeadIcon(jmri.jmrit.display.SignalHeadIcon) Editor(jmri.jmrit.display.Editor)

Example 48 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class Warrant method readStoppingSignal.

//end propertyChange
private boolean readStoppingSignal() {
    String speed;
    if (_protectSignal instanceof SignalHead) {
        SignalHead head = (SignalHead) _protectSignal;
        int appearance = head.getAppearance();
        speed = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getAppearanceSpeed(head.getAppearanceName(appearance));
        if (log.isDebugEnabled())
            log.debug("SignalHead {} sets appearance to {} - warrant= {}", _protectSignal.getDisplayName(), speed, getDisplayName());
    } else {
        SignalMast mast = (SignalMast) _protectSignal;
        String aspect = mast.getAspect();
        speed = jmri.InstanceManager.getDefault(SignalSpeedMap.class).getAspectSpeed(aspect, mast.getSignalSystem());
        if (log.isDebugEnabled())
            log.debug("SignalMast {} sets aspect to {} - warrant= {}", _protectSignal.getDisplayName(), speed, getDisplayName());
    }
    if (speed == null) {
        // dark or no specified speed
        return false;
    } else if (speed.equals(Stop)) {
        _waitForSignal = true;
    } else {
        if (!_waitForBlock && _engineer != null) {
            _engineer.setWaitforClear(false);
            firePropertyChange("SpeedChange", _idxCurrentOrder, _idxCurrentOrder);
        }
        _waitForSignal = false;
    }
    return true;
}
Also used : SignalHead(jmri.SignalHead) SignalMast(jmri.SignalMast)

Example 49 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class DoubleTurnoutSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        l = shared.getChildren("turnout");
    }
    NamedBeanHandle<Turnout> green = loadTurnout(l.get(0));
    NamedBeanHandle<Turnout> red = loadTurnout(l.get(1));
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    SignalHead h;
    if (uname == null) {
        h = new DoubleTurnoutSignalHead(sys, green, red);
    } else {
        h = new DoubleTurnoutSignalHead(sys, uname, green, red);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Element(org.jdom2.Element) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead) SignalHead(jmri.SignalHead) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead) Turnout(jmri.Turnout)

Example 50 with SignalHead

use of jmri.SignalHead in project JMRI by JMRI.

the class QuadOutputSignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        l = shared.getChildren("turnout");
    }
    NamedBeanHandle<Turnout> green = loadTurnout(l.get(0));
    NamedBeanHandle<Turnout> yellow = loadTurnout(l.get(1));
    NamedBeanHandle<Turnout> red = loadTurnout(l.get(2));
    NamedBeanHandle<Turnout> lunar = loadTurnout(l.get(3));
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    SignalHead h;
    if (uname == null) {
        h = new QuadOutputSignalHead(sys, green, yellow, red, lunar);
    } else {
        h = new QuadOutputSignalHead(sys, uname, green, yellow, red, lunar);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) Element(org.jdom2.Element) QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) SignalHead(jmri.SignalHead) Turnout(jmri.Turnout)

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