Search in sources :

Example 41 with Comment

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

the class VariableTableModel method processSplitVal.

protected VariableValue processSplitVal(Element child, String CV, boolean readOnly, boolean infoOnly, boolean writeOnly, String name, String comment, boolean opsOnly, String mask, String item) throws NumberFormatException {
    VariableValue v;
    Attribute a;
    int minVal = 0;
    int maxVal = 255;
    if ((a = child.getAttribute("min")) != null) {
        minVal = Integer.valueOf(a.getValue()).intValue();
    }
    if ((a = child.getAttribute("max")) != null) {
        maxVal = Integer.valueOf(a.getValue()).intValue();
    }
    // no default, must be present
    String highCV = child.getAttribute("highCV").getValue();
    int factor = 1;
    if ((a = child.getAttribute("factor")) != null) {
        factor = Integer.valueOf(a.getValue()).intValue();
    }
    int offset = 0;
    if ((a = child.getAttribute("offset")) != null) {
        offset = Integer.valueOf(a.getValue()).intValue();
    }
    String uppermask = "VVVVVVVV";
    if ((a = child.getAttribute("upperMask")) != null) {
        uppermask = a.getValue();
    }
    // ensure 2nd CV exists
    _cvModel.addCV("" + (highCV), readOnly, infoOnly, writeOnly);
    v = new SplitVariableValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, minVal, maxVal, _cvModel.allCvMap(), _status, item, highCV, factor, offset, uppermask);
    return v;
}
Also used : Attribute(org.jdom2.Attribute)

Example 42 with Comment

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

the class VariableTableModel method processIndexedPairVal.

protected VariableValue processIndexedPairVal(Element child, boolean readOnly, boolean infoOnly, boolean writeOnly, String name, String comment, String cvName, boolean opsOnly, String cv, String mask, String item) throws NumberFormatException {
    VariableValue iv;
    int minVal = 0;
    int maxVal = 65535;
    Attribute a;
    if ((a = child.getAttribute("min")) != null) {
        minVal = Integer.valueOf(a.getValue()).intValue();
    }
    if ((a = child.getAttribute("max")) != null) {
        maxVal = Integer.valueOf(a.getValue()).intValue();
    }
    int factor = 1;
    if ((a = child.getAttribute("factor")) != null) {
        factor = Integer.valueOf(a.getValue()).intValue();
    }
    int offset = 0;
    if ((a = child.getAttribute("offset")) != null) {
        offset = Integer.valueOf(a.getValue()).intValue();
    }
    String uppermask = "VVVVVVVV";
    if ((a = child.getAttribute("upperMask")) != null) {
        uppermask = a.getValue();
    }
    String highCVname = "";
    String highCVnumber = "";
    int highCVpiVal = -1;
    int highCVsiVal = -1;
    if ((a = child.getAttribute("highCVname")) != null) {
        highCVname = a.getValue();
        int x = highCVname.indexOf('.');
        highCVnumber = highCVname.substring(0, x);
        int y = highCVname.indexOf('.', x + 1);
        if (y > 0) {
            highCVpiVal = Integer.valueOf(highCVname.substring(x + 1, y)).intValue();
            x = highCVname.lastIndexOf('.');
            highCVsiVal = Integer.valueOf(highCVname.substring(x + 1)).intValue();
        } else {
            x = highCVname.lastIndexOf('.');
            highCVpiVal = Integer.valueOf(highCVname.substring(x + 1)).intValue();
        }
    }
    // ensure highCVnumber indexed CV exists
    if (log.isDebugEnabled()) {
        log.debug("Add high indexed CV " + highCVname);
    }
    _indxCvModel.addIndxCV(highCVname, _piCv, highCVpiVal, _siCv, highCVsiVal, highCVnumber, readOnly, infoOnly, writeOnly);
    // order
    boolean upperFirst = false;
    if ((a = child.getAttribute("order")) != null) {
        if (a.getValue().equals("highFirst")) {
            upperFirst = true;
        }
    }
    iv = new IndexedPairVariableValue(name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, minVal, maxVal, _indxCvModel.allIndxCvMap(), _status, item, highCVname, factor, offset, uppermask, upperFirst);
    return iv;
}
Also used : Attribute(org.jdom2.Attribute)

Example 43 with Comment

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

the class VariableTableModel method setConstant.

/**
     * Configure from a constant. This is like setRow (which processes a
     * variable Element).
     */
@SuppressFBWarnings(value = "NP_LOAD_OF_KNOWN_NULL_VALUE", justification = "null mask parameter to ConstantValue constructor expected.")
public void setConstant(Element e) {
    // get the values for the VariableValue ctor
    String stdname = e.getAttribute("item").getValue();
    if (log.isDebugEnabled()) {
        log.debug("Starting to setConstant \"" + stdname + "\"");
    }
    String name = LocaleSelector.getAttribute(e, "label");
    if (name == null || name.equals("")) {
        name = stdname;
    }
    String comment = LocaleSelector.getAttribute(e, "comment");
    String mask = null;
    // intrinsically readOnly, so use just that branch
    JButton bw = new JButton();
    _writeButtons.addElement(bw);
    // config read button as a dummy - there's really nothing to read
    JButton br = new JButton("Read");
    _readButtons.addElement(br);
    // no CV references are added here
    // have to handle various value types, see "snippet"
    Attribute a;
    // set to default value if specified (CV load will later override this)
    int defaultVal = 0;
    if ((a = e.getAttribute("default")) != null) {
        String val = a.getValue();
        if (log.isDebugEnabled()) {
            log.debug("Found default value: " + val + " for " + stdname);
        }
        defaultVal = Integer.valueOf(val).intValue();
        if (stdname.compareTo("PICV") == 0) {
            _piCv = val;
        } else if (stdname.compareTo("SICV") == 0) {
            _siCv = val;
        }
    }
    // create the specific object
    ConstantValue v = new ConstantValue(name, comment, "", true, true, false, false, "", mask, defaultVal, defaultVal, _cvModel.allCvMap(), _status, stdname);
    // record new variable, update state, hook up listeners
    rowVector.addElement(v);
    v.setState(VariableValue.FROMFILE);
    v.addPropertyChangeListener(this);
    // set to default value if specified (CV load will later override this)
    if ((a = e.getAttribute("default")) != null) {
        String val = a.getValue();
        if (log.isDebugEnabled()) {
            log.debug("Found default value: " + val + " for " + name);
        }
        v.setIntValue(defaultVal);
    }
}
Also used : Attribute(org.jdom2.Attribute) JButton(javax.swing.JButton) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 44 with Comment

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

the class NceConsistRoster method writeFile.

/**
     * Write the entire roster to a file. This does not do backup; that has to
     * be done separately. See writeRosterFile() for a function that finds the
     * default location, does a backup and then calls this.
     *
     * @param name Filename for new file, including path info as needed.
     * @throws java.io.FileNotFoundException when file not found
     * @throws java.io.IOException when fault accessing file
     */
void writeFile(String name) throws java.io.FileNotFoundException, java.io.IOException {
    if (log.isDebugEnabled()) {
        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
    Element root = new Element("consist-roster-config");
    Document doc = newDocument(root, dtdLocation + "consist-roster-config.dtd");
    // add XSLT processing instruction
    java.util.Map<String, String> m = new java.util.HashMap<String, String>();
    m.put("type", "text/xsl");
    m.put("href", xsltLocation + "consistRoster.xsl");
    ProcessingInstruction p = new ProcessingInstruction("xml-stylesheet", m);
    doc.addContent(0, p);
    //file version for writing
    for (int i = 0; i < numEntries(); i++) {
        //Extract the RosterEntry at this index and inspect the Comment and
        //Decoder Comment fields to change any \n characters to <?p?> processor
        //directives so they can be stored in the xml file and converted
        //back when the file is read.
        NceConsistRosterEntry r = _list.get(i);
        String tempComment = r.getComment();
        StringBuffer buf = new StringBuffer();
        //when \n is found.  In that case, insert <?p?>
        for (int k = 0; k < tempComment.length(); k++) {
            if (tempComment.startsWith("\n", k)) {
                buf.append("<?p?>");
            } else {
                buf.append(tempComment.substring(k, k + 1));
            }
        }
        r.setComment(buf.toString());
    }
    //All Comments and Decoder Comment line feeds have been changed to processor directives
    // add top-level elements
    Element values;
    root.addContent(values = new Element("roster"));
    // add entries
    for (int i = 0; i < numEntries(); i++) {
        values.addContent(_list.get(i).store());
    }
    writeXML(file, doc);
    //other parts of the program (e.g. in copying a roster)
    for (int i = 0; i < numEntries(); i++) {
        NceConsistRosterEntry r = _list.get(i);
        String xmlComment = r.getComment();
        StringBuffer buf = new StringBuffer();
        for (int k = 0; k < xmlComment.length(); k++) {
            if (xmlComment.startsWith("<?p?>", k)) {
                buf.append("\n");
                k = k + 4;
            } else {
                buf.append(xmlComment.substring(k, k + 1));
            }
        }
        r.setComment(buf.toString());
    }
    // done - roster now stored, so can't be dirty
    setDirty(false);
}
Also used : Element(org.jdom2.Element) Document(org.jdom2.Document) File(java.io.File) XmlFile(jmri.jmrit.XmlFile) ProcessingInstruction(org.jdom2.ProcessingInstruction)

Example 45 with Comment

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

the class AbstractNamedBeanManagerConfigXML method storeComment.

/**
     * Store the comment parameter from a NamedBean
     *
     * @param t    The NamedBean being stored
     * @param elem The JDOM element for storing the NamedBean
     */
void storeComment(NamedBean t, Element elem) {
    // add comment, if present
    if (t.getComment() != null) {
        Element c = new Element("comment");
        c.addContent(t.getComment());
        elem.addContent(c);
    }
}
Also used : Element(org.jdom2.Element)

Aggregations

Element (org.jdom2.Element)33 Attribute (org.jdom2.Attribute)10 Document (org.jdom2.Document)6 ArrayList (java.util.ArrayList)4 File (java.io.File)3 Date (java.util.Date)3 HashMap (java.util.HashMap)3 List (java.util.List)3 ProcessingInstruction (org.jdom2.ProcessingInstruction)3 RecyclerView (android.support.v7.widget.RecyclerView)2 View (android.view.View)2 BindView (butterknife.BindView)2 Modification (com.thoughtworks.go.domain.materials.Modification)2 JButton (javax.swing.JButton)2 Block (jmri.Block)2 NamedBeanHandle (jmri.NamedBeanHandle)2 SignalGroup (jmri.SignalGroup)2 SignalGroupManager (jmri.SignalGroupManager)2 SignalMast (jmri.SignalMast)2 SignalMastLogic (jmri.SignalMastLogic)2