Search in sources :

Example 11 with VariableValue

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

the class PaneProgPane method newGroup.

/**
     * Create a new group from the JDOM group Element
     *
     * @param element     element containing group contents
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     * @param modelElem   element containing the decoder model
     * @return a panel containing the group
     */
protected JPanel newGroup(Element element, boolean showStdName, Element modelElem) {
    // create a panel to add as a new column or row
    final JPanel c = new JPanel();
    panelList.add(c);
    GridBagLayout g = new GridBagLayout();
    GridBagConstraints cs = new GridBagConstraints();
    c.setLayout(g);
    // handle include/exclude
    if (!PaneProgFrame.isIncludedFE(element, modelElem, rosterEntry, "", "")) {
        return c;
    }
    // handle the xml definition
    // for all elements in the column or row
    List<Element> elemList = element.getChildren();
    log.trace("newColumn starting with {} elements", elemList.size());
    for (int i = 0; i < elemList.size(); i++) {
        Element e = (elemList.get(i));
        String name = e.getName();
        log.trace("newGroup processing {} element", name);
        // decode the type
        if (name.equals("display")) {
            // its a variable
            // load the variable
            newVariable(e, c, g, cs, showStdName);
        } else if (name.equals("separator")) {
            // its a separator
            JSeparator j = new JSeparator(javax.swing.SwingConstants.HORIZONTAL);
            cs.fill = GridBagConstraints.BOTH;
            cs.gridwidth = GridBagConstraints.REMAINDER;
            g.setConstraints(j, cs);
            c.add(j);
            cs.gridwidth = 1;
        } else if (name.equals("label")) {
            cs.gridwidth = GridBagConstraints.REMAINDER;
            makeLabel(e, c, g, cs);
        } else if (name.equals("soundlabel")) {
            cs.gridwidth = GridBagConstraints.REMAINDER;
            makeSoundLabel(e, c, g, cs);
        } else if (name.equals("cvtable")) {
            makeCvTable(cs, g, c);
        } else if (name.equals("indxcvtable")) {
            log.debug("starting to build IndexedCvTable pane");
            JTable indxcvTable = new JTable(_indexedCvModel);
            JScrollPane cvScroll = new JScrollPane(indxcvTable);
            indxcvTable.setDefaultRenderer(JTextField.class, new ValueRenderer());
            indxcvTable.setDefaultRenderer(JButton.class, new ValueRenderer());
            indxcvTable.setDefaultEditor(JTextField.class, new ValueEditor());
            indxcvTable.setDefaultEditor(JButton.class, new ValueEditor());
            indxcvTable.setRowHeight(new JButton("X").getPreferredSize().height);
            indxcvTable.setPreferredScrollableViewportSize(new Dimension(700, indxcvTable.getRowHeight() * 14));
            cvScroll.setColumnHeaderView(indxcvTable.getTableHeader());
            // don't want a horizontal scroll bar
            // Need to see the whole row at one time
            //                indxcvTable.setAutoResizeMode(JTable.AUTO_RESIZE_OFF);
            cs.gridwidth = GridBagConstraints.REMAINDER;
            g.setConstraints(cvScroll, cs);
            c.add(cvScroll);
            cs.gridwidth = 1;
            // remember which indexed CVs to read/write
            for (int j = 0; j < _indexedCvModel.getRowCount(); j++) {
                String sz = "CV" + _indexedCvModel.getName(j);
                int in = _varModel.findVarIndex(sz);
                indexedCvList.add(in);
            }
            _cvTable = true;
            log.debug("end of building IndexedCvTable pane");
        } else if (name.equals("fnmapping")) {
            pickFnMapPanel(c, g, cs, modelElem);
        } else if (name.equals("dccaddress")) {
            JPanel l = addDccAddressPanel(e);
            if (l.getComponentCount() > 0) {
                cs.gridwidth = GridBagConstraints.REMAINDER;
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("column")) {
            // nested "column" elements ...
            cs.gridheight = GridBagConstraints.REMAINDER;
            JPanel l = newColumn(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridheight = 1;
            }
        } else if (name.equals("row")) {
            // nested "row" elements ...
            cs.gridwidth = GridBagConstraints.REMAINDER;
            JPanel l = newRow(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("grid")) {
            // nested "grid" elements ...
            cs.gridwidth = GridBagConstraints.REMAINDER;
            JPanel l = newGrid(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
                cs.gridwidth = 1;
            }
        } else if (name.equals("group")) {
            // nested "group" elements ...
            JPanel l = newGroup(e, showStdName, modelElem);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, cs);
                c.add(l);
            }
        } else if (!name.equals("qualifier")) {
            // its a mistake
            log.error("No code to handle element of type " + e.getName() + " in newColumn");
        }
    }
    // add glue to the bottom to allow resize
    if (c.getComponentCount() > 0) {
        c.add(Box.createVerticalGlue());
    }
    // handle qualification if any
    QualifierAdder qa = new QualifierAdder() {

        @Override
        protected Qualifier createQualifier(VariableValue var, String relation, String value) {
            return new JComponentQualifier(c, var, Integer.parseInt(value), relation);
        }

        @Override
        protected void addListener(java.beans.PropertyChangeListener qc) {
            c.addPropertyChangeListener(qc);
        }
    };
    qa.processModifierElements(element, _varModel);
    return c;
}
Also used : JScrollPane(javax.swing.JScrollPane) JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) VariableValue(jmri.jmrit.symbolicprog.VariableValue) Element(org.jdom2.Element) JButton(javax.swing.JButton) ValueEditor(jmri.jmrit.symbolicprog.ValueEditor) Dimension(java.awt.Dimension) JTextField(javax.swing.JTextField) JSeparator(javax.swing.JSeparator) ValueRenderer(jmri.jmrit.symbolicprog.ValueRenderer) JTable(javax.swing.JTable) QualifierAdder(jmri.jmrit.symbolicprog.QualifierAdder)

Example 12 with VariableValue

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

the class PaneProgPane method setToWrite.

/**
     * Set the "ToWrite" parameter in all variables and CVs on this pane
     *
     * @param justChanges  true if this is read changes, false if read all
     * @param startProcess true if this is the start of processing, false if
     *                     cleaning up at end
     */
void setToWrite(boolean justChanges, boolean startProcess) {
    if (log.isDebugEnabled()) {
        log.debug("start setToWrite method with " + justChanges + "," + startProcess);
    }
    if (!container.isBusy() || // the frame has already setToWrite
    (!startProcess)) {
        // we want to setToWrite false if the pane's process is being stopped
        log.debug("about to start setToWrite of varList");
        for (int i = 0; i < varList.size(); i++) {
            int varNum = varList.get(i);
            VariableValue var = _varModel.getVariable(varNum);
            if (justChanges) {
                if (var.isChanged()) {
                    var.setToWrite(startProcess);
                } else {
                    var.setToWrite(false);
                }
            } else {
                var.setToWrite(startProcess);
            }
        }
        log.debug("about to start setToWrite of cvList");
        if (isCvTablePane) {
            // make sure list of CVs up to date if table
            setCvListFromTable();
        }
        for (int cvNum : cvList) {
            CvValue cv = _cvModel.getCvByRow(cvNum);
            if (justChanges) {
                if (VariableValue.considerChanged(cv)) {
                    cv.setToWrite(startProcess);
                } else {
                    cv.setToWrite(false);
                }
            } else {
                cv.setToWrite(startProcess);
            }
        }
        log.debug("about to start setToWrite of indexedCvList");
        for (int i = 0; i < indexedCvList.size(); i++) {
            CvValue icv = _indexedCvModel.getCvByRow(i);
            if (justChanges) {
                if (VariableValue.considerChanged(icv)) {
                    icv.setToWrite(startProcess);
                } else {
                    icv.setToWrite(false);
                }
            } else {
                icv.setToWrite(startProcess);
            }
        }
    }
    log.debug("end setToWrite method");
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 13 with VariableValue

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

the class PaneProgPane method newGrid.

/**
     * Create a grid from the JDOM Element.
     *
     * @param element     element containing group contents
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     * @param modelElem   element containing the decoder model
     * @return a panel containing the group
     */
public JPanel newGrid(Element element, boolean showStdName, Element modelElem) {
    // create a panel to add as a new grid
    final JPanel c = new JPanel();
    panelList.add(c);
    GridBagLayout g = new GridBagLayout();
    c.setLayout(g);
    GridGlobals globs = new GridGlobals();
    // handle the xml definition
    // for all elements in the grid
    List<Element> elemList = element.getChildren();
    // get grid-level attributes
    globs.gridAttList = element.getAttributes();
    log.trace("newGrid starting with {} elements", elemList.size());
    for (int i = 0; i < elemList.size(); i++) {
        globs.gridConstraints = new GridBagConstraints();
        Element e = elemList.get(i);
        String name = e.getName();
        log.trace("newGrid processing {} element", name);
        // decode the type
        if (name.equals("griditem")) {
            JPanel l = newGridItem(e, showStdName, modelElem, globs);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, globs.gridConstraints);
                c.add(l);
            //                     globs.gridConstraints.gridwidth = 1;
            }
        } else if (name.equals("group")) {
            // nested "group" elements ...
            newGridGroup(e, c, g, globs, showStdName, modelElem);
        } else if (!name.equals("qualifier")) {
            // its a mistake
            log.error("No code to handle element of type " + e.getName() + " in newGrid");
        }
    }
    // add glue to the bottom to allow resize
    if (c.getComponentCount() > 0) {
        c.add(Box.createVerticalGlue());
    }
    // handle qualification if any
    QualifierAdder qa = new QualifierAdder() {

        @Override
        protected Qualifier createQualifier(VariableValue var, String relation, String value) {
            return new JComponentQualifier(c, var, Integer.parseInt(value), relation);
        }

        @Override
        protected void addListener(java.beans.PropertyChangeListener qc) {
            c.addPropertyChangeListener(qc);
        }
    };
    qa.processModifierElements(element, _varModel);
    return c;
}
Also used : JPanel(javax.swing.JPanel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) VariableValue(jmri.jmrit.symbolicprog.VariableValue) Element(org.jdom2.Element) QualifierAdder(jmri.jmrit.symbolicprog.QualifierAdder)

Example 14 with VariableValue

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

the class PaneProgPane method makeOpsNeededSet.

/**
     * Produce a set of CVs that will be accessed when reading or writing the
     * contents of this pane.
     *
     * @param read    true if counting for read, false for write
     * @param changes true if counting for a *Changes operation; false, if
     *                counting for a *All operation
     * @param set     The set to fill. Any CVs already in here will not be
     *                duplicated, which provides a way to aggregate a set of CVs
     *                across multiple panes.
     * @return the same set as the parameter, for convenient chaining of
     *         operations.
     */
public Set<Integer> makeOpsNeededSet(boolean read, boolean changes, Set<Integer> set) {
    // scan the variable list
    for (int i = 0; i < varList.size(); i++) {
        int varNum = varList.get(i);
        VariableValue var = _varModel.getVariable(varNum);
        // must decide whether this one should be counted
        if (!changes || var.isChanged()) {
            CvValue[] cvs = var.usesCVs();
            for (CvValue cv : cvs) {
                // always of interest
                if (!changes || VariableValue.considerChanged(cv)) {
                    set.add(Integer.valueOf(cv.number()));
                }
            }
        }
    }
    return set;
}
Also used : VariableValue(jmri.jmrit.symbolicprog.VariableValue) CvValue(jmri.jmrit.symbolicprog.CvValue)

Example 15 with VariableValue

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

the class PaneProgPane method newGridGroup.

/**
     * Create a new grid group from the JDOM group Element.
     *
     * @param element     element containing group contents
     * @param c           the panel to create the grid in
     * @param g           the layout manager for the panel
     * @param globs       properties to configure g
     * @param showStdName show the name following the rules for the
     * <em>nameFmt</em> element
     * @param modelElem   element containing the decoder model
     */
protected void newGridGroup(Element element, final JPanel c, GridBagLayout g, GridGlobals globs, boolean showStdName, Element modelElem) {
    // handle include/exclude
    if (!PaneProgFrame.isIncludedFE(element, modelElem, rosterEntry, "", "")) {
        return;
    }
    // handle the xml definition
    // for all elements in the column or row
    List<Element> elemList = element.getChildren();
    log.trace("newColumn starting with {} elements", elemList.size());
    for (int i = 0; i < elemList.size(); i++) {
        Element e = (elemList.get(i));
        String name = e.getName();
        log.trace("newGroup processing {} element", name);
        // decode the type
        if (name.equals("griditem")) {
            final JPanel l = newGridItem(e, showStdName, modelElem, globs);
            if (l.getComponentCount() > 0) {
                panelList.add(l);
                g.setConstraints(l, globs.gridConstraints);
                c.add(l);
                //                     globs.gridConstraints.gridwidth = 1;
                // handle qualification if any
                QualifierAdder qa = new QualifierAdder() {

                    @Override
                    protected Qualifier createQualifier(VariableValue var, String relation, String value) {
                        return new JComponentQualifier(l, var, Integer.parseInt(value), relation);
                    }

                    @Override
                    protected void addListener(java.beans.PropertyChangeListener qc) {
                        l.addPropertyChangeListener(qc);
                    }
                };
                qa.processModifierElements(e, _varModel);
            }
        } else if (name.equals("group")) {
            // nested "group" elements ...
            newGridGroup(e, c, g, globs, showStdName, modelElem);
        } else if (!name.equals("qualifier")) {
            // its a mistake
            log.error("No code to handle element of type " + e.getName() + " in newColumn");
        }
    }
// add glue to the bottom to allow resize
//         if (c.getComponentCount() > 0) {
//             c.add(Box.createVerticalGlue());
//         }
}
Also used : JPanel(javax.swing.JPanel) VariableValue(jmri.jmrit.symbolicprog.VariableValue) Element(org.jdom2.Element) QualifierAdder(jmri.jmrit.symbolicprog.QualifierAdder)

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