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 FrmSWDL extends javax.swing.JFrame {
015
016    /**
017     * Creates new form DlgSWDL
018     */
019    private static final String FORM_PROPERTIES = "DlgSWDL";    // 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 FrmSWDL( AwtWindowProperties awtWindowProperties, CodeButtonHandlerData codeButtonHandlerData,
027                    ProgramProperties programProperties, CheckJMRIObject checkJMRIObject) {
028        super();
029        initComponents();
030        CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_frmSWDL", true);  // NOI18N
031        _mAwtWindowProperties = awtWindowProperties;
032        _mCodeButtonHandlerData = codeButtonHandlerData;
033        _mProgramProperties = programProperties;
034        CommonSubs.populateJComboBoxWithBeans(_mSWDL_InternalSensor, "Sensor", _mCodeButtonHandlerData._mSWDL_InternalSensor.getHandleName(), false);   // NOI18N
035        _mAwtWindowProperties.setWindowState(this, FORM_PROPERTIES);
036        this.getRootPane().setDefaultButton(_mSaveAndClose);
037    }
038
039    /**
040     * This method is called from within the constructor to initialize the form.
041     * WARNING: Do NOT modify this code. The content of this method is always
042     * regenerated by the Form Editor.
043     */
044    // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents
045    private void initComponents() {
046
047        _mSaveAndClose = new javax.swing.JButton();
048        _mSWDL_InternalSensorPrompt = new javax.swing.JLabel();
049        jButton2 = new javax.swing.JButton();
050        _mSWDL_InternalSensor = new javax.swing.JComboBox<>();
051
052        setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE);
053        setTitle(Bundle.getMessage("TitleDlgSWDL"));
054        addWindowListener(new java.awt.event.WindowAdapter() {
055            @Override
056            public void windowClosing(java.awt.event.WindowEvent evt) {
057                formWindowClosing(evt);
058            }
059        });
060
061        _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose"));
062        _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() {
063            @Override
064            public void actionPerformed(java.awt.event.ActionEvent evt) {
065                _mSaveAndCloseActionPerformed(evt);
066            }
067        });
068
069        _mSWDL_InternalSensorPrompt.setHorizontalAlignment(javax.swing.SwingConstants.RIGHT);
070        _mSWDL_InternalSensorPrompt.setText(Bundle.getMessage("LabelDlgSWDLLever"));
071
072        jButton2.setText(Bundle.getMessage("ButtonReapply"));
073        jButton2.addActionListener(new java.awt.event.ActionListener() {
074            @Override
075            public void actionPerformed(java.awt.event.ActionEvent evt) {
076                jButton2ActionPerformed(evt);
077            }
078        });
079
080        _mSWDL_InternalSensor.setModel(new javax.swing.DefaultComboBoxModel<>(new String[] { "Item 1", "Item 2", "Item 3", "Item 4" }));
081
082        javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane());
083        getContentPane().setLayout(layout);
084        layout.setHorizontalGroup(
085            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
086            .addGroup(layout.createSequentialGroup()
087                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
088                    .addGroup(layout.createSequentialGroup()
089                        .addContainerGap()
090                        .addComponent(_mSWDL_InternalSensorPrompt, javax.swing.GroupLayout.PREFERRED_SIZE, 99, javax.swing.GroupLayout.PREFERRED_SIZE)
091                        .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED)
092                        .addComponent(_mSWDL_InternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
093                    .addGroup(layout.createSequentialGroup()
094                        .addGap(106, 106, 106)
095                        .addComponent(_mSaveAndClose))
096                    .addGroup(layout.createSequentialGroup()
097                        .addGap(55, 55, 55)
098                        .addComponent(jButton2)))
099                .addContainerGap(99, Short.MAX_VALUE))
100        );
101        layout.setVerticalGroup(
102            layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING)
103            .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup()
104                .addContainerGap()
105                .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE)
106                    .addComponent(_mSWDL_InternalSensorPrompt, javax.swing.GroupLayout.PREFERRED_SIZE, 12, javax.swing.GroupLayout.PREFERRED_SIZE)
107                    .addComponent(_mSWDL_InternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE))
108                .addGap(18, 18, 18)
109                .addComponent(_mSaveAndClose)
110                .addGap(37, 37, 37)
111                .addComponent(jButton2)
112                .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE))
113        );
114
115        pack();
116    }// </editor-fold>//GEN-END:initComponents
117
118    private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed
119
120        _mCodeButtonHandlerData._mSWDL_InternalSensor = CommonSubs.getNBHSensor((String) _mSWDL_InternalSensor.getSelectedItem(), false);
121
122        _mClosedNormally = true;
123        _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES);
124        dispose();
125    }//GEN-LAST:event__mSaveAndCloseActionPerformed
126
127    private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing
128        _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES);
129        dispose();
130    }//GEN-LAST:event_formWindowClosing
131
132    private void jButton2ActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_jButton2ActionPerformed
133        CodeButtonHandlerData temp = _mCodeButtonHandlerData;
134        temp = CodeButtonHandlerDataRoutines.uECBHDWSD_SWDL(_mProgramProperties, temp);
135        CommonSubs.populateJComboBoxWithBeans(_mSWDL_InternalSensor, "Sensor", temp._mSWDL_InternalSensor.getHandleName(), false);   // NOI18N
136    }//GEN-LAST:event_jButton2ActionPerformed
137
138    // Variables declaration - do not modify//GEN-BEGIN:variables
139    private javax.swing.JComboBox<String> _mSWDL_InternalSensor;
140    private javax.swing.JLabel _mSWDL_InternalSensorPrompt;
141    private javax.swing.JButton _mSaveAndClose;
142    private javax.swing.JButton jButton2;
143    // End of variables declaration//GEN-END:variables
144}