Search in sources :

Example 46 with Element

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

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

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

use of com.zhan_dui.utils.m3u8.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)

Example 50 with Element

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

the class DefaultCatalogTreeManagerXml method loadNode.

/**
     * Recursively load a CatalogTree.
     *
     * @param element element containing the node to load
     * @param parent  the parent node of the node in element
     * @param model   the tree model containing the tree to add the node to
     */
public void loadNode(Element element, CatalogTreeNode parent, DefaultTreeModel model) {
    List<Element> nodeList = element.getChildren("node");
    if (log.isDebugEnabled()) {
        log.debug("Found " + nodeList.size() + " CatalogTreeNode objects");
    }
    for (int i = 0; i < nodeList.size(); i++) {
        Element elem = nodeList.get(i);
        Attribute attr = elem.getAttribute("nodeName");
        if (attr == null) {
            log.warn("unexpected null nodeName. elem= " + elem + ", attrs= " + elem.getAttributes());
            continue;
        }
        String nodeName = attr.getValue();
        CatalogTreeNode n = new CatalogTreeNode(nodeName);
        addLeaves(elem, n);
        model.insertNodeInto(n, parent, parent.getChildCount());
        loadNode(elem, n, model);
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) CatalogTreeNode(jmri.jmrit.catalog.CatalogTreeNode)

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