Search in sources :

Example 36 with Element

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

the class ConfigXmlManager method storeConfig.

/**
     * Writes prefs to a file.
     *
     * @param file config file to write.
     */
@Override
public boolean storeConfig(File file) {
    boolean result = true;
    Element root = initStore();
    if (!addConfigStore(root)) {
        result = false;
    }
    includeHistory(root);
    if (!finalStore(root, file)) {
        result = false;
    }
    return result;
}
Also used : Element(org.jdom2.Element)

Example 37 with Element

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

the class DefaultIdTag method store.

@Override
public Element store(boolean storeState) {
    //NOI18N
    Element e = new Element("idtag");
    // e.setAttribute("systemName", this.mSystemName); // not needed from 2.11.1
    //NOI18N
    e.addContent(new Element("systemName").addContent(this.mSystemName));
    if (this.mUserName != null && this.mUserName.length() > 0) {
        // e.setAttribute("userName", this.mUserName); // not needed from 2.11.1
        //NOI18N
        e.addContent(new Element("userName").addContent(this.mUserName));
    }
    if (this.getComment() != null && this.getComment().length() > 0) {
        //NOI18N
        e.addContent(new Element("comment").addContent(this.getComment()));
    }
    if (this.getWhereLastSeen() != null && storeState) {
        //NOI18N
        e.addContent(new Element("whereLastSeen").addContent(this.getWhereLastSeen().getSystemName()));
    }
    if (this.getWhenLastSeen() != null && storeState) {
        //NOI18N
        e.addContent(new Element("whenLastSeen").addContent(DateFormat.getDateTimeInstance(DateFormat.MEDIUM, DateFormat.MEDIUM).format(this.getWhenLastSeen())));
    }
    return e;
}
Also used : Element(org.jdom2.Element)

Example 38 with Element

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

the class MergSD2SignalHeadXml method addTurnoutElement.

Element addTurnoutElement(NamedBeanHandle<Turnout> to, String which) {
    Element el = new Element("turnoutname");
    el.setAttribute("defines", which);
    el.addContent(to.getName());
    return el;
}
Also used : Element(org.jdom2.Element)

Example 39 with Element

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

the class MergSD2SignalHeadXml method loadTurnout.

NamedBeanHandle<Turnout> loadTurnout(Object o) {
    Element e = (Element) o;
    if (e.getName().equals("turnout")) {
        String name = e.getAttribute("systemName").getValue();
        Turnout t;
        if (e.getAttribute("userName") != null && !e.getAttribute("userName").getValue().equals("")) {
            name = e.getAttribute("userName").getValue();
            t = InstanceManager.turnoutManagerInstance().getTurnout(name);
        } else {
            t = InstanceManager.turnoutManagerInstance().getBySystemName(name);
        }
        return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
    } else {
        String name = e.getText();
        try {
            Turnout t = InstanceManager.turnoutManagerInstance().provideTurnout(name);
            return jmri.InstanceManager.getDefault(jmri.NamedBeanHandleManager.class).getNamedBeanHandle(name, t);
        } catch (IllegalArgumentException ex) {
            log.warn("Failed to provide Turnout \"{}\" in loadTurnout", name);
            return null;
        }
    }
}
Also used : Element(org.jdom2.Element) Turnout(jmri.Turnout)

Example 40 with Element

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

the class MergSD2SignalHeadXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    int aspects = 2;
    List<Element> l = shared.getChildren("turnoutname");
    if (l.size() == 0) {
        l = shared.getChildren("turnout");
        aspects = l.size() + 1;
    }
    NamedBeanHandle<Turnout> input1 = null;
    NamedBeanHandle<Turnout> input2 = null;
    NamedBeanHandle<Turnout> input3 = null;
    String yesno = "";
    boolean feather = false;
    boolean home = true;
    // put it together
    String sys = getSystemName(shared);
    String uname = getUserName(shared);
    if (shared.getAttribute("feather") != null) {
        yesno = shared.getAttribute("feather").getValue();
    }
    if ((yesno != null) && (!yesno.equals(""))) {
        if (yesno.equals("yes")) {
            feather = true;
        } else if (yesno.equals("no")) {
            feather = false;
        }
    }
    if (shared.getAttribute("home") != null) {
        yesno = shared.getAttribute("home").getValue();
    }
    if ((yesno != null) && (!yesno.equals(""))) {
        if (yesno.equals("yes")) {
            home = true;
        } else if (yesno.equals("no")) {
            home = false;
        }
    }
    try {
        aspects = shared.getAttribute("aspects").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.warn("Could not parse level attribute!");
    } catch (NullPointerException e) {
    // considered normal if the attribute not present
    }
    SignalHead h;
    //@TODO could re-arange this so that it falls through
    switch(aspects) {
        case 2:
            input1 = loadTurnout(l.get(0));
            break;
        case 3:
            input1 = loadTurnout(l.get(0));
            input2 = loadTurnout(l.get(1));
            break;
        case 4:
            input1 = loadTurnout(l.get(0));
            input2 = loadTurnout(l.get(1));
            input3 = loadTurnout(l.get(2));
            break;
        default:
            log.error("incorrect number of aspects " + aspects + " when loading Signal " + sys);
    }
    if (uname == null) {
        h = new MergSD2SignalHead(sys, aspects, input1, input2, input3, feather, home);
    } else {
        h = new MergSD2SignalHead(sys, uname, aspects, input1, input2, input3, feather, home);
    }
    loadCommon(h, shared);
    InstanceManager.getDefault(jmri.SignalHeadManager.class).register(h);
    return true;
}
Also used : Element(org.jdom2.Element) MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) SignalHead(jmri.SignalHead) MergSD2SignalHead(jmri.implementation.MergSD2SignalHead) Turnout(jmri.Turnout)

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