001package jmri.jmrit.ctc.editor.gui;
002
003import jmri.jmrit.ctc.editor.code.AwtWindowProperties;
004import jmri.jmrit.ctc.editor.code.CheckJMRIObject;
005import jmri.jmrit.ctc.editor.code.CodeButtonHandlerDataRoutines;
006import jmri.jmrit.ctc.editor.code.CommonSubs;
007import jmri.jmrit.ctc.editor.code.ProgramProperties;
008import jmri.jmrit.ctc.ctcserialdata.CodeButtonHandlerData;
009
010/**
011 *
012 * @author Gregory J. Bedlek Copyright (C) 2018, 2019
013 */
014public class FrmSIDL extends javax.swing.JFrame {
015
016    /**
017     * Creates new form DlgSIDL
018     */
019    private static final String FORM_PROPERTIES = "DlgSIDL";    // NOI18N
020    private final AwtWindowProperties _mAwtWindowProperties;
021    private boolean _mClosedNormally = false;
022    public boolean closedNormally() { return _mClosedNormally; }
023    private final CodeButtonHandlerData _mCodeButtonHandlerData;
024    private final ProgramProperties _mProgramProperties;
025
026    public FrmSIDL( AwtWindowProperties awtWindowProperties, CodeButtonHandlerData codeButtonHandlerData,
027                    ProgramProperties programProperties, CheckJMRIObject checkJMRIObject) {
028        super();
029        initComponents();
030        CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_frmSIDL", true);  // NOI18N
031        _mAwtWindowProperties = awtWindowProperties;
032        _mCodeButtonHandlerData = codeButtonHandlerData;
033        _mProgramProperties = programProperties;
034        CommonSubs.populateJComboBoxWithBeans(_mSIDL_LeftInternalSensor, "Sensor", _mCodeButtonHandlerData._mSIDL_LeftInternalSensor.getHandleName(), false);   // NOI18N
035        CommonSubs.populateJComboBoxWithBeans(_mSIDL_NormalInternalSensor, "Sensor", _mCodeButtonHandlerData._mSIDL_NormalInternalSensor.getHandleName(), false);   // NOI18N
036        CommonSubs.populateJComboBoxWithBeans(_mSIDL_RightInternalSensor, "Sensor", _mCodeButtonHandlerData._mSIDL_RightInternalSensor.getHandleName(), false);   // NOI18N
037        _mAwtWindowProperties.setWindowState(this, FORM_PROPERTIES);
038        this.getRootPane().setDefaultButton(_mSaveAndClose);
039    }
040
041    /**
042     * This method is called from within the constructor to initialize the form.
043     * WARNING: Do NOT modify this code. The content of this method is always
044     * regenerated by the Form Editor.
045     */
046    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
047    private void initComponents() {
048
049        _mSaveAndClose = new javax.swing.JButton();
050        _mSIDL_LeftInternalSensorPrompt = new javax.swing.JLabel();
051        _mSIDL_LeftInternalSensor = new javax.swing.JComboBox<>();
052        _mSIDL_NormalInternalSensorPrompt = new javax.swing.JLabel();
053        _mSIDL_NormalInternalSensor = new javax.swing.JComboBox<>();
054        _mSIDL_RightInternalSensorPrompt = new javax.swing.JLabel();
055        _mSIDL_RightInternalSensor = new javax.swing.JComboBox<>();
056        jButton2 = new javax.swing.JButton();
057
058        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
059        setTitle(Bundle.getMessage("TitleDlgSIDL"));
060        addWindowListener(new java.awt.event.WindowAdapter() {
061            @Override
062            public void windowClosing(java.awt.event.WindowEvent evt) {
063                formWindowClosing(evt);
064            }
065        });
066
067        _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose"));
068        _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() {
069            @Override
070            public void actionPerformed(java.awt.event.ActionEvent evt) {
071                _mSaveAndCloseActionPerformed(evt);
072            }
073        });
074
075        _mSIDL_LeftInternalSensorPrompt.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
076        _mSIDL_LeftInternalSensorPrompt.setText(Bundle.getMessage("LabelDlgSIDLLeft"));
077
078        _mSIDL_LeftInternalSensor.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
079
080        _mSIDL_NormalInternalSensorPrompt.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
081        _mSIDL_NormalInternalSensorPrompt.setText(Bundle.getMessage("LabelDlgSIDLNormal"));
082
083        _mSIDL_NormalInternalSensor.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
084
085        _mSIDL_RightInternalSensorPrompt.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
086        _mSIDL_RightInternalSensorPrompt.setText(Bundle.getMessage("LabelDlgSIDLRight"));
087
088        _mSIDL_RightInternalSensor.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
089
090        jButton2.setText(Bundle.getMessage("ButtonReapply"));
091        jButton2.addActionListener(new java.awt.event.ActionListener() {
092            @Override
093            public void actionPerformed(java.awt.event.ActionEvent evt) {
094                jButton2ActionPerformed(evt);
095            }
096        });
097
098        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
099        getContentPane().setLayout(layout);
100        layout.setHorizontalGroup(
101            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
102            .addGroup(layout.createSequentialGroup()
103                .addContainerGap()
104                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
105                    .addGroup(layout.createSequentialGroup()
106                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING, false)
107                            .addComponent(_mSIDL_RightInternalSensorPrompt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, 132, Short.MAX_VALUE)
108                            .addComponent(_mSIDL_LeftInternalSensorPrompt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.PREFERRED_SIZE, 129, javax.swing.GroupLayout.PREFERRED_SIZE)
109                            .addComponent(_mSIDL_NormalInternalSensorPrompt, javax.swing.GroupLayout.Alignment.TRAILING, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
110                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
111                        .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
112                            .addComponent(_mSIDL_LeftInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
113                            .addComponent(_mSIDL_NormalInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)
114                            .addComponent(_mSIDL_RightInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
115                        .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
116                    .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
117                        .addGap(0, 0, Short.MAX_VALUE)
118                        .addComponent(jButton2)
119                        .addGap(28, 28, 28))))
120            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
121                .addContainerGap(100, Short.MAX_VALUE)
122                .addComponent(_mSaveAndClose)
123                .addGap(72, 72, 72))
124        );
125        layout.setVerticalGroup(
126            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
127            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
128                .addContainerGap()
129                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
130                    .addComponent(_mSIDL_LeftInternalSensorPrompt)
131                    .addComponent(_mSIDL_LeftInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
132                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
133                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
134                    .addComponent(_mSIDL_NormalInternalSensorPrompt)
135                    .addComponent(_mSIDL_NormalInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
136                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED)
137                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
138                    .addComponent(_mSIDL_RightInternalSensorPrompt)
139                    .addComponent(_mSIDL_RightInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
140                .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 15, Short.MAX_VALUE)
141                .addComponent(_mSaveAndClose)
142                .addGap(18, 18, 18)
143                .addComponent(jButton2)
144                .addContainerGap())
145        );
146
147        pack();
148    }// </editor-fold>//GEN-END:initComponents
149
150    private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed
151        _mCodeButtonHandlerData._mSIDL_LeftInternalSensor = CommonSubs.getNBHSensor((String) _mSIDL_LeftInternalSensor.getSelectedItem(), false);
152        _mCodeButtonHandlerData._mSIDL_NormalInternalSensor = CommonSubs.getNBHSensor((String) _mSIDL_NormalInternalSensor.getSelectedItem(), false);
153        _mCodeButtonHandlerData._mSIDL_RightInternalSensor = CommonSubs.getNBHSensor((String) _mSIDL_RightInternalSensor.getSelectedItem(), false);
154
155        _mClosedNormally = true;
156        _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES);
157        dispose();
158    }//GEN-LAST:event__mSaveAndCloseActionPerformed
159
160    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
161        _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES);
162        dispose();
163    }//GEN-LAST:event_formWindowClosing
164
165    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
166        CodeButtonHandlerData temp = _mCodeButtonHandlerData;
167        temp = CodeButtonHandlerDataRoutines.uECBHDWSD_SIDL(_mProgramProperties, temp);
168        CommonSubs.populateJComboBoxWithBeans(_mSIDL_LeftInternalSensor, "Sensor", temp._mSIDL_LeftInternalSensor.getHandleName(), false);   // NOI18N
169        CommonSubs.populateJComboBoxWithBeans(_mSIDL_NormalInternalSensor, "Sensor", temp._mSIDL_NormalInternalSensor.getHandleName(), false);   // NOI18N
170        CommonSubs.populateJComboBoxWithBeans(_mSIDL_RightInternalSensor, "Sensor", temp._mSIDL_RightInternalSensor.getHandleName(), false);   // NOI18N
171    }//GEN-LAST:event_jButton2ActionPerformed
172
173    // Variables declaration - do not modify//GEN-BEGIN:variables
174    private javax.swing.JComboBox<String> _mSIDL_LeftInternalSensor;
175    private javax.swing.JLabel _mSIDL_LeftInternalSensorPrompt;
176    private javax.swing.JComboBox<String> _mSIDL_NormalInternalSensor;
177    private javax.swing.JLabel _mSIDL_NormalInternalSensorPrompt;
178    private javax.swing.JComboBox<String> _mSIDL_RightInternalSensor;
179    private javax.swing.JLabel _mSIDL_RightInternalSensorPrompt;
180    private javax.swing.JButton _mSaveAndClose;
181    private javax.swing.JButton jButton2;
182    // End of variables declaration//GEN-END:variables
183}