Search in sources :

Example 81 with Attribute

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

the class LocaleSelector method checkElement.

/**
     * Checks one element to see if it's the one for the current language else
     * returns null.
     *
     * @param el     the element
     * @param name   the attribute
     * @param suffix the locale
     * @return the value of the attribute or null
     */
static String checkElement(Element el, String name, String suffix) {
    for (Object obj : el.getChildren(name)) {
        Element e = (Element) obj;
        Attribute a = e.getAttribute("lang", Namespace.XML_NAMESPACE);
        if (a != null) {
            if (a.getValue().equals(suffix)) {
                return e.getText();
            }
        }
    }
    return null;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 82 with Attribute

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

the class WebServerPreferences method load.

public void load(Element child) {
    Attribute a;
    a = child.getAttribute(CLICK_DELAY);
    if (a != null) {
        try {
            setClickDelay(a.getIntValue());
        } catch (DataConversionException e) {
            log.debug(e.getLocalizedMessage(), e);
        }
    }
    a = child.getAttribute(REFRESH_DELAY);
    if (a != null) {
        try {
            setRefreshDelay(a.getIntValue());
        } catch (DataConversionException e) {
            log.debug(e.getLocalizedMessage(), e);
        }
    }
    a = child.getAttribute(USE_AJAX);
    if (a != null) {
        setUseAjax(Boolean.parseBoolean(a.getValue()));
    }
    a = child.getAttribute(SIMPLE);
    if (a != null) {
        setSimple(Boolean.parseBoolean(a.getValue()));
    }
    a = child.getAttribute(ALLOW_REMOTE_CONFIG);
    if (a != null) {
        setAllowRemoteConfig(Boolean.parseBoolean(a.getValue()));
    }
    a = child.getAttribute(READONLY_POWER);
    if (a != null) {
        setReadonlyPower(Boolean.parseBoolean(a.getValue()));
    }
    a = child.getAttribute(PORT);
    if (a != null) {
        try {
            setPort(a.getIntValue());
        } catch (DataConversionException ex) {
            setPort(12080);
            log.error("Unable to read port. Setting to default value.", ex);
        }
    }
    a = child.getAttribute(RAILROAD_NAME);
    if (a != null) {
        setRailRoadName(a.getValue());
    }
    Element df = child.getChild(DISALLOWED_FRAMES);
    if (df != null) {
        this.disallowedFrames.clear();
        df.getChildren(FRAME).stream().forEach((f) -> {
            this.disallowedFrames.add(f.getText().trim());
        });
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) DataConversionException(org.jdom2.DataConversionException)

Example 83 with Attribute

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

the class FnMapPanelESU method configOutputs.

/**
     * Use the "model" element from the decoder definition file to configure the
     * number of rows and columns and set up any custom column names.
     */
protected void configOutputs(Element model) {
    if (model == null) {
        log.debug("configOutputs was given a null model");
        return;
    }
    // get numOuts, numFns or leave the defaults
    Attribute a = model.getAttribute("numOuts");
    try {
        if (a != null) {
            numItems = Integer.parseInt(a.getValue());
        }
    } catch (Exception e) {
        log.error("error handling decoder's numOuts value");
    }
    if (numItems > MAX_ITEMS) {
        log.error("numOuts=" + numItems + " exceeds the maximum number of items (" + MAX_ITEMS + ") defined in the code");
        numItems = Math.min(numItems, MAX_ITEMS);
    }
    a = model.getAttribute("numFns");
    try {
        if (a != null) {
            numRows = Integer.parseInt(a.getValue());
        }
    } catch (Exception e) {
        log.error("error handling decoder's numFns value");
    }
    if (numRows > MAX_ROWS) {
        log.error("numFns=" + numRows + " exceeds the maximum number of rows (" + MAX_ROWS + ") defined in the code");
        numRows = Math.min(numRows, MAX_ROWS);
    }
    log.debug("numFns, numOuts {}, {}", numRows, numItems);
    // add ESU default split labels before reading custom ones
    for (int item = 0; item < MAX_ITEMS; item++) {
        loadSplitLabel(item, itemDescESU[item]);
    }
    // take all "output" children
    List<Element> elemList = model.getChildren("output");
    log.debug("output scan starting with {} elements", elemList.size());
    for (int i = 0; i < elemList.size(); i++) {
        Element e = elemList.get(i);
        String name = e.getAttribute("name").getValue();
        // if this a number, or a character name?
        try {
            int outputNum = Integer.parseInt(name);
            // yes, since it was converted.  All we do with
            // these are store the label index (if it exists)
            String at = LocaleSelector.getAttribute(e, "label");
            if (at != null) {
                loadSplitLabel(outputNum - 1, at);
            }
        } catch (java.lang.NumberFormatException ex) {
            // not a number, must be a name
            if (i < MAX_ITEMS) {
                itemName[i][0] = name;
                itemName[i][1] = "";
                itemName[i][2] = "";
                String at;
                if ((at = LocaleSelector.getAttribute(e, "label")) != null) {
                    loadSplitLabel(i, name + "|" + at);
                }
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) MissingResourceException(java.util.MissingResourceException)

Example 84 with Attribute

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

the class FnMapPanel method configOutputs.

/**
     * Use the "model" element from the decoder definition file to configure the
     * number of outputs and set up any that are named instead of numbered.
     */
protected void configOutputs(Element model) {
    if (model == null) {
        log.debug("configOutputs was given a null model");
        return;
    }
    // get numOuts, numFns or leave the defaults
    Attribute a = model.getAttribute("numOuts");
    try {
        if (a != null) {
            numOut = Integer.valueOf(a.getValue()).intValue();
        }
    } catch (Exception e) {
        log.error("error handling decoder's numOuts value");
    }
    a = model.getAttribute("numFns");
    try {
        if (a != null) {
            numFn = Integer.valueOf(a.getValue()).intValue();
        }
    } catch (Exception e) {
        log.error("error handling decoder's numFns value");
    }
    if (log.isDebugEnabled()) {
        log.debug("numFns, numOuts " + numFn + "," + numOut);
    }
    // take all "output" children
    List<Element> elemList = model.getChildren("output");
    if (log.isDebugEnabled()) {
        log.debug("output scan starting with " + elemList.size() + " elements");
    }
    for (int i = 0; i < elemList.size(); i++) {
        Element e = elemList.get(i);
        String name = e.getAttribute("name").getValue();
        // if this a number, or a character name?
        try {
            int outputNum = Integer.valueOf(name).intValue();
            // yes, since it was converted.  All we do with
            // these are store the label index (if it exists)
            String at = LocaleSelector.getAttribute(e, "label");
            if (at != null) {
                loadSplitLabel(outputNum - 1, at);
                numOut = Math.max(numOut, outputNum);
            }
        } catch (java.lang.NumberFormatException ex) {
            // not a number, must be a name
            if (numOut < maxOut) {
                outName[numOut] = name;
                String at;
                if ((at = LocaleSelector.getAttribute(e, "label")) != null) {
                    outLabel[numOut] = at;
                } else {
                    outLabel[numOut] = "";
                }
                numOut++;
            }
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 85 with Attribute

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

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