Search in sources :

Example 66 with Element

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

the class TrainManifestText method load.

public static void load(Element e) {
    Element emts = e.getChild(Xml.MANIFEST_TEXT_STRINGS);
    if (emts == null) {
        return;
    }
    Attribute a;
    if (emts.getChild(Xml.MANIFEST_FOR_TRAIN) != null) {
        if ((a = emts.getChild(Xml.MANIFEST_FOR_TRAIN).getAttribute(Xml.TEXT)) != null) {
            setStringManifestForTrain(a.getValue());
        }
    }
    if (emts.getChild(Xml.VALID) != null) {
        if ((a = emts.getChild(Xml.VALID).getAttribute(Xml.TEXT)) != null) {
            setStringValid(a.getValue());
        }
    }
    if (emts.getChild(Xml.SCHEDULED_WORK) != null) {
        if ((a = emts.getChild(Xml.SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
            setStringScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.WORK_DEPARTURE_TIME) != null) {
        if ((a = emts.getChild(Xml.WORK_DEPARTURE_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringWorkDepartureTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.WORK_ARRIVAL_TIME) != null) {
        if ((a = emts.getChild(Xml.WORK_ARRIVAL_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringWorkArrivalTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_SCHEDULED_WORK) != null) {
        if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK).getAttribute(Xml.TEXT)) != null) {
            setStringNoScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT) != null) {
        if ((a = emts.getChild(Xml.NO_SCHEDULED_WORK_ROUTE_COMMENT).getAttribute(Xml.TEXT)) != null) {
            setStringNoScheduledWorkWithRouteComment(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPART_TIME) != null) {
        if ((a = emts.getChild(Xml.DEPART_TIME).getAttribute(Xml.TEXT)) != null) {
            setStringDepartTime(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsCars(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsLoads(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_TERMINATES) != null) {
        if ((a = emts.getChild(Xml.TRAIN_TERMINATES).getAttribute(Xml.TEXT)) != null) {
            setStringTrainTerminates(a.getValue());
        }
    }
    if (emts.getChild(Xml.DESTINATION) != null) {
        if ((a = emts.getChild(Xml.DESTINATION).getAttribute(Xml.TEXT)) != null) {
            setStringDestination(a.getValue());
        }
    }
    if (emts.getChild(Xml.TO) != null) {
        if ((a = emts.getChild(Xml.TO).getAttribute(Xml.TEXT)) != null) {
            setStringTo(a.getValue());
        }
    }
    if (emts.getChild(Xml.FROM) != null) {
        if ((a = emts.getChild(Xml.FROM).getAttribute(Xml.TEXT)) != null) {
            setStringFrom(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEST) != null) {
        if ((a = emts.getChild(Xml.DEST).getAttribute(Xml.TEXT)) != null) {
            setStringDest(a.getValue());
        }
    }
    if (emts.getChild(Xml.FINAL_DEST) != null) {
        if ((a = emts.getChild(Xml.FINAL_DEST).getAttribute(Xml.TEXT)) != null) {
            setStringFinalDestination(a.getValue());
        }
    }
    if (emts.getChild(Xml.ADD_HELPERS) != null) {
        if ((a = emts.getChild(Xml.ADD_HELPERS).getAttribute(Xml.TEXT)) != null) {
            setStringAddHelpers(a.getValue());
        }
    }
    if (emts.getChild(Xml.REMOVE_HELPERS) != null) {
        if ((a = emts.getChild(Xml.REMOVE_HELPERS).getAttribute(Xml.TEXT)) != null) {
            setStringRemoveHelpers(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCO_CHANGE) != null) {
        if ((a = emts.getChild(Xml.LOCO_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringLocoChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.CABOOSE_CHANGE) != null) {
        if ((a = emts.getChild(Xml.CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringCabooseChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.LOCO_CABOOSE_CHANGE) != null) {
        if ((a = emts.getChild(Xml.LOCO_CABOOSE_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringLocoAndCabooseChange(a.getValue());
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 67 with Element

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

the class TrainManagerXml method writeFile.

@Override
public void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    log.debug("writeFile {}", name);
    // This is taken in large part from "Java and XML" page 368
    File file = findFile(name);
    if (file == null) {
        file = new File(name);
    }
    // create root element
    // NOI18N
    Element root = new Element("operations-config");
    // NOI18N
    Document doc = newDocument(root, dtdLocation + "operations-trains.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    // NOI18N
    m.put("type", "text/xsl");
    // NOI18N
    m.put("href", xsltLocation + "operations-trains.xsl");
    // NOI18N
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    TrainManager.instance().store(root);
    TrainScheduleManager.instance().store(root);
    AutomationManager.instance().store(root);
    writeXML(file, doc);
    // done - train file now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 68 with Element

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

the class RosterEntry method store.

/**
     * Create an XML element to represent this Entry.
     * <p>
     * This member has to remain
     * synchronized with the detailed DTD in roster-config.xml.
     *
     * @return Contents in a JDOM Element
     */
@Override
public Element store() {
    Element e = new Element("locomotive");
    e.setAttribute("id", getId());
    e.setAttribute("fileName", getFileName());
    e.setAttribute("roadNumber", getRoadNumber());
    e.setAttribute("roadName", getRoadName());
    e.setAttribute("mfg", getMfg());
    e.setAttribute("owner", getOwner());
    e.setAttribute("model", getModel());
    e.setAttribute("dccAddress", getDccAddress());
    //e.setAttribute("protocol",""+getProtocol());
    e.setAttribute("comment", getComment());
    e.setAttribute(RosterEntry.MAX_SPEED, (Integer.toString(getMaxSpeedPCT())));
    // file path are saved without default xml config path
    e.setAttribute("imageFilePath", (this.getImagePath() != null) ? FileUtil.getPortableFilename(this.getImagePath()) : "");
    e.setAttribute("iconFilePath", (this.getIconPath() != null) ? FileUtil.getPortableFilename(this.getIconPath()) : "");
    e.setAttribute("URL", getURL());
    e.setAttribute(RosterEntry.SHUNTING_FUNCTION, getShuntingFunction());
    if (_dateUpdated.isEmpty()) {
        // set date updated to now if never set previously
        this.changeDateUpdated();
    }
    e.addContent(new Element("dateUpdated").addContent(this.getDateUpdated()));
    Element d = new Element("decoder");
    d.setAttribute("model", getDecoderModel());
    d.setAttribute("family", getDecoderFamily());
    d.setAttribute("comment", getDecoderComment());
    e.addContent(d);
    if (_dccAddress.isEmpty()) {
        // store a null address
        e.addContent((new jmri.configurexml.LocoAddressXml()).store(null));
    } else {
        e.addContent((new jmri.configurexml.LocoAddressXml()).store(new DccLocoAddress(Integer.parseInt(_dccAddress), _protocol)));
    }
    if (functionLabels != null) {
        d = new Element("functionlabels");
        // loop to copy non-null elements
        for (int i = 0; i <= MAXFNNUM; i++) {
            if (functionLabels[i] != null && !functionLabels[i].isEmpty()) {
                Element fne = new Element(RosterEntry.FUNCTION_LABEL);
                fne.setAttribute("num", "" + i);
                boolean lockable = false;
                if (functionLockables != null) {
                    lockable = functionLockables[i];
                }
                fne.setAttribute("lockable", lockable ? "true" : "false");
                if ((functionImages != null)) {
                    fne.setAttribute("functionImage", (functionImages[i] != null) ? FileUtil.getPortableFilename(functionImages[i]) : "");
                }
                if ((functionSelectedImages != null)) {
                    fne.setAttribute("functionImageSelected", (functionSelectedImages[i] != null) ? FileUtil.getPortableFilename(functionSelectedImages[i]) : "");
                }
                fne.addContent(functionLabels[i]);
                d.addContent(fne);
            }
        }
        e.addContent(d);
    }
    if (soundLabels != null) {
        d = new Element("soundlabels");
        // loop to copy non-null elements
        for (int i = 0; i < MAXSOUNDNUM; i++) {
            if (soundLabels[i] != null && !soundLabels[i].isEmpty()) {
                Element fne = new Element(RosterEntry.SOUND_LABEL);
                fne.setAttribute("num", "" + i);
                fne.addContent(soundLabels[i]);
                d.addContent(fne);
            }
        }
        e.addContent(d);
    }
    if (!getAttributes().isEmpty()) {
        d = new Element("attributepairs");
        for (String key : getAttributes()) {
            d.addContent(new Element("keyvaluepair").addContent(new Element("key").addContent(key)).addContent(new Element("value").addContent(getAttribute(key))));
        }
        e.addContent(d);
    }
    if (_sp != null) {
        _sp.store(e);
    }
    return e;
}
Also used : Element(org.jdom2.Element) DccLocoAddress(jmri.DccLocoAddress)

Example 69 with Element

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

the class RosterSpeedProfile method load.

@SuppressWarnings({ "unchecked" })
public void load(Element e) {
    try {
        setOverRunTimeForward(Float.parseFloat(e.getChild("overRunTimeForward").getText()));
    } catch (Exception ex) {
        log.error("Over run Error For " + _re.getId());
    }
    try {
        setOverRunTimeReverse(Float.parseFloat(e.getChild("overRunTimeReverse").getText()));
    } catch (Exception ex) {
        log.error("Over Run Error Rev " + _re.getId());
    }
    Element speeds = e.getChild("speeds");
    List<Element> speedlist = speeds.getChildren("speed");
    for (Element spd : speedlist) {
        try {
            String step = spd.getChild("step").getText();
            String forward = spd.getChild("forward").getText();
            String reverse = spd.getChild("reverse").getText();
            setSpeed(Integer.parseInt(step), Float.parseFloat(forward), Float.parseFloat(reverse));
        } catch (Exception ex) {
            log.error("Not loaded");
        }
    }
}
Also used : Element(org.jdom2.Element)

Example 70 with Element

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

the class RosterEntry method loadFunctions.

/**
     * Loads function names from a JDOM element. Does not change values that are
     * already present!
     *
     * @param e3     the XML element containing the functions
     * @param source "family" if source is the decoder definition, or "model" if
     *               source is the roster entry itself
     */
public void loadFunctions(Element e3, String source) {
    /*Load flag once, means that when the roster entry is edited only the first set of function labels are displayed 
         ie those saved in the roster file, rather than those being left blank
         rather than being over-written by the defaults linked to the decoder def*/
    if (loadedOnce) {
        return;
    }
    if (e3 != null) {
        // load function names
        List<Element> l = e3.getChildren(RosterEntry.FUNCTION_LABEL);
        for (Element fn : l) {
            int num = Integer.parseInt(fn.getAttribute("num").getValue());
            String lock = fn.getAttribute("lockable").getValue();
            String val = fn.getText();
            if ((this.getFunctionLabel(num) == null) || (source.equalsIgnoreCase("model"))) {
                this.setFunctionLabel(num, val);
                this.setFunctionLockable(num, lock.equals("true"));
                Attribute a;
                if ((a = fn.getAttribute("functionImage")) != null && !a.getValue().isEmpty()) {
                    try {
                        if (FileUtil.getFile(a.getValue()).isFile()) {
                            this.setFunctionImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
                        }
                    } catch (FileNotFoundException ex) {
                        try {
                            if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
                                this.setFunctionImage(num, FileUtil.getUserResourcePath() + a.getValue());
                            }
                        } catch (FileNotFoundException ex1) {
                            this.setFunctionImage(num, null);
                        }
                    }
                }
                if ((a = fn.getAttribute("functionImageSelected")) != null && !a.getValue().isEmpty()) {
                    try {
                        if (FileUtil.getFile(a.getValue()).isFile()) {
                            this.setFunctionSelectedImage(num, FileUtil.getAbsoluteFilename(a.getValue()));
                        }
                    } catch (FileNotFoundException ex) {
                        try {
                            if (FileUtil.getFile(FileUtil.getUserResourcePath() + a.getValue()).isFile()) {
                                this.setFunctionSelectedImage(num, FileUtil.getUserResourcePath() + a.getValue());
                            }
                        } catch (FileNotFoundException ex1) {
                            this.setFunctionSelectedImage(num, null);
                        }
                    }
                }
            }
        }
    }
    if (source.equalsIgnoreCase("RosterEntry")) {
        loadedOnce = true;
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) FileNotFoundException(java.io.FileNotFoundException)

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