Search in sources :

Example 1 with DecoderFile

use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.

the class UpdateDecoderDefinitionAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    List<RosterEntry> list = Roster.getDefault().matchingList(null, null, null, null, null, null, null);
    for (RosterEntry entry : list) {
        String family = entry.getDecoderFamily();
        String model = entry.getDecoderModel();
        // check if replaced
        List<DecoderFile> decoders = DecoderIndexFile.instance().matchingDecoderList(null, family, null, null, null, model);
        log.info("Found " + decoders.size() + " decoders matching family \"" + family + "\" model \"" + model + "\" from roster entry \"" + entry.getId() + "\"");
        String replacementFamily = null;
        String replacementModel = null;
        for (DecoderFile decoder : decoders) {
            if (decoder.getReplacementFamily() != null || decoder.getReplacementModel() != null) {
                log.info("   Recommended replacement is family \"" + decoder.getReplacementFamily() + "\" model \"" + decoder.getReplacementModel() + "\"");
            }
            replacementFamily = decoder.getReplacementFamily();
            replacementModel = decoder.getReplacementModel();
        }
        if (replacementModel != null || replacementFamily != null) {
            // change the roster entry
            if (replacementFamily != null) {
                log.info("   *** Will update. replacementFamily='{}'", replacementFamily);
                entry.setDecoderFamily(replacementFamily);
            }
            if (replacementModel != null) {
                log.info("   *** Will update. replacementModel='{}'", replacementModel);
                entry.setDecoderModel(replacementModel);
            }
            // write it out (not bothering to do backup?)
            entry.updateFile();
        }
    }
    // write updated roster
    Roster.getDefault().makeBackupFile(Roster.getDefault().getRosterIndexPath());
    try {
        Roster.getDefault().writeFile(Roster.getDefault().getRosterIndexPath());
    } catch (IOException ex) {
        log.error("Exception while writing the new roster file, may not be complete: " + ex);
    }
    // use the new one
    Roster.getDefault().reloadRosterFile();
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) IOException(java.io.IOException)

Example 2 with DecoderFile

use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.

the class CombinedLocoSelPane method openNewLoco.

/**
     * Start with a decoder selected, so we're going to create a new
     * RosterEntry.
     */
protected void openNewLoco() {
    // find the decoderFile object
    DecoderFile decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
    if (log.isDebugEnabled()) {
        log.debug("decoder file: " + decoderFile.getFilename());
    }
    // create a dummy RosterEntry with the decoder info
    RosterEntry re = new RosterEntry();
    re.setDecoderFamily(decoderFile.getFamily());
    re.setDecoderModel(decoderFile.getModel());
    re.setId(Bundle.getMessage("LabelNewDecoder"));
    // note that we're leaving the filename null
    // add the new roster entry to the in-memory roster
    Roster.getDefault().addEntry(re);
    startProgrammer(decoderFile, re, (String) programmerBox.getSelectedItem());
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 3 with DecoderFile

use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.

the class CombinedLocoSelTreePane method updateForDecoderTypeID.

/**
     * Decoder identify has matched one or more specific types
     */
@Override
void updateForDecoderTypeID(List<DecoderFile> pList) {
    // find and select the first item
    if (log.isDebugEnabled()) {
        StringBuffer buf = new StringBuffer("Identified " + pList.size() + " matches: ");
        for (int i = 0; i < pList.size(); i++) {
            buf.append(pList.get(i).getModel() + ":");
        }
        log.debug(buf.toString());
    }
    if (pList.size() <= 0) {
        log.error("Found empty list in updateForDecoderTypeID, should not happen");
        return;
    }
    dTree.clearSelection();
    // and issue a warning instruction in the status bar
    if (pList.size() > 1) {
        dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.DISCONTIGUOUS_TREE_SELECTION);
        _statusLabel.setText(Bundle.getMessage("StateMultipleMatch"));
    } else {
        dTree.getSelectionModel().setSelectionMode(DefaultTreeSelectionModel.SINGLE_TREE_SELECTION);
    }
    // set everybody not identified 
    Enumeration<DecoderTreeNode> e = dRoot.breadthFirstEnumeration();
    while (e.hasMoreElements()) {
        // loop over the tree
        DecoderTreeNode node = e.nextElement();
        node.setIdentified(false);
    }
    selectedPath = new ArrayList<TreePath>();
    // Find decoder nodes in tree and set selected
    for (int i = 0; i < pList.size(); i++) {
        // loop over selected decoders
        e = dRoot.breadthFirstEnumeration();
        DecoderFile f = pList.get(i);
        String findMfg = f.getMfg();
        String findFamily = f.getFamily();
        String findModel = f.getModel();
        while (e.hasMoreElements()) {
            // loop over the tree & find node
            DecoderTreeNode node = e.nextElement();
            // never match show=NO nodes
            if (node.getShowable() == DecoderFile.Showable.NO) {
                continue;
            }
            // convert path to comparison string
            TreeNode[] list = node.getPath();
            if (list.length == 3) {
                // check for match to mfg, model (as family)
                if (list[1].toString().equals(findMfg) && list[2].toString().equals(findModel)) {
                    log.debug("match length 3");
                    node.setIdentified(true);
                    dModel.reload();
                    ((DecoderTreeNode) list[1]).setIdentified(true);
                    ((DecoderTreeNode) list[2]).setIdentified(true);
                    TreePath path = new TreePath(node.getPath());
                    selectedPath.add(path);
                    break;
                }
            } else if (list.length == 4) {
                // check for match to mfg, family, model
                if (list[1].toString().equals(findMfg) && list[2].toString().equals(findFamily) && list[3].toString().equals(findModel)) {
                    log.debug("match length 4");
                    node.setIdentified(true);
                    dModel.reload();
                    ((DecoderTreeNode) list[1]).setIdentified(true);
                    ((DecoderTreeNode) list[2]).setIdentified(true);
                    ((DecoderTreeNode) list[3]).setIdentified(true);
                    TreePath path = new TreePath(node.getPath());
                    selectedPath.add(path);
                    break;
                }
            }
        }
    }
    // now select and show paths in tree
    for (TreePath path : selectedPath) {
        dTree.addSelectionPath(path);
        dTree.expandPath(path);
        dTree.scrollPathToVisible(path);
    }
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) TreePath(javax.swing.tree.TreePath) TreeNode(javax.swing.tree.TreeNode) DefaultMutableTreeNode(javax.swing.tree.DefaultMutableTreeNode)

Example 4 with DecoderFile

use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.

the class NewLocoSelPane method matchDecoderToLoco.

private void matchDecoderToLoco() {
    if (((String) locoBox.getSelectedItem()).equals("<none>")) {
        return;
    }
    RosterEntry r = Roster.getDefault().entryFromTitle((String) locoBox.getSelectedItem());
    String decoderModel = r.getDecoderModel();
    String decoderFamily = r.getDecoderFamily();
    if (log.isDebugEnabled()) {
        log.debug("selected loco uses decoder " + decoderFamily + " " + decoderModel);
    }
    // locate a decoder like that.
    List<DecoderFile> l = DecoderIndexFile.instance().matchingDecoderList(null, decoderFamily, null, null, null, decoderModel);
    if (log.isDebugEnabled()) {
        log.debug("found " + l.size() + " matches");
    }
    if (l.size() > 0) {
        DecoderFile d = l.get(0);
        String title = d.titleString();
        if (log.isDebugEnabled()) {
            log.debug("Decoder file title " + title);
        }
        for (int i = 0; i < decoderBox.getItemCount(); i++) {
            if (title.equals(decoderBox.getItemAt(i))) {
                decoderBox.setSelectedIndex(i);
            }
        }
    } else {
        log.warn("Loco uses " + decoderFamily + " " + decoderModel + " decoder, but no such decoder defined");
    }
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 5 with DecoderFile

use of jmri.jmrit.decoderdefn.DecoderFile in project JMRI by JMRI.

the class PaneEditAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (log.isDebugEnabled()) {
        log.debug("Pane programmer requested");
    }
    // create the initial frame that steers
    final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameEditEntrySetup"));
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    // add the Roster menu
    JMenuBar menuBar = new JMenuBar();
    // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
    menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
    f.setJMenuBar(menuBar);
    // known entry, no programmer
    JPanel pane1 = new // not programming
    KnownLocoSelPane(// not programming
    false) {

        @Override
        protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
            String title = SymbolicProgBundle.getMessage("FrameEditEntryTitle");
            JFrame p = new PaneProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", null, false) {

                @Override
                protected JPanel getModePane() {
                    return null;
                }
            };
            p.pack();
            p.setVisible(true);
        }
    };
    // load primary frame
    pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(pane1);
    f.pack();
    if (log.isDebugEnabled()) {
        log.debug("Tab-Programmer setup created");
    }
    f.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) BoxLayout(javax.swing.BoxLayout) KnownLocoSelPane(jmri.jmrit.symbolicprog.KnownLocoSelPane) JmriJFrame(jmri.util.JmriJFrame) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) RosterEntry(jmri.jmrit.roster.RosterEntry) JMenuBar(javax.swing.JMenuBar)

Aggregations

DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)21 RosterEntry (jmri.jmrit.roster.RosterEntry)12 JFrame (javax.swing.JFrame)8 BoxLayout (javax.swing.BoxLayout)7 JPanel (javax.swing.JPanel)7 JMenuBar (javax.swing.JMenuBar)6 JmriJFrame (jmri.util.JmriJFrame)5 JMenu (javax.swing.JMenu)3 DefaultMutableTreeNode (javax.swing.tree.DefaultMutableTreeNode)3 TreeNode (javax.swing.tree.TreeNode)3 TreePath (javax.swing.tree.TreePath)3 KnownLocoSelPane (jmri.jmrit.symbolicprog.KnownLocoSelPane)3 WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 JSeparator (javax.swing.JSeparator)2 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)2 TreeSelectionListener (javax.swing.event.TreeSelectionListener)2 Programmer (jmri.Programmer)2 CombinedLocoSelTreePane (jmri.jmrit.symbolicprog.CombinedLocoSelTreePane)2 BorderLayout (java.awt.BorderLayout)1