Search in sources :

Example 86 with Attribute

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

the class LayoutSlipXml method load.

/**
     * Load, starting with the LayoutSlip element, then all the other data
     *
     * @param element Top level Element to unpack.
     * @param o       LayoutEditor as an Object
     */
@Override
public void load(Element element, Object o) {
    // create the objects
    LayoutEditor p = (LayoutEditor) o;
    // get center point
    String name = element.getAttribute("ident").getValue();
    double x = 0.0;
    double y = 0.0;
    try {
        x = element.getAttribute("xcen").getFloatValue();
        y = element.getAttribute("ycen").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutslip center  attribute");
    }
    int type = LayoutSlip.SINGLE_SLIP;
    try {
        type = element.getAttribute("slipType").getIntValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert layoutslip type attribute");
    }
    // create the new LayoutSlip
    LayoutSlip l = new LayoutSlip(name, new Point2D.Double(x, y), 0.0, p, type);
    // get remaining attributes
    Attribute a = element.getAttribute("blockname");
    if (a != null) {
        l.tBlockName = a.getValue();
    }
    a = element.getAttribute("connectaname");
    if (a != null) {
        l.connectAName = a.getValue();
    }
    a = element.getAttribute("connectbname");
    if (a != null) {
        l.connectBName = a.getValue();
    }
    a = element.getAttribute("connectcname");
    if (a != null) {
        l.connectCName = a.getValue();
    }
    a = element.getAttribute("connectdname");
    if (a != null) {
        l.connectDName = a.getValue();
    }
    l.setSignalA1Name(getElement(element, "signala1name"));
    l.setSignalB1Name(getElement(element, "signalb1name"));
    l.setSignalC1Name(getElement(element, "signalc1name"));
    l.setSignalD1Name(getElement(element, "signald1name"));
    l.setSignalA2Name(getElement(element, "signala2name"));
    l.setSignalB2Name(getElement(element, "signalb2name"));
    l.setSignalC2Name(getElement(element, "signalc2name"));
    l.setSignalD2Name(getElement(element, "signald2name"));
    try {
        x = element.getAttribute("xa").getFloatValue();
        y = element.getAttribute("ya").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert LayoutSlip a coords attribute");
    }
    l.setCoordsA(new Point2D.Double(x, y));
    try {
        x = element.getAttribute("xb").getFloatValue();
        y = element.getAttribute("yb").getFloatValue();
    } catch (org.jdom2.DataConversionException e) {
        log.error("failed to convert LayoutSlip b coords attribute");
    }
    l.setCoordsB(new Point2D.Double(x, y));
    l.setSignalAMast(getElement(element, "signalAMast"));
    l.setSignalBMast(getElement(element, "signalBMast"));
    l.setSignalCMast(getElement(element, "signalCMast"));
    l.setSignalDMast(getElement(element, "signalDMast"));
    l.setSensorA(getElement(element, "sensorA"));
    l.setSensorB(getElement(element, "sensorB"));
    l.setSensorC(getElement(element, "sensorC"));
    l.setSensorD(getElement(element, "sensorD"));
    l.setTurnout(getElement(element, "turnout"));
    l.setTurnoutB(getElement(element, "turnoutB"));
    if (element.getChild("states") != null) {
        Element state = element.getChild("states");
        if (state.getChild("A-C") != null) {
            Element ac = state.getChild("A-C");
            l.setTurnoutStates(LayoutSlip.STATE_AC, ac.getChild("turnout").getText(), ac.getChild("turnoutB").getText());
        }
        if (state.getChild("A-D") != null) {
            Element ad = state.getChild("A-D");
            l.setTurnoutStates(LayoutSlip.STATE_AD, ad.getChild("turnout").getText(), ad.getChild("turnoutB").getText());
        }
        if (state.getChild("B-D") != null) {
            Element bd = state.getChild("B-D");
            l.setTurnoutStates(LayoutSlip.STATE_BD, bd.getChild("turnout").getText(), bd.getChild("turnoutB").getText());
        }
        if (state.getChild("B-C") != null) {
            Element bc = state.getChild("B-C");
            l.setTurnoutStates(LayoutSlip.STATE_BC, bc.getChild("turnout").getText(), bc.getChild("turnoutB").getText());
        }
    }
    p.slipList.add(l);
}
Also used : LayoutEditor(jmri.jmrit.display.layoutEditor.LayoutEditor) LayoutSlip(jmri.jmrit.display.layoutEditor.LayoutSlip) Point2D(java.awt.geom.Point2D) Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 87 with Attribute

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

the class WarrantManagerXml method loadThrottleCommand.

static ThrottleSetting loadThrottleCommand(Element elem) {
    long time = 0;
    try {
        time = elem.getAttribute("time").getLongValue();
    } catch (org.jdom2.DataConversionException dce) {
    }
    Attribute attr = elem.getAttribute("command");
    String command = null;
    if (attr != null)
        command = attr.getValue();
    attr = elem.getAttribute("value");
    String value = null;
    if (attr != null)
        value = attr.getValue();
    attr = elem.getAttribute("block");
    String block = null;
    if (attr != null)
        block = attr.getValue();
    return new ThrottleSetting(time, command, value, block);
}
Also used : Attribute(org.jdom2.Attribute) DataConversionException(org.jdom2.DataConversionException) ThrottleSetting(jmri.jmrit.logix.ThrottleSetting)

Example 88 with Attribute

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

the class CarManager method store.

/**
     * Create an XML element to represent this Entry. This member has to remain
     * synchronized with the detailed DTD in operations-cars.dtd.
     * @param root The common Element for operations-cars.dtd.
     */
public void store(Element root) {
    // nothing to save under
    root.addContent(new Element(Xml.OPTIONS));
    // options
    Element values;
    List<String> names = getKernelNameList();
    if (Control.backwardCompatible) {
        root.addContent(values = new Element(Xml.KERNELS));
        for (String name : names) {
            // NOI18N
            String kernelNames = name + "%%";
            values.addContent(kernelNames);
        }
    }
    // new format using elements
    Element kernels = new Element(Xml.NEW_KERNELS);
    for (String name : names) {
        Element kernel = new Element(Xml.KERNEL);
        kernel.setAttribute(new Attribute(Xml.NAME, name));
        kernels.addContent(kernel);
    }
    root.addContent(kernels);
    root.addContent(values = new Element(Xml.CARS));
    // add entries
    List<RollingStock> carList = getByIdList();
    for (RollingStock rs : carList) {
        Car car = (Car) rs;
        values.addContent(car.store());
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) RollingStock(jmri.jmrit.operations.rollingstock.RollingStock)

Example 89 with Attribute

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

the class TrainManager method load.

public void load(Element root) {
    if (root.getChild(Xml.OPTIONS) != null) {
        Element options = root.getChild(Xml.OPTIONS);
        TrainCustomManifest.instance().load(options);
        TrainCustomSwitchList.instance().load(options);
        Element e = options.getChild(Xml.TRAIN_OPTIONS);
        Attribute a;
        if (e != null) {
            if ((a = e.getAttribute(Xml.BUILD_MESSAGES)) != null) {
                _buildMessages = a.getValue().equals(Xml.TRUE);
            }
            if ((a = e.getAttribute(Xml.BUILD_REPORT)) != null) {
                _buildReport = a.getValue().equals(Xml.TRUE);
            }
            if ((a = e.getAttribute(Xml.PRINT_PREVIEW)) != null) {
                _printPreview = a.getValue().equals(Xml.TRUE);
            }
            if ((a = e.getAttribute(Xml.OPEN_FILE)) != null) {
                _openFile = a.getValue().equals(Xml.TRUE);
            }
            if ((a = e.getAttribute(Xml.RUN_FILE)) != null) {
                _runFile = a.getValue().equals(Xml.TRUE);
            }
            // verify that the Trains Window action is valid
            if ((a = e.getAttribute(Xml.TRAIN_ACTION)) != null && (a.getValue().equals(TrainsTableFrame.MOVE) || a.getValue().equals(TrainsTableFrame.RESET) || a.getValue().equals(TrainsTableFrame.TERMINATE) || a.getValue().equals(TrainsTableFrame.CONDUCTOR))) {
                _trainAction = a.getValue();
            }
        }
        // Row color options
        Element eRowColorOptions = options.getChild(Xml.ROW_COLOR_OPTIONS);
        if (eRowColorOptions != null) {
            if ((a = eRowColorOptions.getAttribute(Xml.ROW_COLOR_MANUAL)) != null) {
                _rowColorManual = a.getValue().equals(Xml.TRUE);
            }
            if ((a = eRowColorOptions.getAttribute(Xml.ROW_COLOR_BUILD_FAILED)) != null) {
                _rowColorBuildFailed = a.getValue();
            }
            if ((a = eRowColorOptions.getAttribute(Xml.ROW_COLOR_BUILT)) != null) {
                _rowColorBuilt = a.getValue();
            }
            if ((a = eRowColorOptions.getAttribute(Xml.ROW_COLOR_TRAIN_EN_ROUTE)) != null) {
                _rowColorTrainEnRoute = a.getValue();
            }
            if ((a = eRowColorOptions.getAttribute(Xml.ROW_COLOR_TERMINATED)) != null) {
                _rowColorTerminated = a.getValue();
            }
        }
        e = options.getChild(Xml.TRAIN_SCHEDULE_OPTIONS);
        if (e != null) {
            if ((a = e.getAttribute(Xml.ACTIVE_ID)) != null) {
                _trainScheduleActiveId = a.getValue();
            }
        }
        // check for scripts
        if (options.getChild(Xml.SCRIPTS) != null) {
            @SuppressWarnings("unchecked") List<Element> lm = options.getChild(Xml.SCRIPTS).getChildren(Xml.START_UP);
            for (Element es : lm) {
                if ((a = es.getAttribute(Xml.NAME)) != null) {
                    addStartUpScript(a.getValue());
                }
            }
            @SuppressWarnings("unchecked") List<Element> lt = options.getChild(Xml.SCRIPTS).getChildren(Xml.SHUT_DOWN);
            for (Element es : lt) {
                if ((a = es.getAttribute(Xml.NAME)) != null) {
                    addShutDownScript(a.getValue());
                }
            }
        }
    }
    if (root.getChild(Xml.TRAINS) != null) {
        @SuppressWarnings("unchecked") List<Element> eTrains = root.getChild(Xml.TRAINS).getChildren(Xml.TRAIN);
        log.debug("readFile sees {} trains", eTrains.size());
        for (Element eTrain : eTrains) {
            register(new Train(eTrain));
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 90 with Attribute

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

the class TrainManifestHeaderText method load.

public static void load(Element e) {
    Element emts = e.getChild(Xml.MANIFEST_HEADER_TEXT_STRINGS);
    if (emts == null) {
        return;
    }
    Attribute a;
    if (emts.getChild(Xml.ROAD) != null) {
        if ((a = emts.getChild(Xml.ROAD).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Road(a.getValue());
        }
    }
    if (emts.getChild(Xml.NUMBER) != null) {
        if ((a = emts.getChild(Xml.NUMBER).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Number(a.getValue());
        }
    }
    if (emts.getChild(Xml.ENGINE_NUMBER) != null) {
        if ((a = emts.getChild(Xml.ENGINE_NUMBER).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_EngineNumber(a.getValue());
        }
    }
    if (emts.getChild(Xml.TYPE) != null) {
        if ((a = emts.getChild(Xml.TYPE).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Type(a.getValue());
        }
    }
    if (emts.getChild(Xml.MODEL) != null) {
        if ((a = emts.getChild(Xml.MODEL).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Model(a.getValue());
        }
    }
    if (emts.getChild(Xml.LENGTH) != null) {
        if ((a = emts.getChild(Xml.LENGTH).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Length(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOAD) != null) {
        if ((a = emts.getChild(Xml.LOAD).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Load(a.getValue());
        }
    }
    if (emts.getChild(Xml.COLOR) != null) {
        if ((a = emts.getChild(Xml.COLOR).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Color(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRACK) != null) {
        if ((a = emts.getChild(Xml.TRACK).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Track(a.getValue());
        }
    }
    if (emts.getChild(Xml.DESTINATION) != null) {
        if ((a = emts.getChild(Xml.DESTINATION).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Destination(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEST_TRACK) != null) {
        if ((a = emts.getChild(Xml.DEST_TRACK).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Dest_Track(a.getValue());
        }
    }
    if (emts.getChild(Xml.FINAL_DEST) != null) {
        if ((a = emts.getChild(Xml.FINAL_DEST).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Final_Dest(a.getValue());
        }
    }
    if (emts.getChild(Xml.FINAL_DEST_TRACK) != null) {
        if ((a = emts.getChild(Xml.FINAL_DEST_TRACK).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Final_Dest_Track(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCATION) != null) {
        if ((a = emts.getChild(Xml.LOCATION).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Location(a.getValue());
        }
    }
    if (emts.getChild(Xml.CONSIST) != null) {
        if ((a = emts.getChild(Xml.CONSIST).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Consist(a.getValue());
        }
    }
    if (emts.getChild(Xml.KERNEL) != null) {
        if ((a = emts.getChild(Xml.KERNEL).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Kernel(a.getValue());
        }
    }
    if (emts.getChild(Xml.OWNER) != null) {
        if ((a = emts.getChild(Xml.OWNER).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Owner(a.getValue());
        }
    }
    if (emts.getChild(Xml.RWE) != null) {
        if ((a = emts.getChild(Xml.RWE).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_RWE(a.getValue());
        }
    }
    if (emts.getChild(Xml.COMMENT) != null) {
        if ((a = emts.getChild(Xml.COMMENT).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Comment(a.getValue());
        }
    }
    if (emts.getChild(Xml.DROP_COMMENT) != null) {
        if ((a = emts.getChild(Xml.DROP_COMMENT).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Drop_Comment(a.getValue());
        }
    }
    if (emts.getChild(Xml.PICKUP_COMMENT) != null) {
        if ((a = emts.getChild(Xml.PICKUP_COMMENT).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Pickup_Comment(a.getValue());
        }
    }
    if (emts.getChild(Xml.HAZARDOUS) != null) {
        if ((a = emts.getChild(Xml.HAZARDOUS).getAttribute(Xml.TEXT)) != null) {
            setStringHeader_Hazardous(a.getValue());
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Aggregations

Attribute (org.jdom2.Attribute)104 Element (org.jdom2.Element)96 DataConversionException (org.jdom2.DataConversionException)17 Editor (jmri.jmrit.display.Editor)15 ArrayList (java.util.ArrayList)13 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)10 File (java.io.File)8 Color (java.awt.Color)7 List (java.util.List)7 HashMap (java.util.HashMap)6 Asn1Integer (com.android.hotspot2.asn1.Asn1Integer)5 Asn1Object (com.android.hotspot2.asn1.Asn1Object)5 Asn1Oid (com.android.hotspot2.asn1.Asn1Oid)5 OidMappings (com.android.hotspot2.asn1.OidMappings)5 ASN1Encodable (com.android.org.bouncycastle.asn1.ASN1Encodable)5 ASN1EncodableVector (com.android.org.bouncycastle.asn1.ASN1EncodableVector)5 ASN1Set (com.android.org.bouncycastle.asn1.ASN1Set)5 DERBitString (com.android.org.bouncycastle.asn1.DERBitString)5