001package jmri.jmrit.operations.trains.excel;
002
003import java.awt.Dimension;
004import java.awt.GridBagLayout;
005import java.io.File;
006import java.util.ResourceBundle;
007
008import javax.swing.*;
009import javax.swing.filechooser.FileNameExtensionFilter;
010
011import jmri.InstanceManager;
012import jmri.jmrit.operations.OperationsFrame;
013import jmri.jmrit.operations.OperationsManager;
014import jmri.jmrit.operations.setup.Control;
015
016/**
017 * Frame for user edit of the file name and setup of an Excel program.
018 *
019 * @author Dan Boudreau Copyright (C) 2013
020 * 
021 */
022public class SetupExcelProgramFrame extends OperationsFrame {
023
024    // checkboxes
025    protected static final ResourceBundle rb = ResourceBundle.getBundle("jmri.jmrit.operations.setup.JmritOperationsSetupBundle");
026    JCheckBox generateCheckBox = new JCheckBox();
027
028    // text windows
029    JTextField fileNameTextField = new JTextField(30);
030
031    // major buttons
032    JButton addButton = new JButton(Bundle.getMessage("Add"));
033    JButton testButton = new JButton(Bundle.getMessage("Test"));
034    JButton saveButton = new JButton(Bundle.getMessage("ButtonSave"));
035
036    // directory
037    JPanel pDirectoryName = new JPanel();
038
039    @Override
040    public void initComponents() {
041
042        getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS));
043
044        // Layout the panel by rows
045        // row 1
046        JPanel pOptions = new JPanel();
047        pOptions.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Options")));
048        pOptions.add(generateCheckBox);
049
050        // row 2
051        pDirectoryName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("Directory")));
052
053        JPanel pFileName = new JPanel();
054        pFileName.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("FileName")));
055        pFileName.add(fileNameTextField);
056
057        // row 4 buttons
058        JPanel pButtons = new JPanel();
059        pButtons.setLayout(new GridBagLayout());
060        addItem(pButtons, addButton, 1, 0);
061        addItem(pButtons, testButton, 2, 0);
062        addItem(pButtons, saveButton, 3, 0);
063
064        getContentPane().add(pOptions);
065        getContentPane().add(pDirectoryName);
066        getContentPane().add(pFileName);
067        getContentPane().add(pButtons);
068
069        // setup buttons
070        addButtonAction(addButton);
071        addButtonAction(testButton);
072        addButtonAction(saveButton);
073
074        addHelpMenu("package.jmri.jmrit.operations.Operations_SetupExcelProgram", true); // NOI18N
075        setTitle(Bundle.getMessage("MenuItemSetupExcelProgram"));
076
077        initMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight300));
078    }
079
080    /**
081     * Opens a dialog window in either the csvManifest or csvSwitchLists
082     * directory
083     * @param directoryName The string name of the directory
084     * @return The File selected.
085     *
086     */
087    protected File selectFile(String directoryName) {
088        JFileChooser fc = new jmri.util.swing.JmriJFileChooser(InstanceManager.getDefault(OperationsManager.class).getFile(directoryName));
089        fc.setFileFilter(new FileNameExtensionFilter(Bundle.getMessage("ExcelProgramFiles"), "xls", "xlsm")); // NOI18N
090        fc.setDialogTitle(Bundle.getMessage("FindDesiredExcelFile"));
091        int retVal = fc.showOpenDialog(null);
092        // handle selection or cancel
093        if (retVal == JFileChooser.APPROVE_OPTION) {
094            return fc.getSelectedFile();
095        }
096        return null;
097    }
098
099//    private final static Logger log = LoggerFactory.getLogger(SetupExcelProgramFrame.class);
100}