Search in sources :

Example 91 with Element

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

the class VSDecoder method getXml.

/**
     * Get an XML representation of this VSDecoder Includes a subtree of
     * Elements for all of the associated SoundEvents, Triggers, VSDSounds, etc.
     *
     * @return Element XML Element for this VSDecoder
     */
public Element getXml() {
    Element me = new Element("vsdecoder");
    ArrayList<Element> le = new ArrayList<Element>();
    me.setAttribute("name", this.config.getProfileName());
    // If this decoder is marked as default, add the default Element.
    if (is_default) {
        me.addContent(new Element("default"));
    }
    for (SoundEvent se : event_list.values()) {
        le.add(se.getXml());
    }
    for (VSDSound vs : sound_list.values()) {
        le.add(vs.getXml());
    }
    for (Trigger t : trigger_list.values()) {
        le.add(t.getXml());
    }
    me.addContent(le);
    // Need to add whatever else here.
    return (me);
}
Also used : Element(org.jdom2.Element) ArrayList(java.util.ArrayList)

Example 92 with Element

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

the class WiThrottlePreferences method store.

@Override
public Element store() {
    if (this.isDirty()) {
        this.isRestartRequired = true;
    }
    Element element = new Element("WiThrottlePreferences");
    element.setAttribute("isUseEStop", "" + isUseEStop());
    this.asLoadedUseEStop = this.isUseEStop();
    element.setAttribute("getEStopDelay", "" + getEStopDelay());
    this.asLoadedEStopDelay = this.getEStopDelay();
    element.setAttribute("isUseMomF2", "" + isUseMomF2());
    this.asLoadedUseMomF2 = this.isUseMomF2();
    element.setAttribute("getPort", "" + getPort());
    this.asLoadedPort = this.getPort();
    element.setAttribute("isAllowTrackPower", "" + isAllowTrackPower());
    this.asLoadedAllowTrackPower = this.isAllowTrackPower();
    element.setAttribute("isAllowTurnout", "" + isAllowTurnout());
    this.asLoadedAllowTurnout = this.isAllowTurnout();
    element.setAttribute("isAllowRoute", "" + isAllowRoute());
    this.asLoadedAllowRoute = this.isAllowRoute();
    element.setAttribute("isAllowConsist", "" + isAllowConsist());
    this.asLoadedAllowConsist = this.isAllowConsist();
    element.setAttribute("isUseWiFiConsist", "" + isUseWiFiConsist());
    this.asLoadedUseWiFiConsist = this.isUseWiFiConsist();
    return element;
}
Also used : Element(org.jdom2.Element)

Example 93 with Element

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

the class WiThrottlePreferences method load.

@Override
public void load(Element child) {
    Attribute a;
    if ((a = child.getAttribute("isUseEStop")) != null) {
        setUseEStop(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseEStop = this.isUseEStop();
    }
    if ((a = child.getAttribute("getEStopDelay")) != null) {
        try {
            setEStopDelay(Integer.valueOf(a.getValue()));
            this.asLoadedEStopDelay = this.getEStopDelay();
        } catch (NumberFormatException e) {
            log.debug(e.getLocalizedMessage(), e);
        }
    }
    if ((a = child.getAttribute("isUseMomF2")) != null) {
        setUseMomF2(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseMomF2 = this.isUseMomF2();
    }
    if ((a = child.getAttribute("getPort")) != null) {
        try {
            setPort(a.getIntValue());
        } catch (DataConversionException ex) {
            log.error("Port {} is invalid.", a.getValue());
        }
        this.asLoadedPort = this.getPort();
    }
    if ((a = child.getAttribute("isAllowTrackPower")) != null) {
        setAllowTrackPower(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTrackPower = this.isAllowTrackPower();
    }
    if ((a = child.getAttribute("isAllowTurnout")) != null) {
        setAllowTurnout(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowTurnout = this.isAllowTurnout();
    }
    if ((a = child.getAttribute("isAllowRoute")) != null) {
        setAllowRoute(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowRoute = this.isAllowRoute();
    }
    if ((a = child.getAttribute("isAllowConsist")) != null) {
        setAllowConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedAllowConsist = this.isAllowConsist();
    }
    if ((a = child.getAttribute("isUseWiFiConsist")) != null) {
        setUseWiFiConsist(a.getValue().equalsIgnoreCase("true"));
        this.asLoadedUseWiFiConsist = this.isUseWiFiConsist();
    }
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException)

Example 94 with Element

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

the class AbstractConnectionConfigXml method saveOptions.

protected void saveOptions(Element e, PortAdapter adapter) {
    Element element = new Element("options");
    String[] options = adapter.getOptions();
    for (String i : options) {
        Element elem = new Element("option");
        elem.addContent(new Element("name").addContent(i));
        elem.addContent(new Element("value").addContent(adapter.getOptionState(i)));
        element.addContent(elem);
    }
    e.addContent(element);
}
Also used : Element(org.jdom2.Element)

Example 95 with Element

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

the class AbstractSerialConnectionConfigXml method store.

/**
     * Default implementation for storing the static contents of the serial port
     * implementation
     *
     * @param object Object to store, of type AbstractSerialConnectionConfig
     * @return Element containing the complete info
     */
@Override
public Element store(Object object) {
    getInstance(object);
    Element e = new Element("connection");
    if (adapter == null) {
        log.warn("No adapter found while saving serial port configuration {}", object.toString());
        return null;
    }
    // many of the following are required by the DTD; failing to include
    // them makes the XML file unreadable, but at least the next
    // invocation of the program can then continue.
    storeCommon(e, adapter);
    if (adapter.getCurrentPortName() != null) {
        e.setAttribute("port", adapter.getCurrentPortName());
    } else {
        e.setAttribute("port", rb.getString("noneSelected"));
    }
    if (adapter.getCurrentBaudRate() != null) {
        e.setAttribute("speed", adapter.getCurrentBaudRate());
    } else {
        e.setAttribute("speed", rb.getString("noneSelected"));
    }
    e.setAttribute("class", this.getClass().getName());
    extendElement(e);
    return e;
}
Also used : 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