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 FrmDebugging extends javax.swing.JFrame { 013 014 /** 015 * Creates new form dlgProperties 016 */ 017 private static final String FORM_PROPERTIES = "DlgDebugging"; // 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 _mCTCDebugSystemReloadInternalSensorOrig; 024 private String _mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensorOrig; 025 026 private void initOrig(OtherData otherData) { 027 _mCTCDebugSystemReloadInternalSensorOrig = otherData._mCTCDebugSystemReloadInternalSensor.getHandleName(); 028 _mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensorOrig = otherData._mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor.getHandleName(); 029 } 030 private boolean dataChanged() { 031 if (!_mCTCDebugSystemReloadInternalSensorOrig.equals(_mCTCSystemReloadInternalSensor.getText())) return true; 032 if (!_mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensorOrig.equals(_mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor.getText())) return true; 033 return false; 034 } 035 036 public FrmDebugging(AwtWindowProperties awtWindowProperties, OtherData otherData) { 037 super(); 038 initComponents(); 039 CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_menuCfgDeb", true); // NOI18N 040 _mAwtWindowProperties = awtWindowProperties; 041 _mOtherData = otherData; 042 _mCTCSystemReloadInternalSensor.setText(otherData._mCTCDebugSystemReloadInternalSensor.getHandleName()); 043 _mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor.setText(otherData._mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor.getHandleName()); 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 _mCTCSystemReloadInternalSensor = new javax.swing.JTextField(); 059 jLabel3 = new javax.swing.JLabel(); 060 jLabel4 = new javax.swing.JLabel(); 061 _mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor = new javax.swing.JTextField(); 062 jLabel1 = new javax.swing.JLabel(); 063 jLabel2 = new javax.swing.JLabel(); 064 jLabel5 = new javax.swing.JLabel(); 065 066 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 067 setTitle(Bundle.getMessage("TitleDlgDeb")); 068 addWindowListener(new java.awt.event.WindowAdapter() { 069 @Override 070 public void windowClosing(java.awt.event.WindowEvent evt) { 071 formWindowClosing(evt); 072 } 073 }); 074 075 _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose")); 076 _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() { 077 @Override 078 public void actionPerformed(java.awt.event.ActionEvent evt) { 079 _mSaveAndCloseActionPerformed(evt); 080 } 081 }); 082 083 jLabel3.setText(Bundle.getMessage("LabelDlgDebReload")); 084 085 jLabel4.setText(Bundle.getMessage("InfoDlgDebReload")); 086 087 jLabel1.setText(Bundle.getMessage("LabelDlgDebRules")); 088 089 jLabel2.setText(Bundle.getMessage("InfoDlgDebRules1")); 090 091 jLabel5.setText(Bundle.getMessage("InfoDlgDebRules2")); 092 093 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 094 getContentPane().setLayout(layout); 095 layout.setHorizontalGroup( 096 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 097 .addGroup(layout.createSequentialGroup() 098 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 099 .addGroup(layout.createSequentialGroup() 100 .addContainerGap() 101 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 102 .addComponent(jLabel1) 103 .addComponent(jLabel3, javax.swing.GroupLayout.Alignment.TRAILING)) 104 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 105 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 106 .addComponent(_mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor) 107 .addComponent(_mCTCSystemReloadInternalSensor))) 108 .addGroup(layout.createSequentialGroup() 109 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 110 .addGroup(layout.createSequentialGroup() 111 .addGap(246, 246, 246) 112 .addComponent(_mSaveAndClose)) 113 .addGroup(layout.createSequentialGroup() 114 .addContainerGap() 115 .addComponent(jLabel5)) 116 .addGroup(layout.createSequentialGroup() 117 .addContainerGap() 118 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 119 .addComponent(jLabel4) 120 .addComponent(jLabel2)))) 121 .addGap(0, 0, Short.MAX_VALUE))) 122 .addContainerGap()) 123 ); 124 layout.setVerticalGroup( 125 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 126 .addGroup(layout.createSequentialGroup() 127 .addContainerGap() 128 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 129 .addComponent(_mCTCSystemReloadInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE) 130 .addComponent(jLabel3)) 131 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 132 .addComponent(jLabel4) 133 .addGap(18, 18, 18) 134 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 135 .addComponent(jLabel1) 136 .addComponent(_mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 137 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 138 .addComponent(jLabel2) 139 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 140 .addComponent(jLabel5) 141 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, 28, Short.MAX_VALUE) 142 .addComponent(_mSaveAndClose) 143 .addContainerGap()) 144 ); 145 146 pack(); 147 }// </editor-fold>//GEN-END:initComponents 148 149 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing 150 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 151 if (CommonSubs.allowClose(this, dataChanged())) dispose(); 152 }//GEN-LAST:event_formWindowClosing 153 154 private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed 155 if (dataChanged()) { 156 157 NBHSensor newSensor = CommonSubs.getNBHSensor(_mCTCSystemReloadInternalSensor.getText(), true); 158 if (newSensor != null) _mOtherData._mCTCDebugSystemReloadInternalSensor = newSensor; 159 160 newSensor = CommonSubs.getNBHSensor(_mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor.getText(), true); 161 if (newSensor != null) _mOtherData._mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor = newSensor; 162 } 163 164 _mClosedNormally = true; 165 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 166 dispose(); 167 }//GEN-LAST:event__mSaveAndCloseActionPerformed 168 169 // Variables declaration - do not modify//GEN-BEGIN:variables 170 private javax.swing.JTextField _mCTCDebug_TrafficLockingRuleTriggeredDisplayInternalSensor; 171 private javax.swing.JTextField _mCTCSystemReloadInternalSensor; 172 private javax.swing.JButton _mSaveAndClose; 173 private javax.swing.JLabel jLabel1; 174 private javax.swing.JLabel jLabel2; 175 private javax.swing.JLabel jLabel3; 176 private javax.swing.JLabel jLabel4; 177 private javax.swing.JLabel jLabel5; 178 // End of variables declaration//GEN-END:variables 179}