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.JMenuBar;
010import javax.swing.JPanel;
011import jmri.jmrit.decoderdefn.DecoderFile;
012import jmri.jmrit.roster.RosterEntry;
013import jmri.jmrit.symbolicprog.KnownLocoSelPane;
014import jmri.jmrit.symbolicprog.SymbolicProgBundle;
015import jmri.util.JmriJFrame;
016import org.slf4j.Logger;
017import org.slf4j.LoggerFactory;
018
019/**
020 * Swing action to create and register a frame for selecting the information
021 * needed to open a PaneProgFrame just for editing, without a programmer.
022 * <p>
023 * The resulting JFrame is constructed on the fly here, and has no specific
024 * type.
025 *
026 *
027 * @author Bob Jacobsen Copyright (C) 2008
028 */
029public class PaneEditAction extends AbstractAction {
030    Object o1, o2, o3, o4;
031
032    public PaneEditAction() {
033        this("Edit Roster Entry");
034    }
035
036    public PaneEditAction(String s) {
037        super(s);
038
039    }
040
041    @Override
042    public void actionPerformed(ActionEvent e) {
043
044        if (log.isDebugEnabled()) {
045            log.debug("Pane programmer requested");
046        }
047
048        // create the initial frame that steers
049        final JmriJFrame f = new JmriJFrame(SymbolicProgBundle.getMessage("FrameEditEntrySetup"));
050        f.getContentPane().setLayout(new BoxLayout(f.getContentPane(), BoxLayout.Y_AXIS));
051
052        // add the Roster menu
053        JMenuBar menuBar = new JMenuBar();
054        // menuBar.setBorder(new BevelBorder(BevelBorder.RAISED));
055        menuBar.add(new jmri.jmrit.roster.swing.RosterMenu(SymbolicProgBundle.getMessage("MenuRoster"),
056                jmri.jmrit.roster.swing.RosterMenu.MAINMENU, f));
057        f.setJMenuBar(menuBar);
058
059        // known entry, no programmer
060        JPanel pane1 = new KnownLocoSelPane(false) {  // not programming
061
062            @Override
063            protected void startProgrammer(DecoderFile decoderFile, RosterEntry re,
064                    String filename) {
065                String title = SymbolicProgBundle.getMessage("FrameEditEntryTitle");
066                JFrame p = new PaneProgFrame(decoderFile, re,
067                        title, "programmers" + File.separator + filename + ".xml",
068                        null, false) {
069
070                    @Override
071                            protected JPanel getModePane() {
072                                return null;
073                            }
074                        };
075                p.pack();
076                p.setVisible(true);
077
078            }
079        };
080
081        // load primary frame
082        pane1.setAlignmentX(JLabel.CENTER_ALIGNMENT);
083        f.getContentPane().add(pane1);
084
085        f.pack();
086        if (log.isDebugEnabled()) {
087            log.debug("Tab-Programmer setup created");
088        }
089        f.setVisible(true);
090    }
091
092    private final static Logger log = LoggerFactory.getLogger(PaneEditAction.class);
093
094}