Search in sources :

Example 41 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class LsDecSignalHeadXml method loadTurnout.

NamedBeanHandle<Turnout> loadTurnout(Object o) {
    Element e = (Element) o;
    String name = e.getAttribute("systemName").getValue();
    Turnout t = InstanceManager.turnoutManagerInstance().getTurnout(name);
    return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
}
Also used : Element(org.jdom2.Element) Turnout(jmri.Turnout)

Example 42 with Element

use of com.zhan_dui.utils.m3u8.Element 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 43 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class DccSignalHeadXml method store.

/**
     * Default implementation for storing the contents of a LsDecSignalHead
     *
     * @param o Object to store, of type LsDecSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    DccSignalHead p = (DccSignalHead) o;
    Element element = new Element("signalhead");
    element.setAttribute("class", this.getClass().getName());
    element.addContent(new Element("systemName").addContent(p.getSystemName()));
    storeCommon(p, element);
    if (p.useAddressOffSet()) {
        element.addContent(new Element("useAddressOffSet").addContent("yes"));
    } else {
        element.addContent(new Element("useAddressOffSet").addContent("no"));
    }
    for (int i = 0; i < p.getValidStates().length; i++) {
        String aspect = p.getValidStateNames()[i];
        //String address = p.getOutputForAppearance(i);
        Element el = new Element("aspect");
        el.setAttribute("defines", aspect);
        el.addContent(new Element("number").addContent(Integer.toString(p.getOutputForAppearance(p.getValidStates()[i]))));
        element.addContent(el);
    }
    return element;
}
Also used : Element(org.jdom2.Element) DccSignalHead(jmri.implementation.DccSignalHead)

Example 44 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class MergSD2SignalHeadXml method store.

/**
     * Default implementation for storing the contents of a MergSD2SignalHead
     *
     * @param o Object to store, of type MergSD2SignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    MergSD2SignalHead p = (MergSD2SignalHead) o;
    Element element = new Element("signalhead");
    element.setAttribute("class", this.getClass().getName());
    element.addContent(new Element("systemName").addContent(p.getSystemName()));
    element.setAttribute("aspects", p.getAspects() + "");
    if (p.getFeather()) {
        element.setAttribute("feather", "yes");
    }
    storeCommon(p, element);
    int aspects = p.getAspects();
    //@TODO could re-arange this so that it falls through
    switch(aspects) {
        case 2:
            element.addContent(addTurnoutElement(p.getInput1(), "input1"));
            if (!p.getHome()) {
                element.setAttribute("home", "no");
            }
            break;
        case 3:
            element.addContent(addTurnoutElement(p.getInput1(), "input1"));
            element.addContent(addTurnoutElement(p.getInput2(), "input2"));
            break;
        case 4:
            element.addContent(addTurnoutElement(p.getInput1(), "input1"));
            element.addContent(addTurnoutElement(p.getInput2(), "input2"));
            element.addContent(addTurnoutElement(p.getInput3(), "input3"));
            break;
        default:
            log.error("incorrect number of aspects " + aspects + " for Signal " + p.getDisplayName());
    }
    return element;
}
Also used : MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) Element(org.jdom2.Element)

Example 45 with Element

use of com.zhan_dui.utils.m3u8.Element in project JMRI by JMRI.

the class LsDecSignalHeadXml method store.

/**
     * Default implementation for storing the contents of a LsDecSignalHead
     *
     * @param o Object to store, of type LsDecSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    LsDecSignalHead p = (LsDecSignalHead) o;
    Element element = new Element("signalhead");
    element.setAttribute("class", this.getClass().getName());
    element.addContent(new Element("systemName").addContent(p.getSystemName()));
    storeCommon(p, element);
    element.addContent(addTurnoutElement(p.getGreen().getName(), p.getGreenState()));
    element.addContent(addTurnoutElement(p.getYellow().getName(), p.getYellowState()));
    element.addContent(addTurnoutElement(p.getRed().getName(), p.getRedState()));
    element.addContent(addTurnoutElement(p.getFlashGreen().getName(), p.getFlashGreenState()));
    element.addContent(addTurnoutElement(p.getFlashYellow().getName(), p.getFlashYellowState()));
    element.addContent(addTurnoutElement(p.getFlashRed().getName(), p.getFlashRedState()));
    element.addContent(addTurnoutElement(p.getDark().getName(), p.getDarkState()));
    return element;
}
Also used : Element(org.jdom2.Element) LsDecSignalHead(jmri.implementation.LsDecSignalHead)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)73 Document (org.jdom2.Document)58 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)27 IOException (java.io.IOException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Turnout (jmri.Turnout)20 DataConversionException (org.jdom2.DataConversionException)20 DocType (org.jdom2.DocType)19 Editor (jmri.jmrit.display.Editor)18 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 Dimension (java.awt.Dimension)14 FileNotFoundException (java.io.FileNotFoundException)13 SignalHead (jmri.SignalHead)13 List (java.util.List)12