001package jmri.jmrit.ctc.editor.gui; 002 003import jmri.jmrit.ctc.NBHSensor; 004import jmri.jmrit.ctc.editor.code.AwtWindowProperties; 005import jmri.jmrit.ctc.editor.code.CommonSubs; 006import jmri.jmrit.ctc.ctcserialdata.OtherData; 007 008/** 009 * 010 * @author Gregory J. Bedlek Copyright (C) 2018, 2019 011 */ 012public class FrmFleeting extends javax.swing.JFrame { 013 014 /** 015 * Creates new form dlgProperties 016 */ 017 private static final String FORM_PROPERTIES = "DlgFleeting"; // NOI18N 018 private final AwtWindowProperties _mAwtWindowProperties; 019 private final OtherData _mOtherData; 020 private boolean _mClosedNormally = false; 021 public boolean closedNormally() { return _mClosedNormally; } 022 023 private String _mFleetingToggleInternalSensorOrig; 024 private boolean _mDefaultFleetingEnabledOrig; 025 026 private void initOrig(OtherData otherData) { 027 _mFleetingToggleInternalSensorOrig = otherData._mFleetingToggleInternalSensor.getHandleName(); 028 _mDefaultFleetingEnabledOrig = otherData._mDefaultFleetingEnabled; 029 } 030 private boolean dataChanged() { 031 if (!_mFleetingToggleInternalSensorOrig.equals(_mFleetingToggleInternalSensor.getText())) return true; 032 if (_mDefaultFleetingEnabledOrig != _mDefaultFleetingEnabled.isSelected()) return true; 033 return false; 034 } 035 036 public FrmFleeting(AwtWindowProperties awtWindowProperties, OtherData otherData) { 037 super(); 038 initComponents(); 039 CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_menuCfgFlt", true); // NOI18N 040 _mAwtWindowProperties = awtWindowProperties; 041 _mOtherData = otherData; 042 _mFleetingToggleInternalSensor.setText(otherData._mFleetingToggleInternalSensor.getHandleName()); 043 _mDefaultFleetingEnabled.setSelected(otherData._mDefaultFleetingEnabled); 044 initOrig(otherData); 045 _mAwtWindowProperties.setWindowState(this, FORM_PROPERTIES); 046 this.getRootPane().setDefaultButton(_mSaveAndClose); 047 } 048 049 /** 050 * This method is called from within the constructor to initialize the form. 051 * WARNING: Do NOT modify this code. The content of this method is always 052 * regenerated by the Form Editor. 053 */ 054 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 055 private void initComponents() { 056 057 _mSaveAndClose = new javax.swing.JButton(); 058 _mFleetingToggleInternalSensor = new javax.swing.JTextField(); 059 jLabel21 = new javax.swing.JLabel(); 060 jLabel26 = new javax.swing.JLabel(); 061 _mDefaultFleetingEnabled = new javax.swing.JCheckBox(); 062 jLabel29 = new javax.swing.JLabel(); 063 064 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 065 setTitle(Bundle.getMessage("TitleDlgFleet")); 066 addWindowListener(new java.awt.event.WindowAdapter() { 067 @Override 068 public void windowClosing(java.awt.event.WindowEvent evt) { 069 formWindowClosing(evt); 070 } 071 }); 072 073 _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose")); 074 _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() { 075 @Override 076 public void actionPerformed(java.awt.event.ActionEvent evt) { 077 _mSaveAndCloseActionPerformed(evt); 078 } 079 }); 080 081 jLabel21.setText(Bundle.getMessage("LabelDlgFleetSensor")); 082 083 jLabel26.setText(Bundle.getMessage("InfoDlgFleet")); 084 085 _mDefaultFleetingEnabled.setText(" "); 086 087 jLabel29.setText(Bundle.getMessage("LabelDlgFleetEnabled")); 088 089 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 090 getContentPane().setLayout(layout); 091 layout.setHorizontalGroup( 092 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 093 .addGroup(layout.createSequentialGroup() 094 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 095 .addGroup(layout.createSequentialGroup() 096 .addGap(45, 45, 45) 097 .addComponent(jLabel21)) 098 .addGroup(layout.createSequentialGroup() 099 .addGap(33, 33, 33) 100 .addComponent(jLabel26)) 101 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 102 .addContainerGap() 103 .addComponent(jLabel29))) 104 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 105 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 106 .addComponent(_mDefaultFleetingEnabled) 107 .addComponent(_mFleetingToggleInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, 124, javax.swing.GroupLayout.PREFERRED_SIZE)) 108 .addGap(0, 179, Short.MAX_VALUE)) 109 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 110 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 111 .addComponent(_mSaveAndClose) 112 .addGap(142, 142, 142)) 113 ); 114 layout.setVerticalGroup( 115 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 116 .addGroup(layout.createSequentialGroup() 117 .addContainerGap() 118 .addComponent(jLabel26) 119 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.UNRELATED) 120 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 121 .addComponent(_mFleetingToggleInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 122 .addComponent(jLabel21)) 123 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 124 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 125 .addComponent(_mDefaultFleetingEnabled) 126 .addComponent(jLabel29)) 127 .addGap(18, 18, 18) 128 .addComponent(_mSaveAndClose) 129 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 130 ); 131 132 pack(); 133 }// </editor-fold>//GEN-END:initComponents 134 135 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing 136 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 137 if (CommonSubs.allowClose(this, dataChanged())) dispose(); 138 }//GEN-LAST:event_formWindowClosing 139 140 private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed 141 if (dataChanged()) { 142 143 NBHSensor newSensor = CommonSubs.getNBHSensor(_mFleetingToggleInternalSensor.getText(), true); 144 if (newSensor != null) _mOtherData._mFleetingToggleInternalSensor = newSensor; 145 146 _mOtherData._mDefaultFleetingEnabled = _mDefaultFleetingEnabled.isSelected(); 147 } 148 _mClosedNormally = true; 149 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 150 dispose(); 151 }//GEN-LAST:event__mSaveAndCloseActionPerformed 152 153 // Variables declaration - do not modify//GEN-BEGIN:variables 154 private javax.swing.JCheckBox _mDefaultFleetingEnabled; 155 private javax.swing.JTextField _mFleetingToggleInternalSensor; 156 private javax.swing.JButton _mSaveAndClose; 157 private javax.swing.JLabel jLabel21; 158 private javax.swing.JLabel jLabel26; 159 private javax.swing.JLabel jLabel29; 160 // End of variables declaration//GEN-END:variables 161}