Search in sources :

Example 16 with VariableValue

use of jmri.jmrit.symbolicprog.VariableValue in project JMRI by JMRI.

the class PaneProgPane method nextRead.

/**
     * If there are any more read operations to be done on this pane, do the
     * next one.
     * <P>
     * Each invocation of this method reads one variable or CV; completion of
     * that request will cause it to happen again, reading the next one, until
     * there's nothing left to read.
     * <P>
     * @return true is a read has been started, false if the pane is complete.
     */
boolean nextRead() {
    // look for possible variables
    if (log.isDebugEnabled()) {
        log.debug("nextRead scans " + varList.size() + " variables");
    }
    while ((varList.size() > 0) && (varListIndex < varList.size())) {
        int varNum = varList.get(varListIndex);
        int vState = _varModel.getState(varNum);
        VariableValue var = _varModel.getVariable(varNum);
        if (log.isDebugEnabled()) {
            log.debug("nextRead var index " + varNum + " state " + VariableValue.stateNameFromValue(vState) + " isToRead: " + var.isToRead() + " label: " + var.label());
        }
        varListIndex++;
        if (var.isToRead()) {
            if (log.isDebugEnabled()) {
                log.debug("start read of variable " + _varModel.getLabel(varNum));
            }
            executeRead(var);
            if (log.isDebugEnabled()) {
                log.debug("return from starting var read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // found no variables needing read, try CVs
    if (log.isDebugEnabled()) {
        log.debug("nextRead scans " + cvList.size() + " CVs");
    }
    while (cvListIterator != null && cvListIterator.hasNext()) {
        int cvNum = cvListIterator.next();
        CvValue cv = _cvModel.getCvByRow(cvNum);
        if (log.isDebugEnabled()) {
            log.debug("nextRead cv index " + cvNum + " state " + cv.getState());
        }
        if (cv.isToRead()) {
            // always read UNKNOWN state
            if (log.isDebugEnabled()) {
                log.debug("start read of cv " + cvNum);
            }
            setBusy(true);
            if (_programmingCV != null) {
                log.error("listener already set at read start");
            }
            _programmingCV = _cvModel.getCvByRow(cvNum);
            _read = true;
            // get notified when that state changes so can repeat
            _programmingCV.addPropertyChangeListener(this);
            // and make the read request
            // _programmingCV.setToRead(false);  // CVs set this themselves
            _programmingCV.read(_cvModel.getStatusLabel());
            if (log.isDebugEnabled()) {
                log.debug("return from starting CV read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // found no CVs needing read, try indexed CVs
    if (log.isDebugEnabled()) {
        log.debug("nextRead scans " + indexedCvList.size() + " indexed CVs");
    }
    while ((indexedCvList.size() > 0) && (indexedCvListIndex < indexedCvList.size())) {
        int indxVarNum = indexedCvList.get(indexedCvListIndex);
        int indxState = _varModel.getState(indxVarNum);
        if (log.isDebugEnabled()) {
            log.debug("nextRead indexed cv @ row index " + indexedCvListIndex + " state " + indxState);
        }
        VariableValue iCv = _varModel.getVariable(indxVarNum);
        indexedCvListIndex++;
        if (iCv.isToRead()) {
            String sz = "start read of indexed cv " + (_indexedCvModel.getCvByRow(indexedCvListIndex - 1)).cvName();
            if (log.isDebugEnabled()) {
                log.debug(sz);
            }
            setBusy(true);
            if (_programmingIndexedCV != null) {
                log.error("listener already set at read start");
            }
            _programmingIndexedCV = _varModel.getVariable(indxVarNum);
            _read = true;
            // get notified when that state changes so can repeat
            _programmingIndexedCV.addPropertyChangeListener(this);
            // and make the read request
            // _programmingIndexedCV.setToRead(false);  // CVs set this themselves
            _programmingIndexedCV.readAll();
            if (log.isDebugEnabled()) {
                log.debug("return from starting indexed CV read");
            }
            // only make one request at a time!
            return true;
        }
    }
    // nothing to program, end politely
    if (log.isDebugEnabled()) {
        log.debug("nextRead found nothing to do");
    }
    readChangesButton.setSelected(false);
    // reset both, as that's final state we want
    readAllButton.setSelected(false);
    setBusy(false);
    container.paneFinished();
    return false;
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 17 with VariableValue

use of jmri.jmrit.symbolicprog.VariableValue in project JMRI by JMRI.

the class PaneProgPane method getRepresentation.

/**
     * Get a GUI representation of a particular variable for display.
     *
     * @param name Name used to look up the Variable object
     * @param var  XML Element which might contain a "format" attribute to be
     *             used in the {@link VariableValue#getNewRep} call from the
     *             Variable object; "tooltip" elements are also processed here.
     * @return JComponent representing this variable
     */
public JComponent getRepresentation(String name, Element var) {
    int i = _varModel.findVarIndex(name);
    VariableValue variable = _varModel.getVariable(i);
    JComponent rep = null;
    String format = "default";
    Attribute attr;
    if ((attr = var.getAttribute("format")) != null && attr.getValue() != null) {
        format = attr.getValue();
    }
    if (i >= 0) {
        rep = getRep(i, format);
        rep.setMaximumSize(rep.getPreferredSize());
        // set tooltip if specified here & not overridden by defn in Variable
        String tip = LocaleSelector.getAttribute(var, "tooltip");
        if (rep.getToolTipText() != null) {
            tip = rep.getToolTipText();
        }
        rep.setToolTipText(modifyToolTipText(tip, variable));
    }
    return rep;
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) Attribute(org.jdom2.Attribute) JComponent(javax.swing.JComponent)

Aggregations

VariableValue (jmri.jmrit.symbolicprog.VariableValue)17 QualifierAdder (jmri.jmrit.symbolicprog.QualifierAdder)9 CvValue (jmri.jmrit.symbolicprog.CvValue)7 JPanel (javax.swing.JPanel)6 Element (org.jdom2.Element)6 GridBagConstraints (java.awt.GridBagConstraints)5 GridBagLayout (java.awt.GridBagLayout)5 Dimension (java.awt.Dimension)4 JButton (javax.swing.JButton)4 JScrollPane (javax.swing.JScrollPane)4 JSeparator (javax.swing.JSeparator)4 JTable (javax.swing.JTable)4 JTextField (javax.swing.JTextField)4 ValueEditor (jmri.jmrit.symbolicprog.ValueEditor)4 ValueRenderer (jmri.jmrit.symbolicprog.ValueRenderer)4 JLabel (javax.swing.JLabel)3 ArrayList (java.util.ArrayList)2 Attribute (org.jdom2.Attribute)2 Font (java.awt.Font)1 Insets (java.awt.Insets)1