001package jmri.jmrit.ctc.editor.gui; 002 003import javax.swing.SpinnerNumberModel; 004 005import jmri.jmrit.ctc.editor.code.AwtWindowProperties; 006import jmri.jmrit.ctc.editor.code.Columns; 007import jmri.jmrit.ctc.editor.code.CommonSubs; 008import jmri.util.swing.JmriJOptionPane; 009 010/** 011 * 012 * @author Gregory J. Bedlek Copyright (C) 2018, 2019 013 */ 014public class FrmAddModifyCTCColumn extends javax.swing.JFrame { 015 016 private static final String FORM_PROPERTIES = "DlgAddModifyCTCColumn"; // NOI18N 017 private final AwtWindowProperties _mAwtWindowProperties; 018 private final Columns _mColumns; 019 private final boolean _mIsModify; 020 public int _mNewSwitchNumber; 021 public int _mNewSignalEtcNumber; 022 public int _mNewGUIColumnNumber; 023 public boolean _mNewGUIGeneratedAtLeastOnceAlready; 024 025 /** 026 * Creates new form NewColumn 027 */ 028 private boolean _mClosedNormally = false; 029 public boolean closedNormally() { return _mClosedNormally; } 030 031 public FrmAddModifyCTCColumn(AwtWindowProperties awtWindowProperties, 032 Columns columns, 033 boolean isModify, 034 int existingSwitchNumber, 035 int existingGUIColumnNumber, 036 boolean existingGUIGeneratedAtLeastOnceAlready) { 037 super(); 038 initComponents(); 039 CommonSubs.addHelpMenu(this, "package.jmri.jmrit.ctc.CTC_osList", true); // NOI18N 040 _mAwtWindowProperties = awtWindowProperties; 041 _mColumns = columns; 042 _mIsModify = isModify; 043 if (!isModify) { // Add: 044 this.setTitle(Bundle.getMessage("TitleDlgAddModAdd")); // NOI18N 045 } else { // Modify: 046 this.setTitle(Bundle.getMessage("TitleDlgAddModChg")); // NOI18N 047 } 048 _mGUIColumnNumber.setModel(new SpinnerNumberModel(existingGUIColumnNumber, 0, 32767, 1)); 049 _mGUISwitchNumber.setModel(new SpinnerNumberModel(existingSwitchNumber, 1, 32767, 2)); 050 _mGUIGeneratedAtLeastOnceAlready.setSelected(existingGUIGeneratedAtLeastOnceAlready); 051 _mAwtWindowProperties.setWindowState(this, FORM_PROPERTIES); 052 this.getRootPane().setDefaultButton(_mSaveAndClose); 053 } 054 055 /** 056 * This method is called from within the constructor to initialize the form. 057 * WARNING: Do NOT modify this code. The content of this method is always 058 * regenerated by the Form Editor. 059 */ 060 // <editor-fold defaultstate="collapsed" desc="Generated Code">//GEN-BEGIN:initComponents 061 private void initComponents() { 062 063 jLabel1 = new javax.swing.JLabel(); 064 jLabel2 = new javax.swing.JLabel(); 065 _mSaveAndClose = new javax.swing.JButton(); 066 jLabel4 = new javax.swing.JLabel(); 067 jLabel5 = new javax.swing.JLabel(); 068 _mGUIColumnNumber = new javax.swing.JSpinner(); 069 _mGUISwitchNumber = new javax.swing.JSpinner(); 070 _mGUIGeneratedAtLeastOnceAlready = new javax.swing.JCheckBox(); 071 072 setDefaultCloseOperation(javax.swing.WindowConstants.DO_NOTHING_ON_CLOSE); 073 addWindowListener(new java.awt.event.WindowAdapter() { 074 @Override 075 public void windowClosing(java.awt.event.WindowEvent evt) { 076 formWindowClosing(evt); 077 } 078 }); 079 080 jLabel1.setHorizontalAlignment(javax.swing.SwingConstants.TRAILING); 081 jLabel1.setText(Bundle.getMessage("LabelDlgAddModSwitch")); 082 083 jLabel2.setText(Bundle.getMessage("InfoDlgAddModSignal")); 084 085 _mSaveAndClose.setText(Bundle.getMessage("ButtonSaveClose")); 086 _mSaveAndClose.addActionListener(new java.awt.event.ActionListener() { 087 @Override 088 public void actionPerformed(java.awt.event.ActionEvent evt) { 089 _mSaveAndCloseActionPerformed(evt); 090 } 091 }); 092 093 jLabel4.setText(Bundle.getMessage("LabelDlgAddModColumn")); 094 095 jLabel5.setText(Bundle.getMessage("InfoDlgAddModGen")); 096 097 _mGUIGeneratedAtLeastOnceAlready.setText(Bundle.getMessage("LabelDlgAddModGen") 098 ); 099 100 javax.swing.GroupLayout layout = new javax.swing.GroupLayout(getContentPane()); 101 getContentPane().setLayout(layout); 102 layout.setHorizontalGroup( 103 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 104 .addGroup(layout.createSequentialGroup() 105 .addGap(15, 15, 15) 106 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 107 .addGroup(javax.swing.GroupLayout.Alignment.TRAILING, layout.createSequentialGroup() 108 .addGap(63, 63, 63) 109 .addComponent(_mSaveAndClose, javax.swing.GroupLayout.PREFERRED_SIZE, 131, javax.swing.GroupLayout.PREFERRED_SIZE) 110 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 111 .addGroup(layout.createSequentialGroup() 112 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 113 .addComponent(_mGUIGeneratedAtLeastOnceAlready) 114 .addComponent(jLabel2) 115 .addGroup(layout.createSequentialGroup() 116 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.TRAILING) 117 .addComponent(jLabel1, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) 118 .addComponent(jLabel4)) 119 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 120 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 121 .addGroup(layout.createSequentialGroup() 122 .addComponent(_mGUIColumnNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 69, javax.swing.GroupLayout.PREFERRED_SIZE) 123 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 124 .addComponent(jLabel5)) 125 .addComponent(_mGUISwitchNumber, javax.swing.GroupLayout.PREFERRED_SIZE, 70, javax.swing.GroupLayout.PREFERRED_SIZE)))) 126 .addGap(0, 136, Short.MAX_VALUE)))) 127 ); 128 layout.setVerticalGroup( 129 layout.createParallelGroup(javax.swing.GroupLayout.Alignment.LEADING) 130 .addGroup(layout.createSequentialGroup() 131 .addContainerGap() 132 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 133 .addComponent(jLabel1) 134 .addComponent(_mGUISwitchNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 135 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 136 .addComponent(jLabel2) 137 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED, javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE) 138 .addGroup(layout.createParallelGroup(javax.swing.GroupLayout.Alignment.BASELINE) 139 .addComponent(jLabel4) 140 .addComponent(jLabel5) 141 .addComponent(_mGUIColumnNumber, javax.swing.GroupLayout.PREFERRED_SIZE, javax.swing.GroupLayout.DEFAULT_SIZE, javax.swing.GroupLayout.PREFERRED_SIZE)) 142 .addPreferredGap(javax.swing.LayoutStyle.ComponentPlacement.RELATED) 143 .addComponent(_mGUIGeneratedAtLeastOnceAlready) 144 .addGap(32, 32, 32) 145 .addComponent(_mSaveAndClose) 146 .addContainerGap(javax.swing.GroupLayout.DEFAULT_SIZE, Short.MAX_VALUE)) 147 ); 148 149 pack(); 150 }// </editor-fold>//GEN-END:initComponents 151 152 private void _mSaveAndCloseActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event__mSaveAndCloseActionPerformed 153 _mNewSwitchNumber = (int)_mGUISwitchNumber.getValue(); 154 _mNewGUIColumnNumber = (int)_mGUIColumnNumber.getValue(); 155 String errorText = _mColumns.checkForDups(_mNewSwitchNumber, _mNewGUIColumnNumber, _mIsModify, _mColumns.getEntrySelectedIndex()); 156 if (errorText != null) { 157 JmriJOptionPane.showMessageDialog(this, errorText, Bundle.getMessage("ErrorDlgAddModDuplicate"), JmriJOptionPane.ERROR_MESSAGE); return; // NOI18N DO NOT EXIT OUT OF FORM! 158 } 159 _mNewSignalEtcNumber = _mNewSwitchNumber + 1; 160 _mNewGUIGeneratedAtLeastOnceAlready = _mGUIGeneratedAtLeastOnceAlready.isSelected(); 161 162 _mClosedNormally = true; 163 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 164 dispose(); // All valid, valid to exit out of form. 165 }//GEN-LAST:event__mSaveAndCloseActionPerformed 166 167 private void formWindowClosing(java.awt.event.WindowEvent evt) {//GEN-FIRST:event_formWindowClosing 168 _mAwtWindowProperties.saveWindowState(this, FORM_PROPERTIES); 169 dispose(); 170 }//GEN-LAST:event_formWindowClosing 171 172 // Variables declaration - do not modify//GEN-BEGIN:variables 173 private javax.swing.JSpinner _mGUIColumnNumber; 174 private javax.swing.JCheckBox _mGUIGeneratedAtLeastOnceAlready; 175 private javax.swing.JSpinner _mGUISwitchNumber; 176 private javax.swing.JButton _mSaveAndClose; 177 private javax.swing.JLabel jLabel1; 178 private javax.swing.JLabel jLabel2; 179 private javax.swing.JLabel jLabel4; 180 private javax.swing.JLabel jLabel5; 181 // End of variables declaration//GEN-END:variables 182}