Search in sources :

Example 1 with SignalAppearanceMap

use of jmri.SignalAppearanceMap in project JMRI by JMRI.

the class MatrixSignalMastXml method store.

/**
     * Default implementation for storing the contents of a
     * MatrixSignalMastManager
     *
     * @param o Object to store, of type MatrixSignalMast
     * @return e Element containing the complete info
     */
@Override
public Element store(Object o) {
    // from mast p to XML
    MatrixSignalMast p = (MatrixSignalMast) o;
    Element e = new Element("matrixsignalmast");
    e.setAttribute("class", this.getClass().getName());
    // include content
    e.addContent(new Element("systemName").addContent(p.getSystemName()));
    // username, comment & properties
    storeCommon(p, e);
    // mast properties:
    Element unlit = new Element("unlit");
    if (p.allowUnLit()) {
        unlit.setAttribute("allowed", "yes");
        unlit.addContent(new Element("bitString").addContent(p.getUnLitChars()));
    } else {
        unlit.setAttribute("allowed", "no");
    }
    e.addContent(unlit);
    List<String> outputs = p.getOutputs();
    // convert char[] to xml-storable simple String
    // max. 5 outputs (either: turnouts (bean names) [or ToDo: DCC addresses (numbers)]
    // spotted by FindBugs as to never be null (check on creation of MatrixMast)
    Element outps = new Element("outputs");
    int i = 1;
    for (String _output : outputs) {
        String key = ("output" + i);
        Element outp = new Element("output");
        outp.setAttribute("matrixCol", key);
        // get name (Turnout)
        outp.addContent(p.getOutputName(i));
        outps.addContent(outp);
        i++;
    }
    if (outputs.size() != 0) {
        e.addContent(outps);
    }
    // string of max. 6 chars "001010" describing matrix row per aspect
    SignalAppearanceMap appMap = p.getAppearanceMap();
    if (appMap != null) {
        Element bss = new Element("bitStrings");
        java.util.Enumeration<String> aspects = appMap.getAspects();
        while (aspects.hasMoreElements()) {
            String key = aspects.nextElement();
            Element bs = new Element("bitString");
            bs.setAttribute("aspect", key);
            bs.addContent(p.getBitstring(key));
            bss.addContent(bs);
        }
        e.addContent(bss);
    }
    List<String> disabledAspects = p.getDisabledAspects();
    if (disabledAspects != null) {
        Element el = new Element("disabledAspects");
        for (String aspect : disabledAspects) {
            Element ele = new Element("disabledAspect");
            ele.addContent(aspect);
            el.addContent(ele);
        }
        if (disabledAspects.size() != 0) {
            e.addContent(el);
        }
    }
    return e;
}
Also used : Element(org.jdom2.Element) SignalAppearanceMap(jmri.SignalAppearanceMap) MatrixSignalMast(jmri.implementation.MatrixSignalMast)

Example 2 with SignalAppearanceMap

use of jmri.SignalAppearanceMap in project JMRI by JMRI.

the class SignalMastItemPanel method getIconMap.

private void getIconMap(int row) {
    if (row < 0) {
        _currentIconMap = null;
        _family = null;
        return;
    }
    NamedBean bean = _model.getBeanAt(row);
    if (bean == null) {
        if (log.isDebugEnabled()) {
            log.debug("getIconMap: NamedBean is null at row " + row);
        }
        _currentIconMap = null;
        _family = null;
        return;
    }
    try {
        _mast = InstanceManager.getDefault(jmri.SignalMastManager.class).provideSignalMast(bean.getDisplayName());
    } catch (IllegalArgumentException ex) {
        log.error("getIconMap: No SignalMast called " + bean.getDisplayName());
        _currentIconMap = null;
        return;
    }
    _family = _mast.getSignalSystem().getSystemName();
    _currentIconMap = new HashMap<String, NamedIcon>();
    SignalAppearanceMap appMap = _mast.getAppearanceMap();
    Enumeration<String> e = _mast.getAppearanceMap().getAspects();
    while (e.hasMoreElements()) {
        String aspect = e.nextElement();
        String s = appMap.getImageLink(aspect, _family);
        if (s != null && !s.equals("")) {
            if (!s.contains("preference:")) {
                s = s.substring(s.indexOf("resources"));
            }
            NamedIcon n = new NamedIcon(s, s);
            _currentIconMap.put(aspect, n);
        }
    }
    if (log.isDebugEnabled()) {
        log.debug("getIconMap: for " + _family + " size= " + _currentIconMap.size());
    }
}
Also used : NamedIcon(jmri.jmrit.catalog.NamedIcon) NamedBean(jmri.NamedBean) SignalAppearanceMap(jmri.SignalAppearanceMap)

Example 3 with SignalAppearanceMap

use of jmri.SignalAppearanceMap in project JMRI by JMRI.

the class DccSignalMastXml method store.

/**
     * Default implementation for storing the contents of a
     * DefaultSignalMastManager
     *
     * @param o Object to store, of type TripleDccSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    DccSignalMast p = (DccSignalMast) o;
    Element e = new Element("dccsignalmast");
    e.setAttribute("class", this.getClass().getName());
    e.addContent(new Element("systemName").addContent(p.getSystemName()));
    storeCommon(p, e);
    Element unlit = new Element("unlit");
    if (p.allowUnLit()) {
        unlit.setAttribute("allowed", "yes");
        unlit.addContent(new Element("aspect").addContent(Integer.toString(p.getUnlitId())));
    } else {
        unlit.setAttribute("allowed", "no");
    }
    e.addContent(unlit);
    SignalAppearanceMap appMap = p.getAppearanceMap();
    if (appMap != null) {
        java.util.Enumeration<String> aspects = appMap.getAspects();
        while (aspects.hasMoreElements()) {
            String key = aspects.nextElement();
            Element el = new Element("aspect");
            el.setAttribute("defines", key);
            el.addContent(new Element("number").addContent(Integer.toString(p.getOutputForAppearance(key))));
            e.addContent(el);
        }
    }
    List<String> disabledAspects = p.getDisabledAspects();
    if (disabledAspects != null) {
        Element el = new Element("disabledAspects");
        for (String aspect : disabledAspects) {
            Element ele = new Element("disabledAspect");
            ele.addContent(aspect);
            el.addContent(ele);
        }
        if (disabledAspects.size() != 0) {
            e.addContent(el);
        }
    }
    return e;
}
Also used : DccSignalMast(jmri.implementation.DccSignalMast) Element(org.jdom2.Element) SignalAppearanceMap(jmri.SignalAppearanceMap)

Example 4 with SignalAppearanceMap

use of jmri.SignalAppearanceMap in project JMRI by JMRI.

the class TurnoutSignalMastXml method store.

/**
     * Default implementation for storing the contents of a
     * DefaultSignalMastManager
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    TurnoutSignalMast p = (TurnoutSignalMast) o;
    Element e = new Element("turnoutsignalmast");
    e.setAttribute("class", this.getClass().getName());
    e.addContent(new Element("systemName").addContent(p.getSystemName()));
    storeCommon(p, e);
    Element unlit = new Element("unlit");
    if (p.allowUnLit()) {
        unlit.setAttribute("allowed", "yes");
        unlit.addContent(new Element("turnout").addContent(p.getUnLitTurnoutName()));
        if (p.getUnLitTurnoutState() == Turnout.CLOSED) {
            unlit.addContent(new Element("turnoutstate").addContent("closed"));
        } else {
            unlit.addContent(new Element("turnoutstate").addContent("thrown"));
        }
    } else {
        unlit.setAttribute("allowed", "no");
    }
    e.addContent(unlit);
    SignalAppearanceMap appMap = p.getAppearanceMap();
    if (appMap != null) {
        java.util.Enumeration<String> aspects = appMap.getAspects();
        while (aspects.hasMoreElements()) {
            String key = aspects.nextElement();
            Element el = new Element("aspect");
            el.setAttribute("defines", key);
            el.addContent(new Element("turnout").addContent(p.getTurnoutName(key)));
            if (p.getTurnoutState(key) == Turnout.CLOSED) {
                el.addContent(new Element("turnoutstate").addContent("closed"));
            } else {
                el.addContent(new Element("turnoutstate").addContent("thrown"));
            }
            e.addContent(el);
        }
    }
    List<String> disabledAspects = p.getDisabledAspects();
    if (disabledAspects != null) {
        Element el = new Element("disabledAspects");
        for (String aspect : disabledAspects) {
            Element ele = new Element("disabledAspect");
            ele.addContent(aspect);
            el.addContent(ele);
        }
        if (disabledAspects.size() != 0) {
            e.addContent(el);
        }
    }
    if (p.resetPreviousStates()) {
        e.addContent(new Element("resetPreviousStates").addContent("yes"));
    }
    return e;
}
Also used : TurnoutSignalMast(jmri.implementation.TurnoutSignalMast) Element(org.jdom2.Element) SignalAppearanceMap(jmri.SignalAppearanceMap)

Aggregations

SignalAppearanceMap (jmri.SignalAppearanceMap)4 Element (org.jdom2.Element)3 NamedBean (jmri.NamedBean)1 DccSignalMast (jmri.implementation.DccSignalMast)1 MatrixSignalMast (jmri.implementation.MatrixSignalMast)1 TurnoutSignalMast (jmri.implementation.TurnoutSignalMast)1 NamedIcon (jmri.jmrit.catalog.NamedIcon)1