Search in sources :

Example 36 with Element

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

the class ConfigXmlManager method addPrefsStore.

protected void addPrefsStore(Element root) {
    for (int i = 0; i < plist.size(); i++) {
        Object o = plist.get(i);
        Element e = elementFromObject(o);
        if (e != null) {
            root.addContent(e);
        }
    }
}
Also used : Element(org.jdom2.Element)

Example 37 with Element

use of org.jdom2.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 38 with Element

use of org.jdom2.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 39 with Element

use of org.jdom2.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 40 with Element

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

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