001package jmri.jmrit.ctc.editor.gui; 002 003import javax.swing.SpinnerNumberModel; 004import jmri.jmrit.ctc.editor.code.AwtWindowProperties; 005import jmri.jmrit.ctc.editor.code.CommonSubs; 006import jmri.jmrit.ctc.editor.code.ProgramProperties; 007import jmri.jmrit.ctc.ctcserialdata.OtherData; 008 009/** 010 * 011 * @author Gregory J. Bedlek Copyright (C) 2018, 2019 012 */ 013public class FrmDefaults extends javax.swing.JFrame { 014 015 private static final String FORM_PROPERTIES = "DlgDefaults"; // NOI18N 016 private final AwtWindowProperties _mAwtWindowProperties; 017 private final ProgramProperties _mProgramProperties; 018 private final OtherData _mOtherData; 019 private boolean _mClosedNormally = false; 020 public boolean closedNormally() { return _mClosedNormally; } 021 022 private int _mSIDI_CodingTimeInMillisecondsOrig; 023 private int _mSIDI_TimeLockingTimeInMillisecondsOrig; 024 private int _mSWDI_CodingTimeInMillisecondsOrig; 025 private boolean _mTUL_EnabledAtStartupOrig; 026 private int _mCodeButtonDelayTimeOrig; 027 private OtherData.SIGNAL_SYSTEM_TYPE _mSignalSystemTypeOrig; 028 private int _mTUL_SecondsToLockTurnoutsOrig; 029 030 private void initOrig(ProgramProperties programProperties, OtherData otherData) { 031 _mSIDI_CodingTimeInMillisecondsOrig = programProperties._mSIDI_CodingTimeInMilliseconds; 032 _mSIDI_TimeLockingTimeInMillisecondsOrig = programProperties._mSIDI_TimeLockingTimeInMilliseconds; 033 _mSWDI_CodingTimeInMillisecondsOrig = programProperties._mSWDI_CodingTimeInMilliseconds; 034 _mTUL_EnabledAtStartupOrig = otherData._mTUL_EnabledAtStartup; 035 _mCodeButtonDelayTimeOrig = programProperties._mCodeButtonDelayTime; 036 _mSignalSystemTypeOrig = otherData._mSignalSystemType; 037 _mTUL_SecondsToLockTurnoutsOrig = otherData._mTUL_SecondsToLockTurnouts; 038 } 039 private boolean dataChanged() { 040 if (CommonSubs.getIntFromJTextFieldNoThrow(_mSIDI_CodingTimeInMilliseconds) != _mSIDI_CodingTimeInMillisecondsOrig) return true; 041 if (CommonSubs.getIntFromJTextFieldNoThrow(_mSIDI_TimeLockingTimeInMilliseconds) != _mSIDI_TimeLockingTimeInMillisecondsOrig) return true; 042 if (CommonSubs.getIntFromJTextFieldNoThrow(_mSWDI_CodingTimeInMilliseconds) != _mSWDI_CodingTimeInMillisecondsOrig) return true; 043 if (_mTUL_EnabledAtStartupOrig != _mTUL_EnabledAtStartup.isSelected()) return true; 044 if (CommonSubs.getIntFromJTextFieldNoThrow(_mCodeButtonDelayTime) != _mCodeButtonDelayTimeOrig) return true; 045 if (_mSignalSystemTypeOrig != OtherData.SIGNAL_SYSTEM_TYPE.getSignalSystemType(_mSignalSystemType)) return true; 046 if (_mTUL_SecondsToLockTurnoutsOrig != (int)_mTUL_SecondsToLockTurnouts.getValue()) return true; 047 return false; 048 } 049 050 public FrmDefaults(AwtWindowProperties awtWindowProperties, ProgramProperties programProperties, OtherData otherData) { 051 super(); 052 initComponents(); 053 CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_menuCfgDef", true); // NOI18N 054 _mAwtWindowProperties = awtWindowProperties; 055 _mProgramProperties = programProperties; 056 _mOtherData = otherData; 057 CommonSubs.numberButtonGroup(_mSignalSystemType); 058 CommonSubs.setButtonSelected(_mSignalSystemType, _mOtherData._mSignalSystemType.getInt()); 059 _mTUL_SecondsToLockTurnouts.setModel(new SpinnerNumberModel(otherData._mTUL_SecondsToLockTurnouts, 0, 32767, 1)); 060 CommonSubs.setMillisecondsEdit(_mSIDI_CodingTimeInMilliseconds); 061 CommonSubs.setMillisecondsEdit(_mSWDI_CodingTimeInMilliseconds); 062 CommonSubs.setMillisecondsEdit(_mSIDI_TimeLockingTimeInMilliseconds); 063 CommonSubs.setMillisecondsEdit(_mCodeButtonDelayTime); 064 _mSIDI_CodingTimeInMilliseconds.setText(Integer.toString(programProperties._mSIDI_CodingTimeInMilliseconds)); 065 _mSIDI_TimeLockingTimeInMilliseconds.setText(Integer.toString(programProperties._mSIDI_TimeLockingTimeInMilliseconds)); 066 _mSWDI_CodingTimeInMilliseconds.setText(Integer.toString(programProperties._mSWDI_CodingTimeInMilliseconds)); 067 _mTUL_EnabledAtStartup.setSelected(_mOtherData._mTUL_EnabledAtStartup); 068 _mCodeButtonDelayTime.setText(Integer.toString(programProperties._mCodeButtonDelayTime)); 069 initOrig(_mProgramProperties, _mOtherData); 070 _mAwtWindowProperties.setWindowState(this, FORM_PROPERTIES); 071 this.getRootPane().setDefaultButton(_mSaveAndClose); 072 } 073 074 /** 075 * This method is called from within the constructor to initialize the form. 076 * WARNING: Do NOT modify this code. The content of this method is always 077 * regenerated by the Form Editor. 078 */ 079 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 080 private void initComponents() { 081 082 _mSignalSystemType = new javax.swing.ButtonGroup(); 083 _mSWDI_CodingTimeInMilliseconds = new javax.swing.JFormattedTextField(); 084 _mSIDI_CodingTimeInMilliseconds = new javax.swing.JFormattedTextField(); 085 jLabel19 = new javax.swing.JLabel(); 086 _mSIDI_TimeLockingTimeInMilliseconds = new javax.swing.JFormattedTextField(); 087 jLabel22 = new javax.swing.JLabel(); 088 jLabel27 = new javax.swing.JLabel(); 089 _mSaveAndClose = new javax.swing.JButton(); 090 jLabel18 = new javax.swing.JLabel(); 091 jLabel17 = new javax.swing.JLabel(); 092 jLabel23 = new javax.swing.JLabel(); 093 _mTUL_EnabledAtStartup = new javax.swing.JCheckBox(); 094 jLabel1 = new javax.swing.JLabel(); 095 jLabel2 = new javax.swing.JLabel(); 096 jLabel3 = new javax.swing.JLabel(); 097 jLabel4 = new javax.swing.JLabel(); 098 _mCodeButtonDelayTime = new javax.swing.JFormattedTextField(); 099 jLabel7 = new javax.swing.JLabel(); 100 jRadioButton1 = new javax.swing.JRadioButton(); 101 jRadioButton2 = new javax.swing.JRadioButton(); 102 jLabel5 = new javax.swing.JLabel(); 103 _mTUL_SecondsToLockTurnouts = new javax.swing.JSpinner(); 104 jLabel6 = new javax.swing.JLabel(); 105 106 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 107 setTitle(Bundle.getMessage("TitleDlgDef")); 108 addWindowListener(new java.awt.event.WindowAdapter() { 109 @Override 110 public void windowClosing(java.awt.event.WindowEvent evt) { 111 formWindowClosing(evt); 112 } 113 }); 114 115 _mSWDI_CodingTimeInMilliseconds.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0")))); 116 117 _mSIDI_CodingTimeInMilliseconds.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0")))); 118 119 jLabel19.setText(Bundle.getMessage("LabelDlgDefSignalTime")); 120 121 _mSIDI_TimeLockingTimeInMilliseconds.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0")))); 122 123 jLabel22.setText(Bundle.getMessage("LabelDlgDefLockTime")); 124 125 jLabel27.setText(Bundle.getMessage("LabelDlgDefSwitchTime")); 126 127 _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose")); 128 _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() { 129 @Override 130 public void actionPerformed(java.awt.event.ActionEvent evt) { 131 _mSaveAndCloseActionPerformed(evt); 132 } 133 }); 134 135 jLabel18.setText(Bundle.getMessage("InfoDlgDefSignalSep")); 136 137 jLabel17.setText(Bundle.getMessage("InfoDlgDefTimeRange")); 138 139 jLabel23.setText(Bundle.getMessage("InfoDlgDefSwitchSep")); 140 141 jLabel1.setText(Bundle.getMessage("LabelDlgDefLockEnabled")); 142 143 jLabel2.setText(Bundle.getMessage("LabelDlgDefCodeDelay")); 144 145 jLabel3.setText(Bundle.getMessage("InfoDlgDefCodeDelayZero")); 146 147 jLabel4.setText(Bundle.getMessage("InfoDlgDefCodeDelayMore")); 148 149 _mCodeButtonDelayTime.setFormatterFactory(new javax.swing.text.DefaultFormatterFactory(new javax.swing.text.NumberFormatter(new java.text.DecimalFormat("#0")))); 150 151 jLabel7.setText(Bundle.getMessage("LabelDlgDefSignalSystemType")); 152 153 _mSignalSystemType.add(jRadioButton1); 154 jRadioButton1.setText(Bundle.getMessage("LabelDlgDefSignalSystemTypeHeads")); 155 156 _mSignalSystemType.add(jRadioButton2); 157 jRadioButton2.setText(Bundle.getMessage("LabelDlgDefSignalSystemTypeMasts")); 158 159 jLabel5.setText(Bundle.getMessage("LabelDlgDefSecondsUntilUnlock")); 160 161 jLabel6.setText(Bundle.getMessage("LabelDlgDefSecondsUntilUnlockHint")); 162 163 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 164 getContentPane().setLayout(layout); 165 layout.setHorizontalGroup( 166 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 167 .addGroup(layout.createSequentialGroup() 168 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 169 .addGroup(layout.createSequentialGroup() 170 .addContainerGap() 171 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 172 .addComponent(jLabel17) 173 .addGroup(layout.createSequentialGroup() 174 .addGap(10, 10, 10) 175 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 176 .addComponent(jLabel18) 177 .addGroup(layout.createSequentialGroup() 178 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 179 .addComponent(jLabel22) 180 .addComponent(jLabel19) 181 .addComponent(jLabel2)) 182 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 183 .addGroup(layout.createSequentialGroup() 184 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 185 .addGroup(layout.createSequentialGroup() 186 .addComponent(_mSIDI_CodingTimeInMilliseconds, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) 187 .addGap(40, 40, 40) 188 .addComponent(jLabel27)) 189 .addComponent(_mSIDI_TimeLockingTimeInMilliseconds, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE)) 190 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 191 .addComponent(_mSWDI_CodingTimeInMilliseconds, javax.swing.GroupLayout.PREFERRED_SIZE, 79, javax.swing.GroupLayout.PREFERRED_SIZE)) 192 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() 193 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 194 .addComponent(_mCodeButtonDelayTime, javax.swing.GroupLayout.PREFERRED_SIZE, 93, javax.swing.GroupLayout.PREFERRED_SIZE) 195 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 196 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 197 .addComponent(jLabel4) 198 .addComponent(jLabel3))) 199 .addGroup(javax.swing.GroupLayout.Alignment.LEADING, layout.createSequentialGroup() 200 .addGap(133, 133, 133) 201 .addComponent(jLabel23)))))) 202 .addGroup(layout.createSequentialGroup() 203 .addComponent(jLabel7) 204 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 205 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 206 .addComponent(jRadioButton2) 207 .addComponent(jRadioButton1))))) 208 .addGroup(layout.createSequentialGroup() 209 .addGap(243, 243, 243) 210 .addComponent(_mSaveAndClose)) 211 .addGroup(layout.createSequentialGroup() 212 .addContainerGap() 213 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 214 .addComponent(jLabel5) 215 .addComponent(jLabel1, javax.swing.GroupLayout.Alignment.TRAILING)) 216 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 217 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 218 .addComponent(_mTUL_EnabledAtStartup) 219 .addGroup(layout.createSequentialGroup() 220 .addComponent(_mTUL_SecondsToLockTurnouts, javax.swing.GroupLayout.PREFERRED_SIZE, 53, javax.swing.GroupLayout.PREFERRED_SIZE) 221 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 222 .addComponent(jLabel6))))) 223 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 224 ); 225 layout.setVerticalGroup( 226 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 227 .addGroup(layout.createSequentialGroup() 228 .addContainerGap() 229 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 230 .addComponent(jLabel7) 231 .addComponent(jRadioButton1)) 232 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 233 .addComponent(jRadioButton2) 234 .addGap(18, 18, 18) 235 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 236 .addComponent(jLabel1) 237 .addComponent(_mTUL_EnabledAtStartup)) 238 .addGap(9, 9, 9) 239 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 240 .addComponent(jLabel5) 241 .addComponent(_mTUL_SecondsToLockTurnouts, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 242 .addComponent(jLabel6)) 243 .addGap(18, 18, 18) 244 .addComponent(jLabel17) 245 .addGap(20, 20, 20) 246 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 247 .addComponent(jLabel18) 248 .addComponent(jLabel23)) 249 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 250 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 251 .addComponent(_mSIDI_CodingTimeInMilliseconds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 252 .addComponent(jLabel19) 253 .addComponent(jLabel27) 254 .addComponent(_mSWDI_CodingTimeInMilliseconds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 255 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 256 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 257 .addComponent(_mSIDI_TimeLockingTimeInMilliseconds, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 258 .addComponent(jLabel22)) 259 .addGap(18, 18, 18) 260 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 261 .addComponent(jLabel2) 262 .addComponent(jLabel3) 263 .addComponent(_mCodeButtonDelayTime, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 264 .addGap(4, 4, 4) 265 .addComponent(jLabel4) 266 .addGap(18, 18, 18) 267 .addComponent(_mSaveAndClose) 268 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 269 ); 270 271 pack(); 272 }// </editor-fold>//GEN-END:initComponents 273 274 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing 275 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 276 if (CommonSubs.allowClose(this, dataChanged())) dispose(); 277 }//GEN-LAST:event_formWindowClosing 278 279 private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed 280 _mProgramProperties._mSIDI_CodingTimeInMilliseconds = Integer.parseInt(_mSIDI_CodingTimeInMilliseconds.getText()); 281 _mProgramProperties._mSIDI_TimeLockingTimeInMilliseconds = Integer.parseInt(_mSIDI_TimeLockingTimeInMilliseconds.getText()); 282 _mProgramProperties._mSWDI_CodingTimeInMilliseconds = Integer.parseInt(_mSWDI_CodingTimeInMilliseconds.getText()); 283 _mOtherData._mTUL_EnabledAtStartup = _mTUL_EnabledAtStartup.isSelected(); 284 _mProgramProperties._mCodeButtonDelayTime = Integer.parseInt(_mCodeButtonDelayTime.getText()); 285 _mOtherData._mSignalSystemType = OtherData.SIGNAL_SYSTEM_TYPE.getSignalSystemType(_mSignalSystemType); 286 _mOtherData._mTUL_SecondsToLockTurnouts = (int)_mTUL_SecondsToLockTurnouts.getValue(); 287 _mClosedNormally = true; 288 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 289 dispose(); 290 }//GEN-LAST:event__mSaveAndCloseActionPerformed 291 292 // Variables declaration - do not modify//GEN-BEGIN:variables 293 private javax.swing.JFormattedTextField _mCodeButtonDelayTime; 294 private javax.swing.JFormattedTextField _mSIDI_CodingTimeInMilliseconds; 295 private javax.swing.JFormattedTextField _mSIDI_TimeLockingTimeInMilliseconds; 296 private javax.swing.JFormattedTextField _mSWDI_CodingTimeInMilliseconds; 297 private javax.swing.JButton _mSaveAndClose; 298 private javax.swing.ButtonGroup _mSignalSystemType; 299 private javax.swing.JCheckBox _mTUL_EnabledAtStartup; 300 private javax.swing.JSpinner _mTUL_SecondsToLockTurnouts; 301 private javax.swing.JLabel jLabel1; 302 private javax.swing.JLabel jLabel17; 303 private javax.swing.JLabel jLabel18; 304 private javax.swing.JLabel jLabel19; 305 private javax.swing.JLabel jLabel2; 306 private javax.swing.JLabel jLabel22; 307 private javax.swing.JLabel jLabel23; 308 private javax.swing.JLabel jLabel27; 309 private javax.swing.JLabel jLabel3; 310 private javax.swing.JLabel jLabel4; 311 private javax.swing.JLabel jLabel5; 312 private javax.swing.JLabel jLabel6; 313 private javax.swing.JLabel jLabel7; 314 private javax.swing.JRadioButton jRadioButton1; 315 private javax.swing.JRadioButton jRadioButton2; 316 // End of variables declaration//GEN-END:variables 317}