use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method processSpeedTableVal.
protected VariableValue processSpeedTableVal(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();
}
Attribute entriesAttr = child.getAttribute("entries");
int entries = 28;
try {
if (entriesAttr != null) {
entries = entriesAttr.getIntValue();
}
} catch (org.jdom2.DataConversionException e1) {
}
Attribute ESUAttr = child.getAttribute("mfx");
boolean mfxFlag = false;
try {
if (ESUAttr != null) {
mfxFlag = ESUAttr.getBooleanValue();
}
} catch (org.jdom2.DataConversionException e1) {
}
// ensure all CVs exist
for (int i = 0; i < entries; i++) {
_cvModel.addCV(Integer.toString(Integer.parseInt(CV) + i), readOnly, infoOnly, writeOnly);
}
if (mfxFlag) {
_cvModel.addCV("2", readOnly, infoOnly, writeOnly);
_cvModel.addCV("5", readOnly, infoOnly, writeOnly);
}
v = new SpeedTableVarValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, minVal, maxVal, _cvModel.allCvMap(), _status, item, entries, mfxFlag);
return v;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method setRow.
/**
* Load one row in the VariableTableModel, by reading in the Element
* containing its definition.
* <p>
* Invoked from DecoderFile
*
* @param row number of row to fill
* @param e Element of type "variable"
*/
public void setRow(int row, Element e) {
// get the values for the VariableValue ctor
// Note the name variable is actually the label attribute
String name = LocaleSelector.getAttribute(e, "label");
if (log.isDebugEnabled()) {
log.debug("Starting to setRow \"" + name + "\"");
}
String item = (e.getAttribute("item") != null ? e.getAttribute("item").getValue() : null);
// as a special case, if no item, use label
if (item == null) {
item = name;
log.debug("no item attribute, used label \"" + name + "\"");
}
// as a special case, if no label, use item
if (name == null) {
name = item;
log.debug("no label attribute, used item attribute \"" + item + "\"");
}
String comment = LocaleSelector.getAttribute(e, "comment");
String CV = "";
if (e.getAttribute("CV") != null) {
CV = e.getAttribute("CV").getValue();
}
String mask = null;
if (e.getAttribute("mask") != null) {
mask = e.getAttribute("mask").getValue();
} else {
mask = "VVVVVVVV";
}
boolean readOnly = e.getAttribute("readOnly") != null ? e.getAttribute("readOnly").getValue().equals("yes") : false;
boolean infoOnly = e.getAttribute("infoOnly") != null ? e.getAttribute("infoOnly").getValue().equals("yes") : false;
boolean writeOnly = e.getAttribute("writeOnly") != null ? e.getAttribute("writeOnly").getValue().equals("yes") : false;
boolean opsOnly = e.getAttribute("opsOnly") != null ? e.getAttribute("opsOnly").getValue().equals("yes") : false;
// Ops mode doesn't allow reads, therefore we must disable read buttons
if (_cvModel.getProgrammer() != null && !_cvModel.getProgrammer().getCanRead()) {
// can't read, so adjust
if (readOnly) {
readOnly = false;
infoOnly = true;
}
if (!infoOnly) {
writeOnly = true;
}
}
JButton bw = new JButton(Bundle.getMessage("ButtonWrite"));
_writeButtons.addElement(bw);
JButton br = new JButton(Bundle.getMessage("ButtonRead"));
_readButtons.addElement(br);
setButtonsReadWrite(readOnly, infoOnly, writeOnly, bw, br, row);
if (_cvModel == null) {
log.error("CvModel reference is null; cannot add variables");
return;
}
if (// some variables have no CV per se
!CV.equals("")) {
_cvModel.addCV(CV, readOnly, infoOnly, writeOnly);
}
// decode and handle specific types
Element child;
VariableValue v = null;
if ((child = e.getChild("decVal")) != null) {
v = processDecVal(child, name, comment, readOnly, infoOnly, writeOnly, opsOnly, CV, mask, item);
} else if ((child = e.getChild("hexVal")) != null) {
v = processHexVal(child, name, comment, readOnly, infoOnly, writeOnly, opsOnly, CV, mask, item);
} else if ((child = e.getChild("enumVal")) != null) {
v = processEnumVal(child, name, comment, readOnly, infoOnly, writeOnly, opsOnly, CV, mask, item);
} else if ((child = e.getChild("compositeVal")) != null) {
// loop over the choices
v = processCompositeVal(child, name, comment, readOnly, infoOnly, writeOnly, opsOnly, CV, mask, item);
} else if ((child = e.getChild("speedTableVal")) != null) {
v = processSpeedTableVal(child, CV, readOnly, infoOnly, writeOnly, name, comment, opsOnly, mask, item);
} else if ((child = e.getChild("longAddressVal")) != null) {
v = processLongAddressVal(CV, readOnly, infoOnly, writeOnly, name, comment, opsOnly, mask, item);
} else if ((child = e.getChild("shortAddressVal")) != null) {
v = processShortAddressVal(name, comment, readOnly, infoOnly, writeOnly, opsOnly, CV, mask, item, child);
} else if ((child = e.getChild("splitVal")) != null) {
v = processSplitVal(child, CV, readOnly, infoOnly, writeOnly, name, comment, opsOnly, mask, item);
} else {
reportBogus();
return;
}
processModifierElements(e, v);
setToolTip(e, v);
// 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 may later override this)
if (setDefaultValue(e, v)) {
// correct for transition to "edited"
_cvModel.getCvByNumber(CV).setState(VariableValue.FROMFILE);
}
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method processHexVal.
protected VariableValue processHexVal(Element child, String name, String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String CV, 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(), 16).intValue();
}
if ((a = child.getAttribute("max")) != null) {
maxVal = Integer.valueOf(a.getValue(), 16).intValue();
}
v = new HexVariableValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, minVal, maxVal, _cvModel.allCvMap(), _status, item);
return v;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method processCompositeVal.
protected VariableValue processCompositeVal(Element child, String name, String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String CV, String mask, String item) {
VariableValue v;
List<Element> lChoice = child.getChildren("compositeChoice");
CompositeVariableValue v1 = new CompositeVariableValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, 0, lChoice.size() - 1, _cvModel.allCvMap(), _status, item);
// v1 is of CompositeVariableType, so doesn't need casts
v = v1;
// loop over the choices
for (int k = 0; k < lChoice.size(); k++) {
// Create the choice
Element choiceElement = lChoice.get(k);
String choice = LocaleSelector.getAttribute(choiceElement, "choice");
v1.addChoice(choice);
// for each choice, capture the settings
@SuppressWarnings("unchecked") List<Element> lSetting = choiceElement.getChildren("compositeSetting");
for (int n = 0; n < lSetting.size(); n++) {
Element settingElement = lSetting.get(n);
String varName = LocaleSelector.getAttribute(settingElement, "label");
String value = settingElement.getAttribute("value").getValue();
v1.addSetting(choice, varName, findVar(varName), value);
}
}
v1.lastItem();
return v;
}
use of org.jdom2.Comment in project JMRI by JMRI.
the class VariableTableModel method processDecVal.
protected VariableValue processDecVal(Element child, String name, String comment, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String CV, 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();
}
v = new DecVariableValue(name, comment, "", readOnly, infoOnly, writeOnly, opsOnly, CV, mask, minVal, maxVal, _cvModel.allCvMap(), _status, item);
return v;
}
Aggregations