001package jmri.jmrit.operations.automation.gui; 002 003import java.awt.Dimension; 004import java.awt.GridBagLayout; 005 006import javax.swing.*; 007 008import jmri.InstanceManager; 009import jmri.jmrit.operations.OperationsFrame; 010import jmri.jmrit.operations.OperationsXml; 011import jmri.jmrit.operations.automation.Automation; 012import jmri.jmrit.operations.automation.AutomationManager; 013import jmri.jmrit.operations.setup.Control; 014import jmri.jmrit.operations.setup.Setup; 015 016/** 017 * Frame for user selection of a startup automation 018 * 019 * @author Bob Jacobsen Copyright (C) 2004 020 * @author Dan Boudreau Copyright (C) 2022 021 */ 022public class AutomationStartupFrame extends OperationsFrame implements java.beans.PropertyChangeListener { 023 024 AutomationManager automationManager = InstanceManager.getDefault(AutomationManager.class); 025 026 JButton saveButton = new JButton(Bundle.getMessage("ButtonSave")); 027 JButton testButton = new JButton(Bundle.getMessage("ButtonTest")); 028 029 JComboBox<Automation> comboBox = automationManager.getComboBox(); 030 031 public AutomationStartupFrame() { 032 super(Bundle.getMessage("MenuStartupAutomation")); 033 // general GUI config 034 getContentPane().setLayout(new BoxLayout(getContentPane(), BoxLayout.Y_AXIS)); 035 036 // setup by rows 037 JPanel pAutomation = new JPanel(); 038 pAutomation.setLayout(new GridBagLayout()); 039 pAutomation.setBorder(BorderFactory.createTitledBorder(Bundle.getMessage("MenuStartupAutomation"))); 040 addItem(pAutomation, comboBox, 0, 0); 041 042 JPanel pB = new JPanel(); 043 pB.setLayout(new GridBagLayout()); 044 pB.setBorder(BorderFactory.createTitledBorder("")); 045 addItem(pB, testButton, 0, 0); 046 addItem(pB, saveButton, 1, 0); 047 048 getContentPane().add(pAutomation); 049 getContentPane().add(pB); 050 051 addButtonAction(testButton); 052 addButtonAction(saveButton); 053 comboBox.setSelectedItem(automationManager.getStartupAutomation()); 054 055 testButton.setToolTipText(Bundle.getMessage("ButtonTestTip")); 056 057 automationManager.addPropertyChangeListener(this); 058 059 initMinimumSize(new Dimension(Control.panelWidth500, Control.panelHeight200)); 060 } 061 062 @Override 063 public void buttonActionPerformed(java.awt.event.ActionEvent ae) { 064 if (ae.getSource() == testButton) { 065 automationManager.runStartupAutomation(); 066 } 067 if (ae.getSource() == saveButton) { 068 automationManager.setStartupAutomation((Automation) comboBox.getSelectedItem()); 069 OperationsXml.save(); 070 if (Setup.isCloseWindowOnSaveEnabled()) { 071 dispose(); 072 } 073 } 074 } 075 076 @Override 077 public void dispose() { 078 automationManager.removePropertyChangeListener(this); 079 super.dispose(); 080 } 081 082 @Override 083 public void propertyChange(java.beans.PropertyChangeEvent e) { 084 if (e.getPropertyName().equals(AutomationManager.LISTLENGTH_CHANGED_PROPERTY)) { 085 automationManager.updateComboBox(comboBox); 086 comboBox.setSelectedItem(automationManager.getStartupAutomation()); 087 } 088 } 089}