Search in sources :

Example 86 with Attribute

use of ucar.nc2.Attribute 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 87 with Attribute

use of ucar.nc2.Attribute 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 88 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class ProgrammerConfigPaneXml method load.

@Override
public boolean load(Element shared, Element perNode) {
    boolean result = true;
    if (shared.getAttribute("defaultFile") != null) {
        if (log.isDebugEnabled()) {
            log.debug("set programmer default file: " + shared.getAttribute("defaultFile").getValue());
        }
        InstanceManager.getDefault(ProgrammerConfigManager.class).setDefaultFile(shared.getAttribute("defaultFile").getValue());
    }
    Attribute a;
    if (null != (a = shared.getAttribute("showEmptyPanes"))) {
        InstanceManager.getDefault(ProgrammerConfigManager.class).setShowEmptyPanes(!a.getValue().equals("no"));
    }
    if (null != (a = shared.getAttribute("showCvNumbers"))) {
        InstanceManager.getDefault(ProgrammerConfigManager.class).setShowCvNumbers(a.getValue().equals("yes"));
    }
    if (null != (a = shared.getAttribute("canCacheDefault"))) {
        InstanceManager.getDefault(ProgrammerConfigManager.class).setCanCacheDefault(a.getValue().equals("yes"));
    }
    if (null != (a = shared.getAttribute("doConfirmRead"))) {
        InstanceManager.getDefault(ProgrammerConfigManager.class).setDoConfirmRead(a.getValue().equals("yes"));
    }
    ConfigureManager cm = InstanceManager.getNullableDefault(jmri.ConfigureManager.class);
    if (cm != null) {
        cm.registerPref(new ProgrammerConfigPane());
    }
    return result;
}
Also used : ConfigureManager(jmri.ConfigureManager) Attribute(org.jdom2.Attribute) ProgrammerConfigManager(jmri.jmrit.symbolicprog.ProgrammerConfigManager) ProgrammerConfigPane(jmri.jmrit.symbolicprog.ProgrammerConfigPane)

Example 89 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class ProgCheckAction method checkMissingNames.

@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION")
static // though it would be good to fix it if you're working in this area
String checkMissingNames(File file) {
    try {
        Element root = readFile(file);
        if (log.isDebugEnabled()) {
            log.debug("parsing complete");
        }
        // check to see if there's a programmer element
        if (root.getChild("programmer") == null) {
            log.warn("Does not appear to be a programmer file");
            return "Does not appear to be a programmer file";
        }
        // walk the entire tree of elements, saving a reference
        // to all of the "display" elements
        List<Element> varList = new ArrayList<>();
        expandElement(root.getChild("programmer"), varList);
        if (log.isDebugEnabled()) {
            log.debug("found " + varList.size() + " display elements");
        }
        jmri.jmrit.symbolicprog.NameFile nfile = jmri.jmrit.symbolicprog.NameFile.instance();
        String warnings = "";
        for (int i = 0; i < varList.size(); i++) {
            Element varElement = (varList.get(i));
            // for each variable, see if can find in names file
            Attribute nameAttr = varElement.getAttribute("item");
            String name = null;
            if (nameAttr != null) {
                name = nameAttr.getValue();
            }
            if (log.isDebugEnabled()) {
                log.debug("Variable called \"" + ((name != null) ? name : "<none>") + "\"");
            }
            if (!(name == null ? false : nfile.checkName(name))) {
                log.warn("Variable not found in name list: name=\"" + ((name != null) ? name : "<none>") + "\"");
                warnings += "Variable not found in name list: name=\"" + ((name != null) ? name : "<none>") + "\"\n";
            }
        }
        if (!warnings.equals("")) {
            return "Names missing from Comprehensive.xml\n" + warnings;
        } else {
            return "";
        }
    } catch (Exception ex) {
        return "Error parsing programmer file: " + ex;
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Example 90 with Attribute

use of ucar.nc2.Attribute in project JMRI by JMRI.

the class ProgCheckAction method checkIncompleteComprehensive.

@SuppressFBWarnings(value = "SBSC_USE_STRINGBUFFER_CONCATENATION")
static // though it would be good to fix it if you're working in this area
String checkIncompleteComprehensive(File file) {
    // handle the file (later should be outside this thread?)
    try {
        Element root = readFile(file);
        if (log.isDebugEnabled()) {
            log.debug("parsing complete");
        }
        // check to see if there's a programmer element
        if (root.getChild("programmer") == null) {
            log.warn("Does not appear to be a programmer file");
            return "Does not appear to be a programmer file";
        }
        // walk the entire tree of elements, saving a reference
        // to all of the "display" elements
        List<Element> varList = new ArrayList<>();
        expandElement(root.getChild("programmer"), varList);
        if (log.isDebugEnabled()) {
            log.debug("found " + varList.size() + " display elements");
        }
        jmri.jmrit.symbolicprog.NameFile nfile = jmri.jmrit.symbolicprog.NameFile.instance();
        String warnings = "";
        // for each item in names, see if found in this file
        for (String s : nfile.names()) {
            if (functionMapName(s)) {
                continue;
            }
            boolean found = false;
            for (int i = 0; i < varList.size(); i++) {
                Element varElement = varList.get(i);
                // for each variable, see if can find in names file
                Attribute nameAttr = varElement.getAttribute("item");
                String name = null;
                if (nameAttr != null) {
                    name = nameAttr.getValue();
                }
                // now check
                if (name != null && name.equals(s)) {
                    found = true;
                }
            }
            if (!found) {
                log.warn("Variable not in Comprehensive: name=\"" + s + "\"");
                warnings += "Variable not in Comprehensive: name=\"" + s + "\"\n";
            }
        }
        return warnings;
    } catch (Exception ex) {
        return "Error parsing programmer file: " + ex;
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) ArrayList(java.util.ArrayList) SuppressFBWarnings(edu.umd.cs.findbugs.annotations.SuppressFBWarnings)

Aggregations

Attribute (org.jdom2.Attribute)106 Element (org.jdom2.Element)75 Editor (jmri.jmrit.display.Editor)15 DataConversionException (org.jdom2.DataConversionException)14 NamedIcon (jmri.jmrit.catalog.NamedIcon)13 IOException (java.io.IOException)12 ArrayList (java.util.ArrayList)12 LayoutEditor (jmri.jmrit.display.layoutEditor.LayoutEditor)9 List (java.util.List)7 Color (java.awt.Color)6 File (java.io.File)6 HashMap (java.util.HashMap)6 ConfigureManager (jmri.ConfigureManager)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