protected void newVarButtonPerformed() { String name = newVarName.getText(); String CV = newVarCv.getText(); String mask = newVarMask.getText(); // ask Table model to do the actuall add variableModel.newDecVariableValue(name, CV, null, mask, false, false, false, false); variableModel.configDone(); }
// use the decoder Element from the file to load a VariableTableModel for programming. public void loadVariableModel(Element decoderElement, VariableTableModel variableModel) { nextCvStoreIndex = 0; nextICvStoreIndex = 0; processVariablesElement(decoderElement.getChild("variables"), variableModel, "", ""); variableModel.configDone(); }
void processLocoFile(Element loco) { // load the name et al locoRoadName.setText(loco.getAttributeValue("roadName")); locoRoadNumber.setText(loco.getAttributeValue("roadNumber")); locoMfg.setText(loco.getAttributeValue("mfg")); locoModel.setText(loco.getAttributeValue("model")); // load the variable definitions for the decoder Element decoder = loco.getChild("decoder"); if (decoder != null) { // get the file name String mfg = decoder.getAttribute("mfg").getValue(); String model = decoder.getAttribute("model").getValue(); String filename = "xml" + File.separator + mfg + "_" + model + ".xml"; if (log.isDebugEnabled()) { log.debug("will read decoder info from " + filename); } readAndParseConfigFile(new File(filename)); if (log.isDebugEnabled()) { log.debug("finished processing decoder file for loco file"); } } else { log.error("No decoder element found in config file"); } // get the CVs and load Element values = loco.getChild("values"); if (values != null) { // get the CV values and load List<Element> varList = values.getChildren("CVvalue"); if (log.isDebugEnabled()) { log.debug("Found " + varList.size() + " CVvalues"); } for (int i = 0; i < varList.size(); i++) { // locate the row if (((varList.get(i))).getAttribute("name") == null) { if (log.isDebugEnabled()) { log.debug( "unexpected null in name " + ((varList.get(i))) + " " + ((varList.get(i))).getAttributes()); } break; } if (((varList.get(i))).getAttribute("value") == null) { if (log.isDebugEnabled()) { log.debug( "unexpected null in value " + ((varList.get(i))) + " " + ((varList.get(i))).getAttributes()); } break; } String name = ((varList.get(i))).getAttribute("name").getValue(); String value = ((varList.get(i))).getAttribute("value").getValue(); if (log.isDebugEnabled()) { log.debug("CV: " + i + "th entry, CV number " + name + " has value: " + value); } CvValue cvObject = cvModel.allCvMap().get(name); cvObject.setValue(Integer.valueOf(value).intValue()); cvObject.setState(CvValue.FROMFILE); } variableModel.configDone(); } else { log.error("no values element found in config file; CVs not configured"); return; } // get the variable values and load Element decoderDef = values.getChild("decoderDef"); if (decoderDef != null) { List<Element> varList = decoderDef.getChildren("varValue"); if (log.isDebugEnabled()) { log.debug("Found " + varList.size() + " varValues"); } for (int i = 0; i < varList.size(); i++) { // locate the row Attribute itemAttr = null; if ((itemAttr = varList.get(i).getAttribute("item")) == null) { if (log.isDebugEnabled()) { log.debug("unexpected null in item " + varList.get(i)); } break; } if ((itemAttr = varList.get(i).getAttribute("name")) == null) { if (log.isDebugEnabled()) { log.debug("unexpected null in name " + varList.get(i)); } break; } String item = itemAttr.getValue(); if (((varList.get(i))).getAttribute("value") == null) { if (log.isDebugEnabled()) { log.debug("unexpected null in value " + ((varList.get(i)))); } break; } String value = ((varList.get(i))).getAttribute("value").getValue(); if (log.isDebugEnabled()) { log.debug("Variable " + i + " is " + item + " value: " + value); } int row; for (row = 0; row < variableModel.getRowCount(); row++) { if (variableModel.getLabel(row).equals(item)) { break; } } if (log.isDebugEnabled()) { log.debug("Variable " + item + " is row " + row); } if (!value.equals("")) { // don't set if no value was stored variableModel.setIntValue(row, Integer.valueOf(value).intValue()); } variableModel.setState(row, VariableValue.FROMFILE); } variableModel.configDone(); } else { log.error("no decoderDef element found in config file"); } // the act of loading values marks as dirty, but we're actually in synch variableModel.setFileDirty(false); }