1 6 7 package org.netbeans.modules.logger; 8 9 import java.lang.StringBuffer ; 10 import org.netbeans.modules.logger.listeners.ListenerTools; 11 12 18 public class UserInput extends javax.swing.JFrame { 19 20 23 public final static String LEVEL1 = "beginner"; 24 27 public final static String LEVEL2 = "frequent user"; 28 31 public final static String LEVEL3 = "experienced user"; 32 static String nickname = ""; 33 static String level = LEVEL2; 34 static boolean typed = false; 35 Main main; 36 37 42 public UserInput(Main main) { 43 this.main = main; 44 initComponents(); 45 } 46 47 private void initComponents() { 48 java.awt.GridBagConstraints gridBagConstraints; 49 50 buttonGroup = new javax.swing.ButtonGroup (); 51 jPanel3 = new javax.swing.JPanel (); 52 jPanel1 = new javax.swing.JPanel (); 53 titleLabel = new javax.swing.JLabel (); 54 nicknameTextField = new javax.swing.JTextField (); 55 levelLabel = new javax.swing.JLabel (); 56 level1RadioButton = new javax.swing.JRadioButton (); 57 level2RadioButton = new javax.swing.JRadioButton (); 58 level3RadioButton = new javax.swing.JRadioButton (); 59 nameLabel = new javax.swing.JLabel (); 60 jPanel2 = new javax.swing.JPanel (); 61 helpButton = new javax.swing.JButton (); 62 okButton = new javax.swing.JButton (); 63 64 setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE); 65 setTitle("Logger Module"); 66 setName("Logger Module"); 67 setResizable(false); 68 jPanel1.setLayout(new java.awt.GridBagLayout ()); 69 70 jPanel1.setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (12, 12, 12, 12))); 71 jPanel1.setMaximumSize(null); 72 jPanel1.setMinimumSize(null); 73 jPanel1.setPreferredSize(new java.awt.Dimension (300, 300)); 74 titleLabel.setText("<html>Thank you for using xDesign Logger Module. Please provide your name and the level of your experience with NetBeans.</html>"); 75 titleLabel.setBorder(new javax.swing.border.TitledBorder ("Thank you!")); 76 titleLabel.setFocusable(false); 77 gridBagConstraints = new java.awt.GridBagConstraints (); 78 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 79 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 80 gridBagConstraints.weightx = 1.0; 81 gridBagConstraints.insets = new java.awt.Insets (0, 10, 11, 9); 82 jPanel1.add(titleLabel, gridBagConstraints); 83 84 nicknameTextField.setInputVerifier(new NicknameNormalizer()); 85 nicknameTextField.addFocusListener(new java.awt.event.FocusAdapter () { 86 public void focusGained(java.awt.event.FocusEvent evt) { 87 focus(evt); 88 } 89 }); 90 nicknameTextField.addKeyListener(new java.awt.event.KeyAdapter () { 91 public void keyTyped(java.awt.event.KeyEvent evt) { 92 UserInput.this.keyTyped(evt); 93 } 94 }); 95 96 gridBagConstraints = new java.awt.GridBagConstraints (); 97 gridBagConstraints.gridx = 1; 98 gridBagConstraints.gridy = 1; 99 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 100 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 101 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 102 gridBagConstraints.insets = new java.awt.Insets (0, 0, 11, 11); 103 jPanel1.add(nicknameTextField, gridBagConstraints); 104 105 levelLabel.setFont(new java.awt.Font ("Lucida Grande", 1, 13)); 106 levelLabel.setText("Select your level as a NetBeans user:"); 107 levelLabel.setFocusable(false); 108 gridBagConstraints = new java.awt.GridBagConstraints (); 109 gridBagConstraints.gridx = 0; 110 gridBagConstraints.gridy = 2; 111 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 112 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 113 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 114 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 11); 115 jPanel1.add(levelLabel, gridBagConstraints); 116 117 buttonGroup.add(level1RadioButton); 118 level1RadioButton.setText(LEVEL1); 119 gridBagConstraints = new java.awt.GridBagConstraints (); 120 gridBagConstraints.gridx = 1; 121 gridBagConstraints.gridy = 3; 122 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 123 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 124 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 11); 125 jPanel1.add(level1RadioButton, gridBagConstraints); 126 127 buttonGroup.add(level2RadioButton); 128 level2RadioButton.setText(LEVEL2); 129 130 gridBagConstraints = new java.awt.GridBagConstraints (); 131 gridBagConstraints.gridx = 1; 132 gridBagConstraints.gridy = 4; 133 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 134 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 135 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 11); 136 jPanel1.add(level2RadioButton, gridBagConstraints); 137 138 buttonGroup.add(level3RadioButton); 139 level3RadioButton.setText(LEVEL3); 140 level2RadioButton.setSelected(true); 141 gridBagConstraints = new java.awt.GridBagConstraints (); 142 gridBagConstraints.gridx = 1; 143 gridBagConstraints.gridy = 5; 144 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 145 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 146 gridBagConstraints.weighty = 1.0; 147 gridBagConstraints.insets = new java.awt.Insets (0, 0, 0, 11); 148 jPanel1.add(level3RadioButton, gridBagConstraints); 149 150 nameLabel.setFont(new java.awt.Font ("Lucida Grande", 1, 13)); 151 nameLabel.setText("Name: "); 152 gridBagConstraints = new java.awt.GridBagConstraints (); 153 gridBagConstraints.gridx = 0; 154 gridBagConstraints.gridy = 1; 155 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 156 gridBagConstraints.insets = new java.awt.Insets (0, 12, 11, 0); 157 jPanel1.add(nameLabel, gridBagConstraints); 158 159 jPanel2.setLayout(new java.awt.FlowLayout (java.awt.FlowLayout.CENTER, 5, 0)); 160 161 helpButton.setText("Help"); 162 helpButton.setEnabled(false); 163 jPanel2.add(helpButton); 164 165 okButton.setText("OK"); 166 okButton.setEnabled(false); 167 okButton.addMouseListener(new java.awt.event.MouseAdapter () { 168 public void mouseClicked(java.awt.event.MouseEvent evt) { 169 okButtonClicked(evt); 170 } 171 }); 172 173 jPanel2.add(okButton); 174 175 gridBagConstraints = new java.awt.GridBagConstraints (); 176 gridBagConstraints.gridx = 1; 177 gridBagConstraints.gridy = 6; 178 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHEAST; 179 jPanel1.add(jPanel2, gridBagConstraints); 180 181 getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER); 182 183 pack(); 184 } 185 186 private void focus(java.awt.event.FocusEvent evt) { 187 nicknameTextField.setText(""); 188 } 189 190 private void keyTyped(java.awt.event.KeyEvent evt) { 191 if(!typed) { 192 typed = true; 193 okButton.setEnabled(true); 194 } 195 } 196 197 private void okButtonClicked(java.awt.event.MouseEvent evt) { 198 if(nickname.length()!=0){ 199 if(level1RadioButton.isSelected()){ 200 level = LEVEL1; 201 } else if (level2RadioButton.isSelected()){ 202 level = LEVEL2; 203 } else if (level3RadioButton.isSelected()){ 204 level = LEVEL3; 205 } 206 level = level.split("\\s+")[0]; 207 ListenerTools.saveParameters(level, nickname); 208 main.wakeUp(); 209 this.dispose(); 210 } else { 211 typed = false; 212 okButton.setEnabled(false); 213 } 214 } 215 216 220 public static void main(String args[]) { 221 java.awt.EventQueue.invokeLater(new Runnable () { 222 public void run() { 223 new UserInput(null).setVisible(true); 224 } 225 }); 226 } 227 228 private class NicknameNormalizer extends javax.swing.InputVerifier { 229 public boolean verify(javax.swing.JComponent input) { 230 javax.swing.JTextField tf = (javax.swing.JTextField ) input; 231 nickname = tf.getText(); 232 StringBuffer buffer = new StringBuffer (); 233 for(int i=0; i<nickname.length(); i++){ 234 char c = nickname.charAt(i); 235 if(Character.isLetterOrDigit(c)) buffer.append(c); 236 } 237 nickname = buffer.toString(); 238 tf.setText(nickname); 239 return nickname.length() != 0; 240 } 241 } 242 243 private javax.swing.ButtonGroup buttonGroup; 244 private javax.swing.JButton helpButton; 245 private javax.swing.JLabel levelLabel; 246 private javax.swing.JPanel jPanel1; 247 private javax.swing.JPanel jPanel2; 248 private javax.swing.JPanel jPanel3; 249 private javax.swing.JRadioButton level1RadioButton; 250 private javax.swing.JRadioButton level2RadioButton; 251 private javax.swing.JRadioButton level3RadioButton; 252 private javax.swing.JLabel nameLabel; 253 private javax.swing.JTextField nicknameTextField; 254 private javax.swing.JButton okButton; 255 private javax.swing.JLabel titleLabel; 256 257 } 258 | Popular Tags |