001package jmri.jmrit.symbolicprog.tabbedframe;
002
003import java.awt.event.ActionEvent;
004import java.io.File;
005import javax.swing.AbstractAction;
006import javax.swing.BoxLayout;
007import javax.swing.JFrame;
008import javax.swing.JLabel;
009import javax.swing.JMenu;
010import javax.swing.JMenuBar;
011import javax.swing.JPanel;
012import jmri.jmrit.decoderdefn.DecoderFile;
013import jmri.jmrit.roster.RosterEntry;
014import jmri.jmrit.symbolicprog.LocoSelTreePane;
015import jmri.jmrit.symbolicprog.SymbolicProgBundle;
016import jmri.util.JmriJFrame;
017import org.slf4j.Logger;
018import org.slf4j.LoggerFactory;
019
020/**
021 * Swing action to create and register a frame for selecting the information
022 * needed to open a PaneProgFrame for creating a new Roster entry.
023 * <p>
024 * The resulting JFrame is constructed on the fly here, and has no specific
025 * type.
026 * <p>
027 * Note that this just works with the roster, no programming track or
028 * layout operations are present.
029 *
030 * @see jmri.jmrit.symbolicprog.tabbedframe.PaneProgAction
031 *
032 * @author Bob Jacobsen Copyright (C) 2001, 2008, 2015
033 */
034public class PaneNewProgAction extends AbstractAction {
035
036    Object o1, o2, o3, o4;
037
038    public PaneNewProgAction() {
039        this("DecoderPro service programmer");
040    }
041
042    public PaneNewProgAction(String s) {
043        super(s);
044    }
045
046    @Override
047    public void actionPerformed(ActionEvent e) {
048
049        if (log.isDebugEnabled()) {
050            log.debug("New roster entry programmer requested");
051        }
052
053        // create the initial frame that steers
054        final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameNewEntrySetup"));
055        f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
056
057        // add the Roster menu
058        JMenuBar menuBar = new JMenuBar();
059        // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
060        JMenu j = new JMenu(SymbolicProgBundle.getMessage("MenuFile"));
061        j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintDecoderDefinitions"), f, false));
062        j.add(new jmri.jmrit.decoderdefn.PrintDecoderListAction(SymbolicProgBundle.getMessage("MenuPrintPreviewDecoderDefinitions"), f, true));
063        menuBar.add(j);
064        menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"), jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
065        f.setJMenuBar(menuBar);
066
067        // new Loco on programming track
068        JPanel pane1 = new LocoSelTreePane(null, null) {
069
070            @Override
071            protected void startProgrammer(DecoderFile decoderFile, RosterEntry re,
072                    String filename) {
073                String title = SymbolicProgBundle.getMessage("FrameNewEntryTitle");
074                JFrame p = new PaneProgFrame(decoderFile, re,
075                        title, "programmers" + File.separator + filename + ".xml",
076                        null, false) {
077
078                    @Override
079                            protected JPanel getModePane() {
080                                return null;
081                            }
082                        };
083                p.pack();
084                p.setVisible(true);
085
086            }
087        };
088
089        // load primary frame
090        pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
091        f.getContentPane().add(pane1);
092
093        f.pack();
094        if (log.isDebugEnabled()) {
095            log.debug("Tab-Programmer setup created");
096        }
097        f.setVisible(true);
098    }
099
100    private final static Logger log = LoggerFactory.getLogger(PaneNewProgAction.class);
101
102}