Search in sources :

Example 1 with CvTableModel

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

the class PaneProgPaneTest method testVarListFill.

// test storage of programming info in list
@Test
public void testVarListFill() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // make sure XML document is ready
    setupDoc();
    PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return null;
        }
    };
    CvTableModel cvModel = new CvTableModel(new JLabel(), p);
    IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
    String[] args = { "CV", "Name" };
    VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
    log.debug("VariableTableModel ctor complete");
    // have to add a couple of defined variables
    Element el0 = new Element("variable").setAttribute("CV", "17").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("longAddressVal"));
    log.debug("First element created");
    varModel.setRow(0, el0);
    log.debug("First element loaded");
    Element el1 = new Element("variable").setAttribute("CV", "17").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
    log.debug("Second element created");
    varModel.setRow(1, el1);
    log.debug("Two elements loaded");
    // test by invoking
    PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
    assertEquals("variable list length", 2, pane.varList.size());
    assertEquals("1st variable index ", Integer.valueOf(1), pane.varList.get(0));
    assertEquals("2nd variable index ", Integer.valueOf(0), pane.varList.get(1));
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 2 with CvTableModel

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

the class PaneProgPaneTest method testVariables.

// test specifying variables in columns
@Test
public void testVariables() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    // make sure XML document is ready
    setupDoc();
    PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return null;
        }
    };
    CvTableModel cvModel = new CvTableModel(new JLabel(), p);
    IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
    String[] args = { "CV", "Name" };
    VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
    log.debug("VariableTableModel ctor complete");
    // create test object with special implementation of the newVariable(String) operation
    varCount = 0;
    PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null) {

        @Override
        public void newVariable(Element e, JComponent p, GridBagLayout g, GridBagConstraints c, boolean a) {
            varCount++;
        }
    };
    assertNotNull("exists", pane);
    assertEquals("variable defn count", 7, varCount);
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) GridBagConstraints(java.awt.GridBagConstraints) GridBagLayout(java.awt.GridBagLayout) Element(org.jdom2.Element) JComponent(javax.swing.JComponent) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 3 with CvTableModel

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

the class PaneProgPaneTest method testPaneRead.

// test storage of programming info in list
@Test
public void testPaneRead() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    log.debug("testPaneRead starts");
    // initialize the system
    // make sure XML document is ready
    setupDoc();
    PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return null;
        }
    };
    CvTableModel cvModel = new CvTableModel(new JLabel(), p);
    IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
    String[] args = { "CV", "Name" };
    VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
    log.debug("VariableTableModel ctor complete");
    // have to add a couple of defined variables
    Element el0 = new Element("variable").setAttribute("CV", "2").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
    Element el1 = new Element("variable").setAttribute("CV", "3").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
    varModel.setRow(0, el0);
    varModel.setRow(1, el1);
    PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
    p.resetCv(2, 20);
    p.resetCv(3, 30);
    // test by invoking
    progPane.readAllButton.setSelected(true);
    // wait for reply (normally, done by callback; will check that later)
    JUnitUtil.waitFor(() -> {
        return !progPane.isBusy();
    }, "progPane.isBusy");
    Assert.assertEquals("CV 2 value ", "20", varModel.getValString(0));
    Assert.assertEquals("CV 3 value ", "30", varModel.getValString(1));
    log.debug("testPaneRead ends ok");
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 4 with CvTableModel

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

the class PaneProgPaneTest method testPaneWrite.

@Test
public void testPaneWrite() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    log.debug("testPaneWrite starts");
    // initialize the system
    // make sure XML document is ready
    setupDoc();
    PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return null;
        }
    };
    CvTableModel cvModel = new CvTableModel(new JLabel(), p);
    IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
    String[] args = { "CV", "Name" };
    VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
    log.debug("VariableTableModel ctor complete");
    // have to add a couple of defined variables
    Element el0 = new Element("variable").setAttribute("CV", "2").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("default", "20").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
    Element el1 = new Element("variable").setAttribute("CV", "3").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("default", "30").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
    varModel.setRow(0, el0);
    varModel.setRow(1, el1);
    log.debug("Two elements loaded");
    //        PaneProgPane progPane = new PaneProgPane("name", pane1, cvModel, varModel, null);
    PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
    p.resetCv(2, -1);
    p.resetCv(3, -1);
    // test by invoking
    progPane.writeAllButton.setSelected(true);
    // wait for reply (normally, done by callback; will check that later)
    JUnitUtil.waitFor(() -> {
        return !progPane.isBusy();
    }, "progPane.isBusy");
    Assert.assertEquals("CV 2 value ", 20, p.getCvVal(2));
    Assert.assertEquals("CV 3 value ", 30, p.getCvVal(3));
    log.debug("testPaneWrite ends ok");
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 5 with CvTableModel

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

the class PaneProgPaneTest method testPaneReadOpCount.

// test counting of read operations needed
@Test
public void testPaneReadOpCount() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    log.debug("testPaneReadOpCount starts");
    // initialize the system
    // make sure XML document is ready
    setupDoc();
    PaneProgFrame pFrame = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", p, false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return null;
        }
    };
    CvTableModel cvModel = new CvTableModel(new JLabel(), p);
    IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
    String[] args = { "CV", "Name" };
    VariableTableModel varModel = new VariableTableModel(null, args, cvModel, icvModel);
    // have to add a couple of defined variables
    int row = 0;
    // note these +have+ to be on this pane, e.g. named in setupDoc
    Element el0 = new Element("variable").setAttribute("CV", "1").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Start voltage").addContent(new Element("decVal"));
    varModel.setRow(row++, el0);
    Element el1 = new Element("variable").setAttribute("CV", "1").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Primary Address").addContent(new Element("decVal"));
    varModel.setRow(row++, el1);
    Element el2 = new Element("variable").setAttribute("CV", "67").setAttribute("label", "Normal direction of motion").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").addContent(new Element("speedTableVal"));
    varModel.setRow(row++, el2);
    Element el3 = new Element("variable").setAttribute("CV", "68").setAttribute("readOnly", "no").setAttribute("mask", "VVVVVVVV").setAttribute("label", "Address").addContent(new Element("decVal"));
    varModel.setRow(row++, el3);
    PaneProgPane progPane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null);
    // start actual testing
    Assert.assertEquals("number of all CVs to read ", 29, progPane.countOpsNeeded(true, false));
    Assert.assertEquals("number of all CVs to write ", 29, progPane.countOpsNeeded(false, false));
    Assert.assertEquals("number of changed CVs to read ", 0, progPane.countOpsNeeded(true, true));
    Assert.assertEquals("number of changed CVs to write ", 0, progPane.countOpsNeeded(false, true));
    // mark some as needing to be written
    (cvModel.allCvMap().get("1")).setValue(12);
    Assert.assertEquals("modified all CVs to read ", 29, progPane.countOpsNeeded(true, false));
    Assert.assertEquals("modified all CVs to write ", 29, progPane.countOpsNeeded(false, false));
    Assert.assertEquals("modified changed CVs to read ", 1, progPane.countOpsNeeded(true, true));
    Assert.assertEquals("modified changed CVs to write ", 1, progPane.countOpsNeeded(false, true));
    (cvModel.allCvMap().get("69")).setValue(12);
    // careful - might change more than one CV!
    Assert.assertEquals("spdtbl all CVs to read ", 29, progPane.countOpsNeeded(true, false));
    Assert.assertEquals("spdtbl all CVs to write ", 29, progPane.countOpsNeeded(false, false));
    Assert.assertEquals("spdtbl changed CVs to read ", 2, progPane.countOpsNeeded(true, true));
    Assert.assertEquals("spdtbl changed CVs to write ", 2, progPane.countOpsNeeded(false, true));
    log.debug("testPaneReadOpCount ends ok");
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Aggregations

CvTableModel (jmri.jmrit.symbolicprog.CvTableModel)13 IndexedCvTableModel (jmri.jmrit.symbolicprog.IndexedCvTableModel)13 VariableTableModel (jmri.jmrit.symbolicprog.VariableTableModel)13 JLabel (javax.swing.JLabel)10 RosterEntry (jmri.jmrit.roster.RosterEntry)6 Element (org.jdom2.Element)6 Test (org.junit.Test)6 JPanel (javax.swing.JPanel)2 Programmer (jmri.Programmer)2 BorderLayout (java.awt.BorderLayout)1 GridBagConstraints (java.awt.GridBagConstraints)1 GridBagLayout (java.awt.GridBagLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JButton (javax.swing.JButton)1 JComponent (javax.swing.JComponent)1 TitledBorder (javax.swing.border.TitledBorder)1 jmri (jmri)1 XmlFile (jmri.jmrit.XmlFile)1 ResetTableModel (jmri.jmrit.symbolicprog.ResetTableModel)1