Search in sources :

Example 46 with Element

use of org.jdom2.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)

Example 47 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class QuadOutputSignalHeadXml method store.

/**
     * Default implementation for storing the contents of a QuadOutputSignalHead
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    QuadOutputSignalHead p = (QuadOutputSignalHead) 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(), "green"));
    element.addContent(addTurnoutElement(p.getYellow(), "yellow"));
    element.addContent(addTurnoutElement(p.getRed(), "red"));
    element.addContent(addTurnoutElement(p.getLunar(), "lunar"));
    return element;
}
Also used : QuadOutputSignalHead(jmri.implementation.QuadOutputSignalHead) Element(org.jdom2.Element)

Example 48 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class DoubleTurnoutSignalHeadXml method store.

/**
     * Default implementation for storing the contents of a
     * DoubleTurnoutSignalHead
     *
     * @param o Object to store, of type TripleTurnoutSignalHead
     * @return Element containing the complete info
     */
@Override
public Element store(Object o) {
    DoubleTurnoutSignalHead p = (DoubleTurnoutSignalHead) 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(), "green"));
    element.addContent(addTurnoutElement(p.getRed(), "red"));
    return element;
}
Also used : Element(org.jdom2.Element) DoubleTurnoutSignalHead(jmri.implementation.DoubleTurnoutSignalHead)

Example 49 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class DccSignalMastXml method loadCommonDCCMast.

protected boolean loadCommonDCCMast(DccSignalMast m, Element element) {
    loadCommon(m, element);
    if (element.getChild("unlit") != null) {
        Element unlit = element.getChild("unlit");
        if (unlit.getAttribute("allowed") != null) {
            if (unlit.getAttribute("allowed").getValue().equals("no")) {
                m.setAllowUnLit(false);
            } else {
                m.setAllowUnLit(true);
                m.setUnlitId(Integer.parseInt(unlit.getChild("aspect").getValue()));
            }
        }
    }
    List<Element> list = element.getChildren("aspect");
    for (int i = 0; i < list.size(); i++) {
        Element e = list.get(i);
        String aspect = e.getAttribute("defines").getValue();
        int number = -1;
        try {
            String value = e.getChild("number").getValue();
            number = Integer.parseInt(value);
        } catch (Exception ex) {
            log.error("failed to convert DCC number");
        }
        m.setOutputForAppearance(aspect, number);
    }
    Element e = element.getChild("disabledAspects");
    if (e != null) {
        list = e.getChildren("disabledAspect");
        for (Element aspect : list) {
            m.setAspectDisabled(aspect.getText());
        }
    }
    InstanceManager.getDefault(jmri.SignalMastManager.class).register(m);
    return true;
}
Also used : Element(org.jdom2.Element)

Example 50 with Element

use of org.jdom2.Element in project JMRI by JMRI.

the class VirtualSignalMastXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    VirtualSignalMast m;
    String sys = getSystemName(shared);
    m = new jmri.implementation.VirtualSignalMast(sys);
    if (getUserName(shared) != null) {
        m.setUserName(getUserName(shared));
    }
    loadCommon(m, shared);
    if (shared.getChild("unlit") != null) {
        Element unlit = shared.getChild("unlit");
        if (unlit.getAttribute("allowed") != null) {
            if (unlit.getAttribute("allowed").getValue().equals("no")) {
                m.setAllowUnLit(false);
            } else {
                m.setAllowUnLit(true);
            }
        }
    }
    Element e = shared.getChild("disabledAspects");
    if (e != null) {
        List<Element> list = e.getChildren("disabledAspect");
        for (Element aspect : list) {
            m.setAspectDisabled(aspect.getText());
        }
    }
    InstanceManager.getDefault(jmri.SignalMastManager.class).register(m);
    return true;
}
Also used : VirtualSignalMast(jmri.implementation.VirtualSignalMast) VirtualSignalMast(jmri.implementation.VirtualSignalMast) Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)673 Attribute (org.jdom2.Attribute)103 Document (org.jdom2.Document)64 File (java.io.File)49 ArrayList (java.util.ArrayList)36 NamedIcon (jmri.jmrit.catalog.NamedIcon)28 IOException (java.io.IOException)27 DataConversionException (org.jdom2.DataConversionException)26 JDOMException (org.jdom2.JDOMException)26 XmlFile (jmri.jmrit.XmlFile)24 Test (org.junit.Test)24 Editor (jmri.jmrit.display.Editor)22 DocType (org.jdom2.DocType)21 Turnout (jmri.Turnout)20 ProcessingInstruction (org.jdom2.ProcessingInstruction)16 Point (java.awt.Point)15 HashMap (java.util.HashMap)15 SignalHead (jmri.SignalHead)15 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)15 Dimension (java.awt.Dimension)14