Search in sources :

Example 11 with IndexedCvTableModel

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

the class PaneProgDp3Action method setUpRosterPanel.

synchronized void setUpRosterPanel() {
    re = null;
    if (rosterPanel == null) {
        rosterPanel = new JPanel();
        rosterPanel.setLayout(new BorderLayout());
        JPanel p = new JPanel();
        // NOI18N
        p.add(new JLabel(Bundle.getMessage("RosterId")));
        p.add(rosterIdField);
        rosterPanel.add(p, BorderLayout.NORTH);
        // NOI18N
        rosterIdField.setText(SymbolicProgBundle.getMessage("LabelNewDecoder"));
        // NOI18N
        saveBasicRoster = new JButton(Bundle.getMessage("Save"));
        saveBasicRoster.addActionListener(new ActionListener() {

            @Override
            public void actionPerformed(java.awt.event.ActionEvent e) {
                try {
                    log.debug("saveBasicRoster button pressed, calls saveRosterEntry");
                    saveRosterEntry();
                } catch (JmriException ex) {
                    return;
                }
            }
        });
        TitledBorder border = BorderFactory.createTitledBorder(BorderFactory.createLineBorder(Color.black));
        // NOI18N
        border.setTitle(Bundle.getMessage("CreateBasicRosterEntry"));
        rosterPanel.setBorder(border);
        rosterPanel.setVisible(false);
        f.getContentPane().add(rosterPanel, BorderLayout.EAST);
    } else {
        // NOI18N
        rosterIdField.setText(SymbolicProgBundle.getMessage("LabelNewDecoder"));
    }
    if (progPane != null) {
        progPane.dispose();
        rosterPanel.remove(progPane);
        progPane = null;
        rosterPanel.revalidate();
        f.getContentPane().repaint();
        f.repaint();
        f.pack();
    }
    if (jmri.InstanceManager.getNullableDefault(jmri.ProgrammerManager.class) != null && jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).isGlobalProgrammerAvailable()) {
        this.mProgrammer = jmri.InstanceManager.getDefault(jmri.ProgrammerManager.class).getGlobalProgrammer();
    }
    cvModel = new CvTableModel(statusLabel, mProgrammer);
    iCvModel = new IndexedCvTableModel(statusLabel, mProgrammer);
    variableModel = new VariableTableModel(statusLabel, new String[] { "Name", "Value" }, cvModel, iCvModel);
    if (decoderFile != null) {
        Element decoderRoot = null;
        try {
            decoderRoot = decoderFile.rootFromName(DecoderFile.fileLocation + decoderFile.getFilename());
        } catch (JDOMException | IOException e) {
            log.error("Exception while loading decoder XML file: " + decoderFile.getFilename(), e);
            return;
        }
        // NOI18N
        modelElem = decoderFile.getModelElement();
        // NOI18N
        decoderFile.loadVariableModel(decoderRoot.getChild("decoder"), variableModel);
        rosterPanel.setVisible(true);
    } else {
        rosterPanel.setVisible(false);
        return;
    }
    Element programmerRoot;
    XmlFile pf = new XmlFile() {
    };
    // XmlFile is abstract
    java.beans.PropertyChangeListener dccNews = new java.beans.PropertyChangeListener() {

        @Override
        public void propertyChange(java.beans.PropertyChangeEvent e) {
            updateDccAddress();
        }
    };
    // NOI18N
    primaryAddr = variableModel.findVar("Short Address");
    if (primaryAddr == null) {
        // NOI18N
        log.debug("DCC Address monitor didnt find a Short Address variable");
    } else {
        primaryAddr.addPropertyChangeListener(dccNews);
    }
    // NOI18N
    extendAddr = variableModel.findVar("Long Address");
    if (extendAddr == null) {
        // NOI18N
        log.debug("DCC Address monitor didnt find an Long Address variable");
    } else {
        extendAddr.addPropertyChangeListener(dccNews);
    }
    // NOI18N
    addMode = (EnumVariableValue) variableModel.findVar("Address Format");
    if (addMode == null) {
        // NOI18N
        log.debug("DCC Address monitor didnt find an Address Format variable");
    } else {
        addMode.addPropertyChangeListener(dccNews);
    }
    try {
        // NOI18N
        programmerRoot = pf.rootFromName("programmers" + File.separator + "Basic.xml");
        Element base;
        if ((base = programmerRoot.getChild("programmer")) == null) {
            // NOI18N
            // NOI18N
            log.error("xml file top element is not programmer");
            return;
        }
        // for all "pane" elements in the programmer
        // NOI18N
        List<Element> paneList = base.getChildren("pane");
        // NOI18N
        log.debug("will process {} pane definitions", paneList.size());
        String name = jmri.util.jdom.LocaleSelector.getAttribute(paneList.get(0), "name");
        progPane = new ThisProgPane(this, name, paneList.get(0), cvModel, iCvModel, variableModel, modelElem);
        // NOI18N
        progPane.setVariableValue("Short Address", cv1);
        // NOI18N
        progPane.setVariableValue("Long Address", longAddress);
        // NOI18N
        progPane.setCVValue("29", cv29);
        // NOI18N
        progPane.setCVValue("19", cv19);
        rosterPanel.add(progPane, BorderLayout.CENTER);
        rosterPanel.revalidate();
        rosterPanel.setVisible(true);
        f.getContentPane().repaint();
        f.repaint();
        f.pack();
        return;
    } catch (JDOMException | IOException e) {
        // NOI18N
        log.error("exception reading programmer file: ", e);
    }
}
Also used : JPanel(javax.swing.JPanel) JButton(javax.swing.JButton) jmri(jmri) TitledBorder(javax.swing.border.TitledBorder) BorderLayout(java.awt.BorderLayout) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) XmlFile(jmri.jmrit.XmlFile) JLabel(javax.swing.JLabel) ActionEvent(java.awt.event.ActionEvent) ActionListener(java.awt.event.ActionListener) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

Example 12 with IndexedCvTableModel

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

the class DecoderFileTest method testMinOut.

public void testMinOut() {
    setupDecoder();
    // this test should probably be done in terms of a test class instead of the real one...
    JLabel progStatus = new JLabel(" OK ");
    CvTableModel cvModel = new CvTableModel(progStatus, p);
    IndexedCvTableModel icvModel = new IndexedCvTableModel(new JLabel(), p);
    VariableTableModel variableModel = new VariableTableModel(progStatus, new String[] { "Name", "Value" }, cvModel, icvModel);
    DecoderFile d = new DecoderFile("mfg", "mfgID", "model", "23", "24", "family", "filename", 16, 3, null);
    d.loadVariableModel(decoder, variableModel);
    Assert.assertEquals("read rows ", 2, variableModel.getRowCount());
}
Also used : IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) JLabel(javax.swing.JLabel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

Example 13 with IndexedCvTableModel

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

the class EcosLocoToRoster method SelectedDecoder.

private void SelectedDecoder(DecoderFile pDecoderFile) {
    //pDecoderFile=DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
    re.setDecoderModel(pDecoderFile.getModel());
    re.setDecoderFamily(pDecoderFile.getFamily());
    re.setDccAddress(Integer.toString(ecosLoco.getNumber()));
    //re.setLongAddress(true);
    re.setRoadName("");
    re.setRoadNumber("");
    re.setMfg("");
    re.setModel("");
    re.setOwner(InstanceManager.getDefault(RosterConfigManager.class).getDefaultOwner());
    re.setComment("Automatically Imported from the Ecos");
    re.setDecoderComment("");
    re.putAttribute(adaptermemo.getPreferenceManager().getRosterAttribute(), _ecosObject);
    re.ensureFilenameExists();
    if ((ecosLoco.getECOSProtocol().startsWith("DCC"))) {
        if (ecosLoco.getNumber() <= 127) {
            re.setProtocol(jmri.LocoAddress.Protocol.DCC_SHORT);
        } else {
            re.setProtocol(jmri.LocoAddress.Protocol.DCC_LONG);
        }
    } else if (ecosLoco.getECOSProtocol().equals("MMFKT") || ecosLoco.getECOSProtocol().equals("MFX")) {
        re.setProtocol(jmri.LocoAddress.Protocol.MFX);
    } else if (ecosLoco.getECOSProtocol().startsWith("MM")) {
        re.setProtocol(jmri.LocoAddress.Protocol.MOTOROLA);
    } else if (ecosLoco.getECOSProtocol().equals("SX32")) {
        re.setProtocol(jmri.LocoAddress.Protocol.SELECTRIX);
    }
    mProgrammer = null;
    cvModel = new CvTableModel(progStatus, mProgrammer);
    iCvModel = new IndexedCvTableModel(progStatus, mProgrammer);
    variableModel = new VariableTableModel(progStatus, new String[] { "CV", "Value" }, cvModel, iCvModel);
    resetModel = new ResetTableModel(progStatus, mProgrammer);
    storeloco();
    filename = "programmers" + File.separator + "Basic.xml";
    loadProgrammerFile(re);
    loadDecoderFile(pDecoderFile, re);
    variableModel.findVar("Speed Step Mode").setIntValue(0);
    if (ecosLoco.getECOSProtocol().equals("DCC128")) {
        variableModel.findVar("Speed Step Mode").setIntValue(1);
    }
    re.writeFile(cvModel, iCvModel, variableModel);
    getFunctionDetails(0);
    JOptionPane.showMessageDialog(frame, "Loco Added to the JMRI Roster");
    waitingForComplete = true;
}
Also used : CvTableModel(jmri.jmrit.symbolicprog.CvTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel) VariableTableModel(jmri.jmrit.symbolicprog.VariableTableModel) ResetTableModel(jmri.jmrit.symbolicprog.ResetTableModel) IndexedCvTableModel(jmri.jmrit.symbolicprog.IndexedCvTableModel)

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