Search in sources :

Example 11 with DecoderFile

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

the class CombinedLocoSelTreePane method createDecoderTypeContents.

/**
     * Reads the available decoders and loads them into the dModel tree model.
     */
void createDecoderTypeContents() {
    List<DecoderFile> decoders = DecoderIndexFile.instance().matchingDecoderList(null, null, null, null, null, null);
    int len = decoders.size();
    DecoderTreeNode mfgElement = null;
    DecoderTreeNode familyElement = null;
    HashMap<String, DecoderTreeNode> familyNameNode = new HashMap<String, DecoderTreeNode>();
    for (int i = 0; i < len; i++) {
        DecoderFile decoder = decoders.get(i);
        String mfg = decoder.getMfg();
        String family = decoder.getFamily();
        String model = decoder.getModel();
        log.debug(" process " + mfg + "/" + family + "/" + model + " on nodes " + (mfgElement == null ? "<null>" : mfgElement.toString() + "(" + mfgElement.getChildCount() + ")") + "/" + (familyElement == null ? "<null>" : familyElement.toString() + "(" + familyElement.getChildCount() + ")"));
        // build elements
        if (mfgElement == null || !mfg.equals(mfgElement.toString())) {
            // need new mfg node
            mfgElement = new DecoderTreeNode(mfg, "CV8 = " + DecoderIndexFile.instance().mfgIdFromName(mfg), "");
            dModel.insertNodeInto(mfgElement, dRoot, dRoot.getChildCount());
            familyNameNode = new HashMap<String, DecoderTreeNode>();
            familyElement = null;
        }
        String famComment = decoders.get(i).getFamilyComment();
        String verString = decoders.get(i).getVersionsAsString();
        if (familyElement == null || (!family.equals(familyElement.toString()) && !familyNameNode.containsKey(family))) {
            // appears to have decoder names separate from the family name
            if ((i + 2 >= len) || decoders.get(i + 2).getFamily().equals(family) || !decoders.get(i + 1).getModel().equals(family)) {
                // normal here; insert the new family element & exit
                log.debug("normal family update case: " + family);
                familyElement = new DecoderTreeNode(family, getHoverText(verString, famComment), decoders.get(i).titleString());
                dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
                familyNameNode.put(family, familyElement);
                continue;
            } else {
                // this is short case; insert decoder entry (next) here
                log.debug("short case, i=" + i + " family=" + family + " next " + decoders.get(i + 1).getModel());
                if (i + 1 > len) {
                    log.error("Unexpected single entry for family: " + family);
                }
                family = decoders.get(i + 1).getModel();
                familyElement = new DecoderTreeNode(family, getHoverText(verString, famComment), decoders.get(i).titleString());
                dModel.insertNodeInto(familyElement, mfgElement, mfgElement.getChildCount());
                familyNameNode.put(family, familyElement);
                i = i + 1;
                continue;
            }
        }
        // insert at the decoder level, except if family name is the same
        if (!family.equals(model)) {
            if (familyNameNode.containsKey(family)) {
                familyElement = familyNameNode.get(family);
            }
            String modelComment = decoders.get(i).getModelComment();
            DecoderTreeNode decoderNameNode = new DecoderTreeNode(model, getHoverText(verString, modelComment), decoders.get(i).titleString());
            decoderNameNode.setShowable(decoder.getShowable());
            dModel.insertNodeInto(decoderNameNode, familyElement, familyElement.getChildCount());
        }
    }
// end of loop over decoders       
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) HashMap(java.util.HashMap)

Example 12 with DecoderFile

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

the class PaneNewProgAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (log.isDebugEnabled()) {
        log.debug("New roster entry programmer requested");
    }
    // create the initial frame that steers
    final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameNewEntrySetup"));
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    // add the Roster menu
    JMenuBar menuBar = new JMenuBar();
    // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
    JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
    j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
    j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
    menuBar.add(j);
    menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
    f.setJMenuBar(menuBar);
    // new Loco on programming track
    JPanel pane1 = new LocoSelTreePane(null, null) {

        @Override
        protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
            String title = SymbolicProgBundle.getMessage("FrameNewEntryTitle");
            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) LocoSelTreePane(jmri.jmrit.symbolicprog.LocoSelTreePane) JmriJFrame(jmri.util.JmriJFrame) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) RosterEntry(jmri.jmrit.roster.RosterEntry) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu)

Example 13 with DecoderFile

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

the class SymbolicProgFrame method readAndParseConfigFile.

void readAndParseConfigFile(File file) {
    try {
        DecoderFile xf = new DecoderFile() {
        };
        // XmlFile is abstract
        Element root = xf.rootFromFile(file);
        // decode type, invoke proper processing routine if a decoder file
        if (root.getChild("decoder") != null) {
            log.debug("Attempt to open as decoder file");
            processDecoderFile(root.getChild("decoder"), xf);
            log.debug("succeeded");
        } else {
            // try again as a loco file
            log.debug("Attempt to open as loco file");
            if (root.getChild("locomotive") != null) {
                processLocoFile(root.getChild("locomotive"));
            } else {
                log.error("Unrecognized config file contents");
            }
        }
    } catch (org.jdom2.JDOMException | java.io.IOException e) {
        log.warn("readAndParseDecoderConfig: readAndParseDecoderConfig exception: " + e);
    }
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile) Element(org.jdom2.Element)

Example 14 with DecoderFile

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

the class AutoSpeedAction method actionPerformed.

@Override
public void actionPerformed(ActionEvent e) {
    if (log.isInfoEnabled()) {
        log.debug("auto speed tool requested");
    }
    // create the initial frame that steers
    final JFrame f = new JFrame("Auto-speed Tool Setup");
    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("Roster", jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
    f.setJMenuBar(menuBar);
    // known loco on main track
    JPanel pane1 = new // no ident in ops mode yet
    KnownLocoSelPane(// no ident in ops mode yet
    false) {

        @Override
        protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
            String title = "Set speed info for " + re.getId() + " on main track";
            // find the ops-mode programmer
            int address = Integer.parseInt(re.getDccAddress());
            boolean longAddr = true;
            if (address < 100) {
                longAddr = false;
            }
            Programmer programmer = InstanceManager.getDefault(jmri.ProgrammerManager.class).getAddressedProgrammer(longAddr, address);
            // and created the frame
            JFrame p = new PaneOpsProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", programmer);
            p.pack();
            p.setVisible(true);
            f.setVisible(false);
            f.dispose();
        }
    };
    // load primary frame
    pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(pane1);
    f.pack();
    if (log.isInfoEnabled()) {
        log.debug("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) PaneOpsProgFrame(jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgFrame) JFrame(javax.swing.JFrame) Programmer(jmri.Programmer) RosterEntry(jmri.jmrit.roster.RosterEntry) JMenuBar(javax.swing.JMenuBar)

Example 15 with DecoderFile

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

the class PaneProgFrame method loadDecoderFromLoco.

protected void loadDecoderFromLoco(RosterEntry r) {
    // get a DecoderFile from the locomotive xml
    String decoderModel = r.getDecoderModel();
    String decoderFamily = r.getDecoderFamily();
    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);
    log.debug("found {} matches", l.size());
    if (l.size() == 0) {
        log.debug("Loco uses " + decoderFamily + " " + decoderModel + " decoder, but no such decoder defined");
        // fall back to use just the decoder name, not family
        l = DecoderIndexFile.instance().matchingDecoderList(null, null, null, null, null, decoderModel);
        if (log.isDebugEnabled()) {
            log.debug("found " + l.size() + " matches without family key");
        }
    }
    if (l.size() > 0) {
        DecoderFile d = l.get(0);
        loadDecoderFile(d, r);
    } else {
        if (decoderModel.equals("")) {
            log.debug("blank decoderModel requested, so nothing loaded");
        } else {
            log.warn("no matching \"" + decoderModel + "\" decoder found for loco, no decoder info loaded");
        }
    }
}
Also used : DecoderFile(jmri.jmrit.decoderdefn.DecoderFile)

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