Search in sources :

Example 16 with Attribute

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

the class TrainSwitchListText method load.

public static void load(Element e) {
    Element emts = e.getChild(Xml.SWITCH_LIST_TEXT_STRINGS);
    if (emts == null) {
        return;
    }
    Attribute a;
    if (emts.getChild(Xml.SWICH_LIST_FOR) != null) {
        if ((a = emts.getChild(Xml.SWICH_LIST_FOR).getAttribute(Xml.TEXT)) != null) {
            setStringSwitchListFor(a.getValue());
        }
    }
    if (emts.getChild(Xml.SCHEDULED_WORK_TRAIN) != null) {
        if ((a = emts.getChild(Xml.SCHEDULED_WORK_TRAIN).getAttribute(Xml.TEXT)) != null) {
            setStringScheduledWork(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPARTS_AT) != null) {
        if ((a = emts.getChild(Xml.DEPARTS_AT).getAttribute(Xml.TEXT)) != null) {
            setStringDepartsAt(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPARTS_EXPECTED_ARRIVAL) != null) {
        if ((a = emts.getChild(Xml.DEPARTS_EXPECTED_ARRIVAL).getAttribute(Xml.TEXT)) != null) {
            setStringDepartsAtExpectedArrival(a.getValue());
        }
    }
    if (emts.getChild(Xml.DEPARTED_EXPECTED) != null) {
        if ((a = emts.getChild(Xml.DEPARTED_EXPECTED).getAttribute(Xml.TEXT)) != null) {
            setStringDepartedExpected(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumber(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_DEPARTED) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_DEPARTED).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberDeparted(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_TERMINATES) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_TERMINATES).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberTerminates(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_TERMINATES_DEPARTED) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_TERMINATES_DEPARTED).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberTerminatesDeparted(a.getValue());
        }
    }
    if (emts.getChild(Xml.VISIT_NUMBER_DONE) != null) {
        if ((a = emts.getChild(Xml.VISIT_NUMBER_DONE).getAttribute(Xml.TEXT)) != null) {
            setStringVisitNumberDone(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DIRECTION_CHANGE) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DIRECTION_CHANGE).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDirectionChange(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_CAR_PICK_UPS) != null) {
        if ((a = emts.getChild(Xml.NO_CAR_PICK_UPS).getAttribute(Xml.TEXT)) != null) {
            setStringNoCarPickUps(a.getValue());
        }
    }
    if (emts.getChild(Xml.NO_CAR_SET_OUTS) != null) {
        if ((a = emts.getChild(Xml.NO_CAR_SET_OUTS).getAttribute(Xml.TEXT)) != null) {
            setStringNoCarDrops(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DONE) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DONE).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDone(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_CARS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_CARS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsCars(a.getValue());
        }
    }
    if (emts.getChild(Xml.TRAIN_DEPARTS_LOADS) != null) {
        if ((a = emts.getChild(Xml.TRAIN_DEPARTS_LOADS).getAttribute(Xml.TEXT)) != null) {
            setStringTrainDepartsLoads(a.getValue());
        }
    }
    if (emts.getChild(Xml.SWITCH_LIST_TRACK) != null) {
        if ((a = emts.getChild(Xml.SWITCH_LIST_TRACK).getAttribute(Xml.TEXT)) != null) {
            setStringSwitchListByTrack(a.getValue());
        }
    }
    if (emts.getChild(Xml.HOLD_CAR) != null) {
        if ((a = emts.getChild(Xml.HOLD_CAR).getAttribute(Xml.TEXT)) != null) {
            setStringHoldCar(a.getValue());
        }
    }
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 17 with Attribute

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

the class SymbolicProgFrame method processLocoFile.

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);
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element) CvValue(jmri.jmrit.symbolicprog.CvValue) DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) File(java.io.File)

Example 18 with Attribute

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

the class VariableTableModel method processIEnumVal.

protected VariableValue processIEnumVal(Element child, String name, String comment, String cvName, boolean readOnly, boolean infoOnly, boolean writeOnly, boolean opsOnly, String cv, String mask, String item, String productID, String modelID, String familyID) throws NumberFormatException {
    VariableValue iv;
    List<Element> l = child.getChildren("ienumChoice");
    IndexedEnumVariableValue v1 = new IndexedEnumVariableValue(name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, _indxCvModel.allIndxCvMap(), _status, item);
    iv = v1;
    for (int x = 0; x < l.size(); x++) {
        Element ex = l.get(x);
        if (DecoderFile.isIncluded(ex, productID, modelID, familyID, "", "") == false) {
            // add inherited include, inherited exclude
            l.remove(x);
            x--;
        }
    }
    v1.nItems(l.size());
    for (int k = 0; k < l.size(); k++) {
        Element enumChElement = l.get(k);
        // is a value specified?
        Attribute valAttr = enumChElement.getAttribute("value");
        if (valAttr == null) {
            v1.addItem(LocaleSelector.getAttribute(enumChElement, "choice"));
        } else {
            v1.addItem(LocaleSelector.getAttribute(enumChElement, "choice"), Integer.parseInt(valAttr.getValue()));
        }
    }
    v1.lastItem();
    return iv;
}
Also used : Attribute(org.jdom2.Attribute) Element(org.jdom2.Element)

Example 19 with Attribute

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

the class VariableTableModel method setIndxRow.

/**
     * Load one row in the IndexedVariableTableModel, 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"
     * @param productID product ID of decoder, passed in so that subparts of the
     *                  variable can use it for selection
     */
public int setIndxRow(int row, Element e, String productID, String modelID, String familyID) {
    // 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 setIndexedRow \"" + name + "\" row " + row);
    }
    String cvName = e.getAttributeValue("CVname");
    String item = (e.getAttribute("item") != null ? e.getAttribute("item").getValue() : null);
    String comment = LocaleSelector.getAttribute(e, "comment");
    int piVal = Integer.valueOf(e.getAttribute("PI").getValue()).intValue();
    int siVal = (e.getAttribute("SI") != null ? Integer.valueOf(e.getAttribute("SI").getValue()).intValue() : -1);
    String 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;
    JButton br = new JButton("Read");
    _readButtons.addElement(br);
    JButton bw = new JButton("Write");
    _writeButtons.addElement(bw);
    setButtonsReadWrite(readOnly, infoOnly, writeOnly, bw, br, row);
    if (_indxCvModel == null) {
        log.error("IndexedCvModel reference is null; can not add variables");
        return -1;
    }
    // add the information to the indexed CV model
    int _newRow = _indxCvModel.addIndxCV(cvName, _piCv, piVal, _siCv, siVal, cv, readOnly, infoOnly, writeOnly);
    if (_newRow != row) {
        row = _newRow;
        if (log.isDebugEnabled()) {
            log.debug("new row is " + _newRow + ", row was " + row);
        }
    }
    // Find and process the specific content types
    VariableValue iv;
    iv = createIndexedVariableFromElement(e, name, comment, cvName, readOnly, infoOnly, writeOnly, opsOnly, cv, mask, item, productID, modelID, familyID);
    if (iv == null) {
        // trouble reporting
        reportBogus();
        return -1;
    }
    processModifierElements(e, iv);
    setToolTip(e, iv);
    // record new variable, update state, hook up listeners
    rowVector.addElement(iv);
    iv.setState(VariableValue.FROMFILE);
    iv.addPropertyChangeListener(this);
    // set to default value if specified (CV load may later override this)
    Attribute a;
    if ((a = e.getAttribute("default")) != null) {
        String val = a.getValue();
        if (log.isDebugEnabled()) {
            log.debug("Found default value: " + val + " for " + name);
        }
        iv.setIntValue(Integer.valueOf(val).intValue());
        if (_indxCvModel.getCvByRow(row).getInfoOnly()) {
            _indxCvModel.getCvByRow(row).setState(VariableValue.READ);
        } else {
            // correct for transition to "edited"
            _indxCvModel.getCvByRow(row).setState(VariableValue.FROMFILE);
        }
    } else {
        _indxCvModel.getCvByRow(row).setState(VariableValue.UNKNOWN);
    }
    return row;
}
Also used : Attribute(org.jdom2.Attribute) JButton(javax.swing.JButton)

Example 20 with Attribute

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

the class VariableTableModel method setDefaultValue.

/**
     * If there's a "default" attribute, set that value to start
     *
     * @return true if the value was set
     */
protected boolean setDefaultValue(Element e, VariableValue v) {
    Attribute a;
    if ((a = e.getAttribute("default")) != null) {
        String val = a.getValue();
        v.setIntValue(Integer.valueOf(val).intValue());
        return true;
    }
    return false;
}
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