use of ucar.nc2.Attribute in project JMRI by JMRI.
the class VariableTableModel method processIndexedVal.
protected VariableValue processIndexedVal(Element child, String name, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String cv, String mask, String item) throws NumberFormatException {
VariableValue iv;
int minVal = 0;
int maxVal = 255;
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();
}
iv = new IndexedVariableValue(name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, minVal, maxVal, _indxCvModel.allIndxCvMap(), _status, item);
return iv;
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class PositionFile method getReceiverMax.
/**
* Get the nth receiver max time.
*
* @return 0 if not present
*/
public int getReceiverMax(int n) {
List<Element> kids = root.getChildren("receiver");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
Attribute a = e.getAttribute("number");
if (a == null) {
continue;
}
int num = -1;
try {
num = a.getIntValue();
} catch (org.jdom2.DataConversionException ex1) {
log.error("in getReceiverMax", ex1);
}
if (num != n) {
continue;
}
a = e.getAttribute("maxtime");
if (a == null) {
// default value
return 99999;
}
try {
return a.getIntValue();
} catch (org.jdom2.DataConversionException ex2) {
return 99999;
}
}
return 99999;
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class PositionFile method getReceiverPosition.
/**
* Get the nth receiver position in the file.
*
* @return null if not present
*/
public Point3d getReceiverPosition(int n) {
List<Element> kids = root.getChildren("receiver");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
Attribute a = e.getAttribute("number");
if (a == null) {
continue;
}
int num = -1;
try {
num = a.getIntValue();
} catch (org.jdom2.DataConversionException ex) {
log.error("in getReceiverPosition", ex);
}
if (num == n) {
return positionFromElement(e.getChild("position"));
}
}
return null;
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class PositionFile method getReceiverActive.
/**
* Get the nth receiver active state in the file.
*
* @return true if not present
*/
public boolean getReceiverActive(int n) {
List<Element> kids = root.getChildren("receiver");
for (int i = 0; i < kids.size(); i++) {
Element e = kids.get(i);
Attribute a = e.getAttribute("number");
if (a == null) {
continue;
}
int num = -1;
try {
num = a.getIntValue();
} catch (org.jdom2.DataConversionException ex) {
log.error("in getReceiverActive", ex);
}
if (num != n) {
continue;
}
a = e.getAttribute("active");
if (a == null) {
// default value
return true;
}
if (a.getValue().equals("false")) {
return false;
}
return true;
}
return true;
}
use of ucar.nc2.Attribute in project JMRI by JMRI.
the class NameCheckAction method actionPerformed.
@SuppressWarnings("unchecked")
@Override
public void actionPerformed(ActionEvent e) {
if (fci == null) {
fci = jmri.jmrit.XmlFile.userFileChooser("XML files", "xml");
}
// request the filename from an open dialog
fci.rescanCurrentDirectory();
int retVal = fci.showOpenDialog(_who);
// handle selection or cancel
if (retVal == JFileChooser.APPROVE_OPTION) {
File file = fci.getSelectedFile();
if (log.isDebugEnabled()) {
log.debug("located file " + file + " for XML processing");
}
// 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 decoder element
if (root.getChild("decoder") == null) {
log.warn("Does not appear to be a decoder file");
return;
}
Iterator<Element> iter = root.getChild("decoder").getChild("variables").getDescendants(new ElementFilter("variable"));
jmri.jmrit.symbolicprog.NameFile nfile = jmri.jmrit.symbolicprog.NameFile.instance();
String warnings = "";
while (iter.hasNext()) {
Element varElement = iter.next();
// for each variable, see if can find in names file
Attribute labelAttr = varElement.getAttribute("label");
String label = null;
if (labelAttr != null) {
label = labelAttr.getValue();
}
Attribute itemAttr = varElement.getAttribute("item");
String item = null;
if (itemAttr != null) {
item = itemAttr.getValue();
}
if (log.isDebugEnabled()) {
log.debug("Variable called \"" + ((label != null) ? label : "<none>") + "\" \"" + ((item != null) ? item : "<none>"));
}
if (!(label == null ? false : nfile.checkName(label)) && !(item == null ? false : nfile.checkName(item))) {
log.warn("Variable not found: label=\"" + ((label != null) ? label : "<none>") + "\" item=\"" + ((item != null) ? label : "<none>") + "\"");
warnings += "Variable not found: label=\"" + ((label != null) ? label : "<none>") + "\" item=\"" + ((item != null) ? item : "<none>") + "\"\n";
}
}
if (!warnings.equals("")) {
JOptionPane.showMessageDialog(_who, warnings);
} else {
JOptionPane.showMessageDialog(_who, "No mismatched items found");
}
} catch (HeadlessException | IOException | JDOMException ex) {
JOptionPane.showMessageDialog(_who, "Error parsing decoder file: " + ex);
}
} else {
log.debug("XmlFileCheckAction cancelled in open dialog");
}
}
Aggregations