Search in sources :

Example 1 with PaneProgFrame

use of jmri.jmrit.symbolicprog.tabbedframe.PaneProgFrame 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 2 with PaneProgFrame

use of jmri.jmrit.symbolicprog.tabbedframe.PaneProgFrame in project JMRI by JMRI.

the class RosterFrame method startProgrammer.

protected void startProgrammer(DecoderFile decoderFile, RosterEntry re, String filename) {
    if (inStartProgrammer) {
        log.debug("Call to start programmer has been called twice when the first call hasn't opened");
        return;
    }
    if (!checkIfEntrySelected()) {
        return;
    }
    try {
        setCursor(new Cursor(Cursor.WAIT_CURSOR));
        inStartProgrammer = true;
        String title = re.getId();
        JFrame progFrame = null;
        if (edit.isSelected()) {
            progFrame = new PaneProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", null, false) {

                @Override
                protected JPanel getModePane() {
                    return null;
                }
            };
        } else if (service.isSelected()) {
            progFrame = new PaneServiceProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", modePanel.getProgrammer()) {
            };
        } else if (ops.isSelected()) {
            int address = Integer.parseInt(re.getDccAddress());
            boolean longAddr = re.isLongAddress();
            Programmer pProg = InstanceManager.getDefault(AddressedProgrammerManager.class).getAddressedProgrammer(longAddr, address);
            progFrame = new PaneOpsProgFrame(decoderFile, re, title, "programmers" + File.separator + filename + ".xml", pProg);
        }
        if (progFrame == null) {
            return;
        }
        progFrame.pack();
        progFrame.setVisible(true);
    } finally {
        setCursor(new Cursor(Cursor.DEFAULT_CURSOR));
    }
    inStartProgrammer = false;
}
Also used : JPanel(javax.swing.JPanel) PaneProgFrame(jmri.jmrit.symbolicprog.tabbedframe.PaneProgFrame) JFrame(javax.swing.JFrame) Programmer(jmri.Programmer) PaneServiceProgFrame(jmri.jmrit.symbolicprog.tabbedframe.PaneServiceProgFrame) AddressedProgrammerManager(jmri.AddressedProgrammerManager) Cursor(java.awt.Cursor) PaneOpsProgFrame(jmri.jmrit.symbolicprog.tabbedframe.PaneOpsProgFrame)

Aggregations

JFrame (javax.swing.JFrame)2 JPanel (javax.swing.JPanel)2 PaneProgFrame (jmri.jmrit.symbolicprog.tabbedframe.PaneProgFrame)2 PaneServiceProgFrame (jmri.jmrit.symbolicprog.tabbedframe.PaneServiceProgFrame)2 BorderLayout (java.awt.BorderLayout)1 Cursor (java.awt.Cursor)1 ActionEvent (java.awt.event.ActionEvent)1 ActionListener (java.awt.event.ActionListener)1 WindowAdapter (java.awt.event.WindowAdapter)1 WindowEvent (java.awt.event.WindowEvent)1 BoxLayout (javax.swing.BoxLayout)1 JButton (javax.swing.JButton)1 JMenu (javax.swing.JMenu)1 JMenuBar (javax.swing.JMenuBar)1 JSeparator (javax.swing.JSeparator)1 TreeSelectionEvent (javax.swing.event.TreeSelectionEvent)1 TreeSelectionListener (javax.swing.event.TreeSelectionListener)1 TreeNode (javax.swing.tree.TreeNode)1 jmri (jmri)1 AddressedProgrammerManager (jmri.AddressedProgrammerManager)1