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 * switch lists. 015 * 016 * @author Dan Boudreau Copyright (C) 2014, 2023 017 */ 018public class SetupExcelProgramSwitchListFrame extends SetupExcelProgramFrame { 019 020 TrainCustomSwitchList tcs = InstanceManager.getDefault(TrainCustomSwitchList.class); 021 022 @Override 023 public void initComponents() { 024 super.initComponents(); 025 026 generateCheckBox.setText(rb.getString("GenerateCsvSwitchList")); 027 generateCheckBox.setSelected(Setup.isGenerateCsvSwitchListEnabled()); 028 fileNameTextField.setText(tcs.getFileName()); 029 pDirectoryName.add(new JLabel(tcs.getDirectoryPathName())); 030 setTitle(Bundle.getMessage("MenuItemSetupExcelProgramSwitchList")); 031 032 } 033 034 // Save and Test 035 @Override 036 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 037 if (ae.getSource() == addButton) { 038 File f = selectFile(tcs.getDirectoryName()); 039 if (f != null) { 040 log.debug("User selected file: {}", f.getName()); 041 fileNameTextField.setText(f.getName()); 042 } 043 } 044 045 tcs.setFileName(fileNameTextField.getText()); 046 047 if (ae.getSource() == testButton) { 048 if (tcs.excelFileExists()) { 049 JmriJOptionPane.showMessageDialog(this, Bundle.getMessage("DirectoryNameFileName", 050 tcs.getDirectoryName(), tcs.getFileName()), 051 Bundle.getMessage("ManifestCreatorFound"), JmriJOptionPane.INFORMATION_MESSAGE); 052 } else { 053 JmriJOptionPane.showMessageDialog(this, 054 Bundle.getMessage("LoadDirectoryNameFileName", 055 tcs.getDirectoryPathName(), 056 tcs.getFileName()), 057 Bundle.getMessage("ManifestCreatorNotFound"), JmriJOptionPane.ERROR_MESSAGE); 058 } 059 } 060 if (ae.getSource() == saveButton) { 061 log.debug("Save button activated"); 062 Setup.setGenerateCsvSwitchListEnabled(generateCheckBox.isSelected()); 063 OperationsXml.save(); 064 if (Setup.isCloseWindowOnSaveEnabled()) { 065 dispose(); 066 } 067 } 068 } 069 070 private static final org.slf4j.Logger log = org.slf4j.LoggerFactory.getLogger(SetupExcelProgramSwitchListFrame.class); 071}