Search in sources :

Example 6 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 7 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 8 with DecoderFile

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

the class PaneProgFrameTest method testFrame.

// show me the specially-created frame
public void testFrame() {
    if (GraphicsEnvironment.isHeadless()) {
        return;
    }
    setupDoc();
    PaneProgFrame p = new PaneProgFrame(null, new RosterEntry(), "test frame", "programmers/Basic.xml", new jmri.progdebugger.ProgDebugger(), false) {

        // dummy implementations
        @Override
        protected JPanel getModePane() {
            return null;
        }
    };
    // ugly, temporary way to load the decoder info
    jmri.jmrit.decoderdefn.DecoderFileTest t = new jmri.jmrit.decoderdefn.DecoderFileTest("");
    t.setupDecoder();
    // used as a temporary
    DecoderFile df = new DecoderFile();
    df.loadVariableModel(t.decoder, p.variableModel);
    p.readConfig(root, new RosterEntry());
    p.pack();
    p.setVisible(true);
    JFrame f = jmri.util.JmriJFrame.getFrame("test frame");
    Assert.assertTrue("found frame", f != null);
    f.dispose();
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) JFrame(javax.swing.JFrame) RosterEntry(jmri.jmrit.roster.RosterEntry)

Example 9 with DecoderFile

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

the class PaneProgDp3Action method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    // NOI18N
    log.debug("Pane programmer requested");
    if (f == null) {
        log.debug("found f==null");
        // create the initial frame that steers
        // NOI18N
        f = new JmriJFrame(apps.gui3.dp3.Bundle.getMessage("FrameProgrammerSetup"));
        f.getContentPane().setLayout(new BorderLayout());
        // ensure status line is cleared on close so it is normal if re-opened
        f.addWindowListener(new WindowAdapter() {

            @Override
            public void windowClosing(WindowEvent we) {
                // NOI18N
                statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle"));
                f.windowClosing(we);
            }
        });
        // add the Roster menu
        JMenuBar menuBar = new JMenuBar();
        // NOI18N
        JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
        // NOI18N
        j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
        // NOI18N
        j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
        menuBar.add(j);
        // NOI18N
        menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
        f.setJMenuBar(menuBar);
        final JPanel bottomPanel = new JPanel(new BorderLayout());
        // new Loco on programming track
        combinedLocoSelTree = new CombinedLocoSelTreePane(statusLabel, modePane) {

            @Override
            protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String progName) {
                // progName is ignored here
                log.debug("startProgrammer");
                String title = // NOI18N
                java.text.MessageFormat.format(// NOI18N
                SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), // NOI18N
                new Object[] { Bundle.getMessage("NewDecoder") });
                if (re != null) {
                    title = // NOI18N
                    java.text.MessageFormat.format(// NOI18N
                    SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { re.getId() });
                }
                JFrame p;
                if (!modePane.isSelected() || modePane.getProgrammer() == null) {
                    p = new PaneProgFrame(decoderFile, re, // NOI18N
                    title, // NOI18N
                    "programmers" + File.separator + "Comprehensive.xml", null, false) {

                        @Override
                        protected JPanel getModePane() {
                            return null;
                        }
                    };
                } else {
                    p = new PaneServiceProgFrame(decoderFile, re, // NOI18N
                    title, // NOI18N
                    "programmers" + File.separator + "Comprehensive.xml", modePane.getProgrammer());
                }
                p.pack();
                p.setVisible(true);
            }

            @Override
            protected void openNewLoco() {
                log.debug("openNewLoco");
                // find the decoderFile object
                DecoderFile decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
                // NOI18N
                log.debug("decoder file: {}", decoderFile.getFilename());
                if (rosterIdField.getText().equals(SymbolicProgBundle.getMessage("LabelNewDecoder"))) {
                    // NOI18N
                    re = new RosterEntry();
                    re.setDecoderFamily(decoderFile.getFamily());
                    re.setDecoderModel(decoderFile.getModel());
                    // NOI18N
                    re.setId(SymbolicProgBundle.getMessage("LabelNewDecoder"));
                    //re.writeFile(cvModel, iCvModel, variableModel );
                    // note that we're leaving the filename null
                    // add the new roster entry to the in-memory roster
                    Roster.getDefault().addEntry(re);
                } else {
                    try {
                        saveRosterEntry();
                    } catch (JmriException ex) {
                        // NOI18N
                        log.warn("Exception while saving roster entry", ex);
                        return;
                    }
                }
                // create a dummy RosterEntry with the decoder info
                // no programmer name in this case
                startProgrammer(decoderFile, re, "");
                //Set our roster entry back to null so that a fresh roster entry can be created if needed
                re = null;
            }

            @Override
            protected JPanel layoutRosterSelection() {
                log.debug("layoutRosterSelection");
                return null;
            }

            @Override
            protected JPanel layoutDecoderSelection() {
                log.debug("layoutDecoderSelection");
                JPanel pan = super.layoutDecoderSelection();
                dTree.removeTreeSelectionListener(dListener);
                dTree.addTreeSelectionListener(dListener = new TreeSelectionListener() {

                    @Override
                    public void valueChanged(TreeSelectionEvent e) {
                        if (!dTree.isSelectionEmpty() && dTree.getSelectionPath() != null && // check that this isn't just a model
                        ((TreeNode) dTree.getSelectionPath().getLastPathComponent()).isLeaf() && // can't be just a mfg, has to be at least a family
                        dTree.getSelectionPath().getPathCount() > 2 && // can't be a multiple decoder selection
                        dTree.getSelectionCount() < 2) {
                            log.debug("Selection event with " + dTree.getSelectionPath().toString());
                            //if (locoBox != null) locoBox.setSelectedIndex(0);
                            go2.setEnabled(true);
                            go2.setRequestFocusEnabled(true);
                            go2.requestFocus();
                            // NOI18N
                            go2.setToolTipText(SymbolicProgBundle.getMessage("TipClickToOpen"));
                            decoderFile = DecoderIndexFile.instance().fileFromTitle(selectedDecoderType());
                            setUpRosterPanel();
                        } else {
                            decoderFile = null;
                            // decoder not selected - require one
                            go2.setEnabled(false);
                            // NOI18N
                            go2.setToolTipText(SymbolicProgBundle.getMessage("TipSelectLoco"));
                            setUpRosterPanel();
                        }
                    }
                });
                return pan;
            }

            @Override
            protected void selectDecoder(int mfgID, int modelID, int productID) {
                log.debug("selectDecoder");
                //On selecting a new decoder start a fresh with a new roster entry
                super.selectDecoder(mfgID, modelID, productID);
                findDecoderAddress();
            }

            @Override
            protected JPanel createProgrammerSelection() {
                log.debug("createProgrammerSelection");
                JPanel pane3a = new JPanel();
                pane3a.setLayout(new BoxLayout(pane3a, BoxLayout.Y_AXIS));
                // NOI18N
                go2 = new JButton(Bundle.getMessage("OpenProgrammer"));
                go2.addActionListener(new ActionListener() {

                    @Override
                    public void actionPerformed(java.awt.event.ActionEvent e) {
                        // NOI18N
                        log.debug("Open programmer pressed");
                        openButton();
                        // close this window to prevent having
                        // two windows processing at the same time
                        //
                        // Alternately, could have just cleared out a 
                        // bunch of stuff to force starting over, but 
                        // that seems to be an even more confusing
                        // user experience.
                        log.debug("Closing f {}", f);
                        WindowEvent wev = new WindowEvent(f, WindowEvent.WINDOW_CLOSING);
                        java.awt.Toolkit.getDefaultToolkit().getSystemEventQueue().postEvent(wev);
                    }
                });
                go2.setAlignmentX(JLabel.RIGHT_ALIGNMENT);
                go2.setEnabled(false);
                // NOI18N
                go2.setToolTipText(SymbolicProgBundle.getMessage("TipSelectLoco"));
                bottomPanel.add(go2, BorderLayout.EAST);
                return pane3a;
            }
        };
        // load primary frame
        JPanel topPanel = new JPanel();
        topPanel.add(modePane);
        topPanel.add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
        f.getContentPane().add(topPanel, BorderLayout.NORTH);
        //f.getContentPane().add(modePane);
        //f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
        combinedLocoSelTree.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        f.getContentPane().add(combinedLocoSelTree, BorderLayout.CENTER);
        //f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
        //basicRoster.setEnabled(false);
        statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
        bottomPanel.add(statusLabel, BorderLayout.SOUTH);
        f.getContentPane().add(bottomPanel, BorderLayout.SOUTH);
        f.pack();
        // NOI18N
        log.debug("Tab-Programmer setup created");
    } else {
        re = null;
        combinedLocoSelTree.resetSelections();
    }
    f.setVisible(true);
}
Also used : JPanel(javax.swing.JPanel) DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) PaneProgFrame(jmri.jmrit.symbolicprog.tabbedframe.PaneProgFrame) ActionEvent(java.awt.event.ActionEvent) BoxLayout(javax.swing.BoxLayout) JButton(javax.swing.JButton) WindowAdapter(java.awt.event.WindowAdapter) TreeSelectionListener(javax.swing.event.TreeSelectionListener) jmri(jmri) JSeparator(javax.swing.JSeparator) BorderLayout(java.awt.BorderLayout) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) TreeNode(javax.swing.tree.TreeNode) PaneServiceProgFrame(jmri.jmrit.symbolicprog.tabbedframe.PaneServiceProgFrame) CombinedLocoSelTreePane(jmri.jmrit.symbolicprog.CombinedLocoSelTreePane) ActionListener(java.awt.event.ActionListener) JmriJFrame(jmri.util.JmriJFrame) WindowEvent(java.awt.event.WindowEvent) RosterEntry(jmri.jmrit.roster.RosterEntry) TreeSelectionEvent(javax.swing.event.TreeSelectionEvent) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 10 with DecoderFile

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

the class RosterFrame method selectLoco.

/**
     * Identify locomotive complete, act on it by setting the GUI. This will
     * fire "GUI changed" events which will reset the decoder GUI.
     *
     * @param dccAddress address of locomotive
     * @param isLong     true if address is long; false if short
     * @param mfgId      manufacturer id as in decoder
     * @param modelId    model id as in decoder
     */
protected void selectLoco(int dccAddress, boolean isLong, int mfgId, int modelId) {
    // raise the button again
    // idloco.setSelected(false);
    // locate that loco
    inStartProgrammer = false;
    if (re != null) {
        //We remove the propertychangelistener if we had a previoulsy selected entry;
        re.removePropertyChangeListener(rosterEntryUpdateListener);
    }
    List<RosterEntry> l = Roster.getDefault().matchingList(null, null, Integer.toString(dccAddress), null, null, null, null);
    if (log.isDebugEnabled()) {
        log.debug("selectLoco found " + l.size() + " matches");
    }
    if (l.size() > 0) {
        if (l.size() > 1) {
            //More than one possible loco, so check long flag
            List<RosterEntry> l2 = new ArrayList<>();
            for (RosterEntry _re : l) {
                if (_re.isLongAddress() == isLong) {
                    l2.add(_re);
                }
            }
            if (l2.size() == 1) {
                re = l2.get(0);
            } else {
                if (l2.isEmpty()) {
                    l2 = l;
                }
                //Still more than one possible loco, so check against the decoder family
                List<RosterEntry> l3 = new ArrayList<>();
                List<DecoderFile> temp = DecoderIndexFile.instance().matchingDecoderList(null, null, "" + mfgId, "" + modelId, null, null);
                ArrayList<String> decoderFam = new ArrayList<>();
                for (DecoderFile f : temp) {
                    if (!decoderFam.contains(f.getModel())) {
                        decoderFam.add(f.getModel());
                    }
                }
                for (RosterEntry _re : l2) {
                    if (decoderFam.contains(_re.getDecoderModel())) {
                        l3.add(_re);
                    }
                }
                if (l3.isEmpty()) {
                    //Unable to determine the loco against the manufacture therefore will be unable to further identify against decoder.
                    re = l2.get(0);
                } else {
                    //We have no other options to match against so will return the first one we come across;
                    re = l3.get(0);
                }
            }
        } else {
            re = l.get(0);
        }
        re.addPropertyChangeListener(rosterEntryUpdateListener);
        rtable.setSelection(re);
        updateDetails();
        rtable.moveTableViewToSelected();
    } else {
        //"No roster entry found"
        log.warn("Read address " + dccAddress + ", but no such loco in roster");
        JOptionPane.showMessageDialog(this, "No roster entry found", "Address " + dccAddress + " was read from the decoder\nbut has not been found in the Roster", JOptionPane.INFORMATION_MESSAGE);
    }
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) ArrayList(java.util.ArrayList) PrintRosterEntry(jmri.jmrit.roster.PrintRosterEntry) RosterEntry(jmri.jmrit.roster.RosterEntry)

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