Search in sources :

Example 6 with RosterEntry

use of jmri.jmrit.roster.RosterEntry 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 7 with RosterEntry

use of jmri.jmrit.roster.RosterEntry 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)

Example 8 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class PaneProgPaneTest method testColumn.

// test creating columns in a pane
@Test
public void testColumn() {
    Assume.assumeFalse(GraphicsEnvironment.isHeadless());
    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);
    log.debug("CvTableModel ctor complete");
    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 newColumn(String) operation
    colCount = 0;
    PaneProgPane pane = new PaneProgPane(pFrame, "name", pane1, cvModel, icvModel, varModel, null, null) {

        @Override
        public JPanel newColumn(Element e, boolean a, Element el) {
            colCount++;
            return new JPanel();
        }
    };
    assertNotNull("exists", pane);
    assertEquals("column count", 2, colCount);
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) JPanel(javax.swing.JPanel) Element(org.jdom2.Element) JLabel(javax.swing.JLabel) RosterEntry(jmri.jmrit.roster.RosterEntry) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) Test(org.junit.Test)

Example 9 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class PaneProgFrameTest method testPane.

// test creating a pane in config file
public void testPane() {
    if (GraphicsEnvironment.isHeadless()) {
        return;
    }
    setupDoc();
    // create test object
    result = null;
    PaneProgFrame p = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", new jmri.progdebugger.ProgDebugger(), false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return new JPanel();
        }
    };
    // invoke
    result = null;
    p.readConfig(root, new RosterEntry());
    Assert.assertEquals("paneList length ", 4, p.paneList.size());
    // three panes in root, plus roster entry pane
    JFrame f = jmri.util.JmriJFrame.getFrame("test frame");
    Assert.assertTrue("found frame", f != null);
    f.dispose();
}
Also used : JPanel(javax.swing.JPanel) JFrame(javax.swing.JFrame) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 10 with RosterEntry

use of jmri.jmrit.roster.RosterEntry in project JMRI by JMRI.

the class DispatcherFrame method loadAtStartup.

public void loadAtStartup() {
    log.debug("Loading saved trains flagged as LoadAtStartup");
    TrainInfoFile tif = new TrainInfoFile();
    String[] names = tif.getTrainInfoFileNames();
    boolean pathsInited = false;
    if (names.length > 0) {
        for (int i = 0; i < names.length; i++) {
            //read xml data from selected filename and move it into the new train dialog box 
            TrainInfo info = null;
            try {
                info = tif.readTrainInfo(names[i]);
            } catch (java.io.IOException ioe) {
                log.error("IO Exception when reading train info file {}: {}", names[i], ioe);
            } catch (org.jdom2.JDOMException jde) {
                log.error("JDOM Exception when reading train info file {}: {}", names[i], jde);
            }
            if (info != null && info.getLoadAtStartup()) {
                log.debug("restoring train:{}, startblockname:{}, destinationBlockName:{}", info.getTrainName(), info.getStartBlockName(), info.getDestinationBlockName());
                // create a new Active Train
                int tSource = ActiveTrain.ROSTER;
                if (info.getTrainFromTrains()) {
                    tSource = ActiveTrain.OPERATIONS;
                } else if (info.getTrainFromUser()) {
                    tSource = ActiveTrain.USER;
                }
                //block and seq are stored together, split out for use here
                String startBlock = info.getStartBlockName().split("-")[0];
                int startBlockSeq = Integer.parseInt(info.getStartBlockName().split("-")[1]);
                String destinationBlock = info.getDestinationBlockName().split("-")[0];
                int destinationBlockSeq = Integer.parseInt(info.getDestinationBlockName().split("-")[1]);
                if (!pathsInited) {
                    //only init the layoutblockpaths once here
                    //TODO: figure out how to prevent the "regular" init
                    log.debug("initializing block paths early");
                    InstanceManager.getDefault(jmri.jmrit.display.layoutEditor.LayoutBlockManager.class).initializeLayoutBlockPaths();
                }
                ActiveTrain at = createActiveTrain(info.getTransitName(), info.getTrainName(), tSource, startBlock, startBlockSeq, destinationBlock, destinationBlockSeq, info.getAutoRun(), info.getDCCAddress(), info.getPriority(), info.getResetWhenDone(), info.getReverseAtEnd(), info.getAllocateAllTheWay(), true, null);
                if (at != null) {
                    if (tSource == ActiveTrain.ROSTER) {
                        RosterEntry re = Roster.getDefault().getEntryForId(info.getTrainName());
                        at.setRosterEntry(re);
                        at.setDccAddress(re.getDccAddress());
                    }
                    //this is a code: NODELAY, TIMEDDELAY, SENSORDELAY
                    at.setDelayedStart(info.getDelayedStart());
                    // hour of day (fast-clock) to start this train
                    at.setDepartureTimeHr(info.getDepartureTimeHr());
                    //minute of hour to start this train
                    at.setDepartureTimeMin(info.getDepartureTimeMin());
                    //this is a code: NODELAY, TIMEDDELAY, SENSORDELAY
                    at.setDelayedReStart(info.getDelayedRestart());
                    //this is number of minutes to delay between runs
                    at.setRestartDelay(info.getRestartDelayMin());
                    at.setDelaySensor(info.getDelaySensor());
                    if ((isFastClockTimeGE(at.getDepartureTimeHr(), at.getDepartureTimeMin()) && info.getDelayedStart() != ActiveTrain.SENSORDELAY) || info.getDelayedStart() == ActiveTrain.NODELAY) {
                        at.setStarted();
                    }
                    at.setRestartSensor(info.getRestartSensor());
                    at.setTrainType(info.getTrainType());
                    at.setTerminateWhenDone(info.getTerminateWhenDone());
                    if (info.getAutoRun()) {
                        AutoActiveTrain aat = new AutoActiveTrain(at);
                        aat.setSpeedFactor(info.getSpeedFactor());
                        aat.setMaxSpeed(info.getMaxSpeed());
                        aat.setRampRate(AutoActiveTrain.getRampRateFromName(info.getRampRate()));
                        aat.setResistanceWheels(info.getResistanceWheels());
                        aat.setRunInReverse(info.getRunInReverse());
                        aat.setSoundDecoder(info.getSoundDecoder());
                        aat.setMaxTrainLength(info.getMaxTrainLength());
                        if (!aat.initialize()) {
                            log.error("ERROR initializing autorunning for train {}", at.getTrainName());
                            JOptionPane.showMessageDialog(dispatcherFrame, Bundle.getMessage("Error27", at.getTrainName()), Bundle.getMessage("InformationTitle"), JOptionPane.INFORMATION_MESSAGE);
                        }
                        getAutoTrainsFrame().addAutoActiveTrain(aat);
                    }
                    allocateNewActiveTrain(at);
                    newTrainDone(at);
                } else {
                    log.warn("failed to create create Active Train {}", info.getTrainName());
                }
            }
        }
    }
}
Also used : EntryPoint(jmri.EntryPoint) RosterEntry(jmri.jmrit.roster.RosterEntry)

Aggregations

RosterEntry (jmri.jmrit.roster.RosterEntry)77 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)12 JPanel (javax.swing.JPanel)11 Element (org.jdom2.Element)11 JFrame (javax.swing.JFrame)9 BoxLayout (javax.swing.BoxLayout)8 JLabel (javax.swing.JLabel)8 Test (org.junit.Test)7 ActionEvent (java.awt.event.ActionEvent)6 ActionListener (java.awt.event.ActionListener)6 JMenuBar (javax.swing.JMenuBar)6 CvTableModel (jmri.jmrit.symbolicprog.CvTableModel)6 IndexedCvTableModel (jmri.jmrit.symbolicprog.IndexedCvTableModel)6 VariableTableModel (jmri.jmrit.symbolicprog.VariableTableModel)6 ArrayList (java.util.ArrayList)5 JmriJFrame (jmri.util.JmriJFrame)5 File (java.io.File)4 JButton (javax.swing.JButton)3 JMenu (javax.swing.JMenu)3 NamedIcon (jmri.jmrit.catalog.NamedIcon)3