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;
}
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);
}
}
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;
}
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;
}
}
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;
}
}
Aggregations