Search in sources :

Example 1 with CombinedLocoSelTreePane

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

the class PaneProgAction 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("FrameServiceProgrammerSetup"));
    f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
    // ensure status line is cleared on close so it is normal if re-opened
    f.addWindowListener(new WindowAdapter() {

        @Override
        public void windowClosing(WindowEvent we) {
            statusLabel.setText(SymbolicProgBundle.getMessage("StateIdle"));
            f.windowClosing(we);
        }
    });
    // 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 CombinedLocoSelTreePane(statusLabel, modePane) {

        @Override
        protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
            String title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { "new decoder" });
            if (re != null) {
                title = java.text.MessageFormat.format(SymbolicProgBundle.getMessage("FrameServiceProgrammerTitle"), new Object[] { re.getId() });
            }
            JFrame p = new PaneServiceProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", modePane.getProgrammer());
            p.pack();
            p.setVisible(true);
        // f.setVisible(false);
        // f.dispose();
        }
    };
    // load primary frame
    JPanel tempPane = new JPanel();
    tempPane.add(modePane);
    f.getContentPane().add(tempPane);
    f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
    pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(pane1);
    f.getContentPane().add(new JSeparator(javax.swing.SwingConstants.HORIZONTAL));
    statusLabel.setAlignmentX(JLabel.CENTER_ALIGNMENT);
    f.getContentPane().add(statusLabel);
    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) WindowAdapter(java.awt.event.WindowAdapter) JSeparator(javax.swing.JSeparator) JmriJFrame(jmri.util.JmriJFrame) JmriJFrame(jmri.util.JmriJFrame) JFrame(javax.swing.JFrame) WindowEvent(java.awt.event.WindowEvent) RosterEntry(jmri.jmrit.roster.RosterEntry) JMenuBar(javax.swing.JMenuBar) JMenu(javax.swing.JMenu) CombinedLocoSelTreePane(jmri.jmrit.symbolicprog.CombinedLocoSelTreePane)

Example 2 with CombinedLocoSelTreePane

use of jmri.jmrit.symbolicprog.CombinedLocoSelTreePane 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)

Aggregations

WindowAdapter (java.awt.event.WindowAdapter)2 WindowEvent (java.awt.event.WindowEvent)2 BoxLayout (javax.swing.BoxLayout)2 JFrame (javax.swing.JFrame)2 JMenu (javax.swing.JMenu)2 JMenuBar (javax.swing.JMenuBar)2 JPanel (javax.swing.JPanel)2 JSeparator (javax.swing.JSeparator)2 DecoderFile (jmri.jmrit.decoderdefn.DecoderFile)2 RosterEntry (jmri.jmrit.roster.RosterEntry)2 CombinedLocoSelTreePane (jmri.jmrit.symbolicprog.CombinedLocoSelTreePane)2 JmriJFrame (jmri.util.JmriJFrame)2 BorderLayout (java.awt.BorderLayout)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 JButton (javax.swing.JButton)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 TreeNode (javax.swing.tree.TreeNode)1 jmri (jmri)1