1 31 32 package org.antlr.works.dialog; 33 34 import com.jgoodies.forms.factories.Borders; 35 import com.jgoodies.forms.factories.FormFactory; 36 import com.jgoodies.forms.layout.*; 37 import org.antlr.works.prefs.AWPrefs; 38 import org.antlr.works.stats.StatisticsReporter; 39 import org.antlr.works.utils.IconManager; 40 import org.antlr.works.utils.Localizable; 41 import org.antlr.xjlib.appkit.frame.XJDialog; 42 43 import javax.swing.*; 44 import java.awt.*; 45 import java.awt.event.ActionEvent ; 46 import java.awt.event.ActionListener ; 47 import java.util.HashMap ; 48 import java.util.Map ; 49 50 public class DialogPersonalInfo extends XJDialog { 51 52 public static final String INFO_WHO = "who"; 53 public static final String INFO_SECTOR = "sector"; 54 public static final String INFO_DEVTOOL = "devtool"; 55 public static final String INFO_YEARSLANG = "yearslang"; 56 public static final String INFO_YEARSPROG = "yearsprog"; 57 public static final String INFO_RESIDING = "residing"; 58 public static final String INFO_CAFFEINE = "caffeine"; 59 60 public DialogPersonalInfo(Container parent) { 61 super(parent, true); 62 63 initComponents(); 64 65 setSize(780, 550); 66 iconButton.setIcon(IconManager.shared().getIconApplication()); 67 setTitle(Localizable.getLocalizedString(Localizable.APP_NAME)+" "+Localizable.getLocalizedString(Localizable.APP_VERSION_LONG)); 68 69 setCancelButton(cancelButton); 71 setDefaultButton(okButton); 72 setOKButton(okButton); 73 74 whoCombo.setSelectedIndex(-1); 75 whoCombo.addActionListener(new MyActionListener()); 76 sectorCombo.setSelectedIndex(-1); 77 sectorCombo.addActionListener(new MyActionListener()); 78 devtoolCombo.setSelectedIndex(-1); 79 devtoolCombo.addActionListener(new MyActionListener()); 80 81 okButton.setEnabled(false); 82 } 83 84 public void dialogWillCloseCancel() { 85 86 87 requestAndRegisterID(); 88 } 89 90 public void dialogWillCloseOK() { 91 Map <String ,Object > info = new HashMap <String , Object >(); 92 info.put(INFO_WHO, whoCombo.getSelectedIndex()); 93 info.put(INFO_SECTOR, sectorCombo.getSelectedIndex()); 94 info.put(INFO_DEVTOOL, devtoolCombo.getSelectedIndex()); 95 info.put(INFO_YEARSLANG, languageExperienceSpinner.getValue()); 96 info.put(INFO_YEARSPROG, programmingExperienceSpinner.getValue()); 97 info.put(INFO_RESIDING, countryField.getText()); 98 info.put(INFO_CAFFEINE, funField.getText()); 99 AWPrefs.setPersonalInfo(info); 100 101 requestAndRegisterID(); 102 } 103 104 public void requestAndRegisterID() { 105 StatisticsReporter sr = new StatisticsReporter(); 106 String id = sr.getID(); 107 if(id == null) { 108 System.err.println("Cannot send info ="+sr.getError()+"\nID is null."); 109 } 110 } 111 112 protected class MyActionListener implements ActionListener { 113 public void actionPerformed(ActionEvent event) { 114 okButton.setEnabled(whoCombo.getSelectedIndex() > -1 && sectorCombo.getSelectedIndex() > -1 115 && devtoolCombo.getSelectedIndex() > -1); 116 } 117 } 118 119 private void initComponents() { 120 dialogPane = new JPanel(); 123 contentPane = new JPanel(); 124 iconButton = new JButton(); 125 label6 = new JLabel(); 126 textArea1 = new JTextArea(); 127 whoCombo = new JComboBox(); 128 label1 = new JLabel(); 129 sectorCombo = new JComboBox(); 130 label7 = new JLabel(); 131 label8 = new JLabel(); 132 devtoolCombo = new JComboBox(); 133 languageExperienceSpinner = new JSpinner(); 134 label2 = new JLabel(); 135 programmingExperienceSpinner = new JSpinner(); 136 label3 = new JLabel(); 137 countryField = new JTextField(); 138 label4 = new JLabel(); 139 funField = new JTextField(); 140 label5 = new JLabel(); 141 buttonBar = new JPanel(); 142 cancelButton = new JButton(); 143 okButton = new JButton(); 144 CellConstraints cc = new CellConstraints(); 145 146 setTitle("ANTLRWorks early access 1"); 148 Container contentPane2 = getContentPane(); 149 contentPane2.setLayout(new BorderLayout()); 150 151 { 153 dialogPane.setBorder(Borders.DIALOG_BORDER); 154 dialogPane.setPreferredSize(new Dimension(750, 500)); 155 dialogPane.setLayout(new BorderLayout()); 156 157 { 159 contentPane.setLayout(new FormLayout( 160 new ColumnSpec[] { 161 FormFactory.DEFAULT_COLSPEC, 162 FormFactory.LABEL_COMPONENT_GAP_COLSPEC, 163 new ColumnSpec(Sizes.dluX(50)), 164 FormFactory.LABEL_COMPONENT_GAP_COLSPEC, 165 new ColumnSpec("max(min;100dlu):grow"), 166 FormFactory.LABEL_COMPONENT_GAP_COLSPEC, 167 new ColumnSpec("max(default;30dlu)"), 168 FormFactory.LABEL_COMPONENT_GAP_COLSPEC, 169 FormFactory.DEFAULT_COLSPEC 170 }, 171 new RowSpec[] { 172 new RowSpec(RowSpec.FILL, Sizes.DEFAULT, FormSpec.NO_GROW), 173 FormFactory.LINE_GAP_ROWSPEC, 174 new RowSpec(Sizes.DLUY5), 175 FormFactory.LINE_GAP_ROWSPEC, 176 FormFactory.DEFAULT_ROWSPEC, 177 FormFactory.LINE_GAP_ROWSPEC, 178 new RowSpec(Sizes.DLUY5), 179 FormFactory.LINE_GAP_ROWSPEC, 180 FormFactory.DEFAULT_ROWSPEC, 181 FormFactory.LINE_GAP_ROWSPEC, 182 FormFactory.DEFAULT_ROWSPEC, 183 FormFactory.LINE_GAP_ROWSPEC, 184 FormFactory.DEFAULT_ROWSPEC, 185 FormFactory.LINE_GAP_ROWSPEC, 186 FormFactory.DEFAULT_ROWSPEC, 187 FormFactory.LINE_GAP_ROWSPEC, 188 FormFactory.DEFAULT_ROWSPEC, 189 FormFactory.LINE_GAP_ROWSPEC, 190 FormFactory.DEFAULT_ROWSPEC, 191 FormFactory.LINE_GAP_ROWSPEC, 192 FormFactory.DEFAULT_ROWSPEC, 193 FormFactory.LINE_GAP_ROWSPEC, 194 FormFactory.DEFAULT_ROWSPEC, 195 FormFactory.LINE_GAP_ROWSPEC, 196 FormFactory.DEFAULT_ROWSPEC, 197 FormFactory.LINE_GAP_ROWSPEC, 198 FormFactory.DEFAULT_ROWSPEC, 199 FormFactory.LINE_GAP_ROWSPEC, 200 FormFactory.DEFAULT_ROWSPEC, 201 FormFactory.LINE_GAP_ROWSPEC, 202 FormFactory.DEFAULT_ROWSPEC, 203 FormFactory.LINE_GAP_ROWSPEC, 204 FormFactory.DEFAULT_ROWSPEC, 205 FormFactory.LINE_GAP_ROWSPEC, 206 FormFactory.DEFAULT_ROWSPEC, 207 FormFactory.LINE_GAP_ROWSPEC, 208 new RowSpec(RowSpec.CENTER, Sizes.DEFAULT, FormSpec.DEFAULT_GROW) 209 })); 210 211 iconButton.setBorder(null); 213 iconButton.setIcon(null); 214 iconButton.setEnabled(true); 215 iconButton.setFocusable(false); 216 iconButton.setFocusPainted(false); 217 iconButton.setBorderPainted(false); 218 iconButton.setContentAreaFilled(false); 219 iconButton.setDefaultCapable(false); 220 iconButton.setRequestFocusEnabled(false); 221 iconButton.setOpaque(false); 222 iconButton.setVerifyInputWhenFocusTarget(false); 223 iconButton.setVerticalAlignment(SwingConstants.TOP); 224 contentPane.add(iconButton, cc.xywh(1, 1, 1, 37)); 225 226 label6.setText("Welcome to ANTLRWorks!"); 228 label6.setFont(new Font("Lucida Grande", Font.PLAIN, 20)); 229 contentPane.add(label6, cc.xywh(3, 1, 5, 1)); 230 231 textArea1.setText("Please take a few seconds to fill out some information about yourself to help us improve our products. Thank you!"); 233 textArea1.setEditable(false); 234 textArea1.setOpaque(false); 235 textArea1.setWrapStyleWord(true); 236 textArea1.setLineWrap(true); 237 textArea1.setBackground(UIManager.getColor("window")); 238 contentPane.add(textArea1, cc.xywh(3, 5, 5, 1)); 239 240 whoCombo.setModel(new DefaultComboBoxModel(new String [] { 242 "Professional programmer", 243 "Researcher", 244 "Graduate student", 245 "Undergraduate student", 246 "Professor" 247 })); 248 contentPane.add(whoCombo, cc.xywh(3, 11, 3, 1)); 249 250 label1.setText("Who are you?"); 252 label1.setHorizontalAlignment(SwingConstants.LEFT); 253 contentPane.add(label1, cc.xywh(3, 9, 3, 1)); 254 255 sectorCombo.setModel(new DefaultComboBoxModel(new String [] { 257 "Industry", 258 "Government", 259 "Academia", 260 "Military", 261 "Other" 262 })); 263 contentPane.add(sectorCombo, cc.xywh(3, 15, 3, 1)); 264 265 label7.setText("What is your sector of activity?"); 267 label7.setHorizontalAlignment(SwingConstants.LEFT); 268 contentPane.add(label7, cc.xywh(3, 13, 3, 1)); 269 270 label8.setText("What is your primary development environment?"); 272 contentPane.add(label8, cc.xywh(3, 17, 3, 1)); 273 274 devtoolCombo.setModel(new DefaultComboBoxModel(new String [] { 276 "Eclipse", 277 "IntelliJ", 278 "Microsoft Visual Studio", 279 "Borland JBuilder", 280 "Xcode", 281 "Text Editor (vi, emacs) - hardcore old-school \"I don't need no stinkin' IDE coder\"", 282 "Other" 283 })); 284 contentPane.add(devtoolCombo, cc.xywh(3, 19, 3, 1)); 285 286 languageExperienceSpinner.setModel(new SpinnerNumberModel(0, 0, null, 1)); 288 contentPane.add(languageExperienceSpinner, cc.xy(3, 23)); 289 290 label2.setText("How many years of experience with language translation/implementation?"); 292 label2.setHorizontalAlignment(SwingConstants.LEFT); 293 contentPane.add(label2, cc.xywh(3, 21, 3, 1)); 294 295 programmingExperienceSpinner.setModel(new SpinnerNumberModel(0, 0, null, 1)); 297 contentPane.add(programmingExperienceSpinner, cc.xy(3, 27)); 298 299 label3.setText("How many years of programming experience?"); 301 label3.setHorizontalAlignment(SwingConstants.LEFT); 302 contentPane.add(label3, cc.xywh(3, 25, 3, 1)); 303 contentPane.add(countryField, cc.xywh(3, 31, 3, 1)); 304 305 label4.setText("In which country do you currently live?"); 307 label4.setHorizontalAlignment(SwingConstants.LEFT); 308 contentPane.add(label4, cc.xywh(3, 29, 3, 1)); 309 contentPane.add(funField, cc.xywh(3, 35, 3, 1)); 310 311 label5.setText("What is your preferred caffeinated beverage?"); 313 label5.setHorizontalAlignment(SwingConstants.LEFT); 314 contentPane.add(label5, cc.xywh(3, 33, 3, 1)); 315 } 316 dialogPane.add(contentPane, BorderLayout.CENTER); 317 318 { 320 buttonBar.setBorder(Borders.BUTTON_BAR_GAP_BORDER); 321 buttonBar.setLayout(new FormLayout( 322 new ColumnSpec[] { 323 FormFactory.GLUE_COLSPEC, 324 FormFactory.LABEL_COMPONENT_GAP_COLSPEC, 325 FormFactory.DEFAULT_COLSPEC, 326 FormFactory.BUTTON_COLSPEC 327 }, 328 RowSpec.decodeSpecs("pref"))); 329 330 cancelButton.setText("Don't Send"); 332 buttonBar.add(cancelButton, cc.xy(3, 1)); 333 334 okButton.setText("Send"); 336 buttonBar.add(okButton, cc.xy(4, 1)); 337 } 338 dialogPane.add(buttonBar, BorderLayout.SOUTH); 339 } 340 contentPane2.add(dialogPane, BorderLayout.CENTER); 341 pack(); 342 } 344 345 private JPanel dialogPane; 348 private JPanel contentPane; 349 private JButton iconButton; 350 private JLabel label6; 351 private JTextArea textArea1; 352 private JComboBox whoCombo; 353 private JLabel label1; 354 private JComboBox sectorCombo; 355 private JLabel label7; 356 private JLabel label8; 357 private JComboBox devtoolCombo; 358 private JSpinner languageExperienceSpinner; 359 private JLabel label2; 360 private JSpinner programmingExperienceSpinner; 361 private JLabel label3; 362 private JTextField countryField; 363 private JLabel label4; 364 private JTextField funField; 365 private JLabel label5; 366 private JPanel buttonBar; 367 private JButton cancelButton; 368 private JButton okButton; 369 371 } 372 | Popular Tags |