001package jmri.jmrit.operations.trains.excel;
002
003import java.io.File;
004
005import javax.swing.JLabel;
006
007import jmri.InstanceManager;
008import jmri.jmrit.operations.OperationsXml;
009import jmri.jmrit.operations.setup.Setup;
010import jmri.util.swing.JmriJOptionPane;
011
012/**
013 * Frame for user edit of the file name of an Excel program used to generate
014 * custom manifests.
015 *
016 * @author Dan Boudreau Copyright (C) 2014, 2023
017 */
018public class SetupExcelProgramManifestFrame extends SetupExcelProgramFrame {
019
020    TrainCustomManifest tcm = InstanceManager.getDefault(TrainCustomManifest.class);
021
022    @Override
023    public void initComponents() {
024        super.initComponents();
025
026        generateCheckBox.setText(rb.getString("GenerateCsvManifest"));
027        generateCheckBox.setSelected(Setup.isGenerateCsvManifestEnabled());
028        fileNameTextField.setText(tcm.getFileName());
029        pDirectoryName.add(new JLabel(tcm.getDirectoryPathName()));
030    }
031
032    // Add, Test and Save buttons
033    @Override
034    public void buttonActionPerformed(java.awt.event.ActionEvent ae) {
035        if (ae.getSource() == addButton) {
036            File f = selectFile(tcm.getDirectoryName());
037            if (f != null) {
038                log.debug("User selected file: {}", f.getName());
039                fileNameTextField.setText(f.getName());
040            }
041        }
042
043        tcm.setFileName(fileNameTextField.getText());
044
045        if (ae.getSource() == testButton) {
046            if (tcm.excelFileExists()) {
047                JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("DirectoryNameFileName",
048                        tcm.getDirectoryName(), tcm.getFileName()),
049                        Bundle.getMessage("ManifestCreatorFound"), JmriJOptionPane.INFORMATION_MESSAGE);
050            } else {
051                JmriJOptionPane.showMessageDialog(this, 
052                        Bundle.getMessage("LoadDirectoryNameFileName",
053                                tcm.getDirectoryPathName(),
054                                tcm.getFileName()),
055                        Bundle.getMessage("ManifestCreatorNotFound"), JmriJOptionPane.ERROR_MESSAGE);
056            }
057        }
058        if (ae.getSource() == saveButton) {
059            log.debug("Save button activated");
060            Setup.setGenerateCsvManifestEnabled(generateCheckBox.isSelected());
061            OperationsXml.save();
062            if (Setup.isCloseWindowOnSaveEnabled()) {
063                dispose();
064            }
065        }
066    }
067
068    private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SetupExcelProgramManifestFrame.class);
069}