1 19 20 package org.netbeans.modules.java.j2seproject.ui.customizer; 21 22 import java.awt.Component ; 23 import java.awt.Dialog ; 24 import java.awt.Font ; 25 import java.awt.event.ActionEvent ; 26 import java.awt.event.ActionListener ; 27 import java.awt.event.MouseEvent ; 28 import java.io.File ; 29 import java.text.Collator ; 30 import java.util.Comparator ; 31 import java.util.HashMap ; 32 import java.util.Map ; 33 import java.util.SortedSet ; 34 import java.util.TreeSet ; 35 import javax.swing.DefaultComboBoxModel ; 36 import javax.swing.DefaultListCellRenderer ; 37 import javax.swing.JButton ; 38 import javax.swing.JComponent ; 39 import javax.swing.JFileChooser ; 40 import javax.swing.JLabel ; 41 import javax.swing.JList ; 42 import javax.swing.JPanel ; 43 import javax.swing.JTextField ; 44 import javax.swing.ListCellRenderer ; 45 import javax.swing.event.ChangeEvent ; 46 import javax.swing.event.ChangeListener ; 47 import javax.swing.event.DocumentEvent ; 48 import javax.swing.event.DocumentListener ; 49 import javax.swing.plaf.UIResource ; 50 import org.netbeans.api.project.Project; 51 import org.netbeans.modules.java.j2seproject.J2SEProject; 52 import org.netbeans.modules.java.j2seproject.SourceRoots; 53 import org.netbeans.modules.java.j2seproject.api.J2SERunConfigProvider; 54 import org.openide.DialogDescriptor; 55 import org.openide.DialogDisplayer; 56 import org.openide.NotifyDescriptor; 57 import org.openide.awt.MouseUtils; 58 import org.openide.filesystems.FileUtil; 59 import org.openide.util.HelpCtx; 60 import org.openide.util.Lookup; 61 import org.openide.util.NbBundle; 62 import org.openide.util.Utilities; 63 64 public class CustomizerRun extends JPanel implements HelpCtx.Provider { 65 66 private J2SEProject project; 67 68 private JTextField [] data; 69 private JLabel [] dataLabels; 70 private String [] keys; 71 private Map <String ,Map <String ,String >> configs; 72 J2SEProjectProperties uiProperties; 73 74 private J2SERunConfigProvider compProvider; 75 76 public CustomizerRun( J2SEProjectProperties uiProperties ) { 77 this.uiProperties = uiProperties; 78 initComponents(); 79 80 this.project = uiProperties.getProject(); 81 82 compProvider = Lookup.getDefault().lookup(J2SERunConfigProvider.class); 83 initExtPanel(project); 84 85 configs = uiProperties.RUN_CONFIGS; 86 87 data = new JTextField [] { 88 jTextFieldMainClass, 89 jTextFieldArgs, 90 jTextVMOptions, 91 jTextWorkingDirectory, 92 }; 93 dataLabels = new JLabel [] { 94 jLabelMainClass, 95 jLabelArgs, 96 jLabelVMOptions, 97 jLabelWorkingDirectory, 98 }; 99 keys = new String [] { 100 J2SEProjectProperties.MAIN_CLASS, 101 J2SEProjectProperties.APPLICATION_ARGS, 102 J2SEProjectProperties.RUN_JVM_ARGS, 103 J2SEProjectProperties.RUN_WORK_DIR, 104 }; 105 assert data.length == keys.length; 106 107 configChanged(uiProperties.activeConfig); 108 109 configCombo.setRenderer(new ConfigListCellRenderer()); 110 111 for (int i = 0; i < data.length; i++) { 112 final JTextField field = data[i]; 113 final String prop = keys[i]; 114 final JLabel label = dataLabels[i]; 115 field.getDocument().addDocumentListener(new DocumentListener () { 116 Font basefont = label.getFont(); 117 Font boldfont = basefont.deriveFont(Font.BOLD); 118 { 119 updateFont(); 120 } 121 public void insertUpdate(DocumentEvent e) { 122 changed(); 123 } 124 public void removeUpdate(DocumentEvent e) { 125 changed(); 126 } 127 public void changedUpdate(DocumentEvent e) {} 128 void changed() { 129 String config = (String ) configCombo.getSelectedItem(); 130 if (config.length() == 0) { 131 config = null; 132 } 133 String v = field.getText(); 134 if (v != null && config != null && v.equals(configs.get(null).get(prop))) { 135 v = null; 137 } 138 configs.get(config).put(prop, v); 139 updateFont(); 140 } 141 void updateFont() { 142 String v = field.getText(); 143 String config = (String ) configCombo.getSelectedItem(); 144 if (config.length() == 0) { 145 config = null; 146 } 147 String def = configs.get(null).get(prop); 148 label.setFont(config != null && !Utilities.compareObjects(v != null ? v : "", def != null ? def : "") ? boldfont : basefont); 149 } 150 }); 151 } 152 153 jButtonMainClass.addActionListener( new MainClassListener( project.getSourceRoots(), jTextFieldMainClass ) ); 154 } 155 156 public HelpCtx getHelpCtx() { 157 return new HelpCtx( CustomizerRun.class ); 158 } 159 160 165 private void initComponents() { 167 java.awt.GridBagConstraints gridBagConstraints; 168 169 configSep = new javax.swing.JSeparator (); 170 configPanel = new javax.swing.JPanel (); 171 configLabel = new javax.swing.JLabel (); 172 configCombo = new javax.swing.JComboBox (); 173 configNew = new javax.swing.JButton (); 174 configDel = new javax.swing.JButton (); 175 mainPanel = new javax.swing.JPanel (); 176 jLabelMainClass = new javax.swing.JLabel (); 177 jTextFieldMainClass = new javax.swing.JTextField (); 178 jButtonMainClass = new javax.swing.JButton (); 179 jLabelArgs = new javax.swing.JLabel (); 180 jTextFieldArgs = new javax.swing.JTextField (); 181 jLabelWorkingDirectory = new javax.swing.JLabel (); 182 jTextWorkingDirectory = new javax.swing.JTextField (); 183 jButtonWorkingDirectoryBrowse = new javax.swing.JButton (); 184 jLabelVMOptions = new javax.swing.JLabel (); 185 jTextVMOptions = new javax.swing.JTextField (); 186 jLabelVMOptionsExample = new javax.swing.JLabel (); 187 extPanel = new javax.swing.JPanel (); 188 189 setLayout(new java.awt.GridBagLayout ()); 190 gridBagConstraints = new java.awt.GridBagConstraints (); 191 gridBagConstraints.gridx = 0; 192 gridBagConstraints.gridy = 1; 193 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 194 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 195 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 196 add(configSep, gridBagConstraints); 197 198 configPanel.setLayout(new java.awt.GridBagLayout ()); 199 200 configLabel.setLabelFor(configCombo); 201 org.openide.awt.Mnemonics.setLocalizedText(configLabel, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 203 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 204 gridBagConstraints.insets = new java.awt.Insets (2, 0, 2, 0); 205 configPanel.add(configLabel, gridBagConstraints); 206 207 configCombo.setModel(new javax.swing.DefaultComboBoxModel (new String [] { "<default>" })); 208 configCombo.addActionListener(new java.awt.event.ActionListener () { 209 public void actionPerformed(java.awt.event.ActionEvent evt) { 210 configComboActionPerformed(evt); 211 } 212 }); 213 gridBagConstraints = new java.awt.GridBagConstraints (); 214 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 215 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 216 gridBagConstraints.weightx = 1.0; 217 gridBagConstraints.insets = new java.awt.Insets (2, 6, 2, 0); 218 configPanel.add(configCombo, gridBagConstraints); 219 220 org.openide.awt.Mnemonics.setLocalizedText(configNew, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configNew")); configNew.addActionListener(new java.awt.event.ActionListener () { 222 public void actionPerformed(java.awt.event.ActionEvent evt) { 223 configNewActionPerformed(evt); 224 } 225 }); 226 gridBagConstraints = new java.awt.GridBagConstraints (); 227 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 228 gridBagConstraints.insets = new java.awt.Insets (2, 6, 2, 0); 229 configPanel.add(configNew, gridBagConstraints); 230 231 org.openide.awt.Mnemonics.setLocalizedText(configDel, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configDelete")); configDel.addActionListener(new java.awt.event.ActionListener () { 233 public void actionPerformed(java.awt.event.ActionEvent evt) { 234 configDelActionPerformed(evt); 235 } 236 }); 237 gridBagConstraints = new java.awt.GridBagConstraints (); 238 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 239 gridBagConstraints.insets = new java.awt.Insets (2, 6, 2, 0); 240 configPanel.add(configDel, gridBagConstraints); 241 242 gridBagConstraints = new java.awt.GridBagConstraints (); 243 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 244 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 245 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 246 add(configPanel, gridBagConstraints); 247 248 mainPanel.setLayout(new java.awt.GridBagLayout ()); 249 250 jLabelMainClass.setLabelFor(jTextFieldMainClass); 251 org.openide.awt.Mnemonics.setLocalizedText(jLabelMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 253 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 254 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 255 mainPanel.add(jLabelMainClass, gridBagConstraints); 256 gridBagConstraints = new java.awt.GridBagConstraints (); 257 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 258 gridBagConstraints.weightx = 1.0; 259 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 260 mainPanel.add(jTextFieldMainClass, gridBagConstraints); 261 jTextFieldMainClass.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jTextFieldMainClass")); 263 org.openide.awt.Mnemonics.setLocalizedText(jButtonMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JButton")); gridBagConstraints = new java.awt.GridBagConstraints (); 265 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 266 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 267 gridBagConstraints.insets = new java.awt.Insets (0, 6, 5, 0); 268 mainPanel.add(jButtonMainClass, gridBagConstraints); 269 jButtonMainClass.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jButtonMainClass")); 271 jLabelArgs.setLabelFor(jTextFieldArgs); 272 org.openide.awt.Mnemonics.setLocalizedText(jLabelArgs, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Args_JLabel")); gridBagConstraints = new java.awt.GridBagConstraints (); 274 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 275 gridBagConstraints.insets = new java.awt.Insets (0, 0, 12, 0); 276 mainPanel.add(jLabelArgs, gridBagConstraints); 277 gridBagConstraints = new java.awt.GridBagConstraints (); 278 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 279 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 280 gridBagConstraints.weightx = 1.0; 281 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 0); 282 mainPanel.add(jTextFieldArgs, gridBagConstraints); 283 jTextFieldArgs.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jTextFieldArgs")); 285 jLabelWorkingDirectory.setLabelFor(jTextWorkingDirectory); 286 org.openide.awt.Mnemonics.setLocalizedText(jLabelWorkingDirectory, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory")); gridBagConstraints = new java.awt.GridBagConstraints (); 288 gridBagConstraints.gridy = 2; 289 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 290 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 291 mainPanel.add(jLabelWorkingDirectory, gridBagConstraints); 292 gridBagConstraints = new java.awt.GridBagConstraints (); 293 gridBagConstraints.gridy = 2; 294 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 295 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 296 gridBagConstraints.weightx = 1.0; 297 gridBagConstraints.insets = new java.awt.Insets (0, 12, 5, 0); 298 mainPanel.add(jTextWorkingDirectory, gridBagConstraints); 299 java.util.ResourceBundle bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle"); jTextWorkingDirectory.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_Working_Directory ")); 302 org.openide.awt.Mnemonics.setLocalizedText(jButtonWorkingDirectoryBrowse, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse")); jButtonWorkingDirectoryBrowse.addActionListener(new java.awt.event.ActionListener () { 304 public void actionPerformed(java.awt.event.ActionEvent evt) { 305 jButtonWorkingDirectoryBrowseActionPerformed(evt); 306 } 307 }); 308 gridBagConstraints = new java.awt.GridBagConstraints (); 309 gridBagConstraints.gridy = 2; 310 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 311 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 312 gridBagConstraints.insets = new java.awt.Insets (0, 6, 5, 0); 313 mainPanel.add(jButtonWorkingDirectoryBrowse, gridBagConstraints); 314 jButtonWorkingDirectoryBrowse.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_Working_Directory_Browse")); 316 jLabelVMOptions.setLabelFor(jTextVMOptions); 317 org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptions, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options")); gridBagConstraints = new java.awt.GridBagConstraints (); 319 gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST; 320 gridBagConstraints.insets = new java.awt.Insets (0, 0, 5, 0); 321 mainPanel.add(jLabelVMOptions, gridBagConstraints); 322 gridBagConstraints = new java.awt.GridBagConstraints (); 323 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 324 gridBagConstraints.weightx = 1.0; 325 gridBagConstraints.insets = new java.awt.Insets (0, 12, 0, 0); 326 mainPanel.add(jTextVMOptions, gridBagConstraints); 327 jTextVMOptions.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_VM_Options")); 329 jLabelVMOptionsExample.setLabelFor(jTextFieldMainClass); 330 org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptionsExample, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options_Example")); gridBagConstraints = new java.awt.GridBagConstraints (); 332 gridBagConstraints.gridx = 1; 333 gridBagConstraints.gridy = 4; 334 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 335 gridBagConstraints.weighty = 1.0; 336 gridBagConstraints.insets = new java.awt.Insets (0, 12, 12, 0); 337 mainPanel.add(jLabelVMOptionsExample, gridBagConstraints); 338 jLabelVMOptionsExample.getAccessibleContext().setAccessibleDescription(bundle.getString("LBL_CustomizeRun_Run_VM_Options_Example")); 340 gridBagConstraints = new java.awt.GridBagConstraints (); 341 gridBagConstraints.gridx = 0; 342 gridBagConstraints.gridy = 2; 343 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 344 gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 345 gridBagConstraints.weightx = 1.0; 346 gridBagConstraints.insets = new java.awt.Insets (6, 0, 6, 0); 347 add(mainPanel, gridBagConstraints); 348 349 extPanel.setLayout(new java.awt.GridBagLayout ()); 350 gridBagConstraints = new java.awt.GridBagConstraints (); 351 gridBagConstraints.gridx = 0; 352 gridBagConstraints.gridy = 3; 353 gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER; 354 gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER; 355 gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH; 356 gridBagConstraints.weightx = 1.0; 357 gridBagConstraints.weighty = 1.0; 358 add(extPanel, gridBagConstraints); 359 } 361 private void initExtPanel(Project p) { 362 if (compProvider != null) { 363 J2SERunConfigProvider.ConfigChangeListener ccl = new J2SERunConfigProvider.ConfigChangeListener() { 364 public void propertiesChanged(Map <String , String > updates) { 365 Map <String ,String > m = configs.get(uiProperties.activeConfig); 367 m.putAll(updates); 368 } 369 }; 370 JComponent comp = compProvider.createComponent(p, ccl); 371 if (comp != null) { 372 java.awt.GridBagConstraints constraints = new java.awt.GridBagConstraints (); 373 constraints.anchor = java.awt.GridBagConstraints.NORTHWEST; 374 constraints.gridx = 0; 375 constraints.gridy = 0; 376 constraints.weightx = 1.0; 377 constraints.weighty = 1.0; 378 extPanel.add(comp, constraints); 379 } 380 } 381 } 382 383 private void configDelActionPerformed(java.awt.event.ActionEvent evt) { String config = (String ) configCombo.getSelectedItem(); 385 assert config != null; 386 configs.put(config, null); 387 configChanged(null); 388 uiProperties.activeConfig = null; 389 } 391 private void configNewActionPerformed(java.awt.event.ActionEvent evt) { NotifyDescriptor.InputLine d = new NotifyDescriptor.InputLine( 393 NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.input.prompt"), 394 NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.input.title")); 395 if (DialogDisplayer.getDefault().notify(d) != NotifyDescriptor.OK_OPTION) { 396 return; 397 } 398 String name = d.getInputText(); 399 String config = name.replaceAll("[^a-zA-Z0-9_.-]", "_"); if (configs.get(config) != null) { 401 DialogDisplayer.getDefault().notify(new NotifyDescriptor.Message( 402 NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.input.duplicate", config), 403 NotifyDescriptor.WARNING_MESSAGE)); 404 return; 405 } 406 Map <String ,String > m = new HashMap <String ,String >(); 407 if (!name.equals(config)) { 408 m.put("$label", name); } 410 configs.put(config, m); 411 configChanged(config); 412 uiProperties.activeConfig = config; 413 } 415 private void configComboActionPerformed(java.awt.event.ActionEvent evt) { String config = (String ) configCombo.getSelectedItem(); 417 if (config.length() == 0) { 418 config = null; 419 } 420 configChanged(config); 421 uiProperties.activeConfig = config; 422 } 424 private void jButtonWorkingDirectoryBrowseActionPerformed(java.awt.event.ActionEvent evt) { JFileChooser chooser = new JFileChooser (); 426 FileUtil.preventFileChooserSymlinkTraversal(chooser, null); 427 chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY); 428 chooser.setMultiSelectionEnabled(false); 429 430 String workDir = jTextWorkingDirectory.getText(); 431 if (workDir.equals("")) { 432 workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath(); 433 } 434 chooser.setSelectedFile(new File (workDir)); 435 chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title")); 436 if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { File file = FileUtil.normalizeFile(chooser.getSelectedFile()); 438 jTextWorkingDirectory.setText(file.getAbsolutePath()); 439 } 440 } 442 private void configChanged(String activeConfig) { 443 DefaultComboBoxModel model = new DefaultComboBoxModel (); 444 model.addElement(""); 445 SortedSet <String > alphaConfigs = new TreeSet <String >(new Comparator <String >() { 446 Collator coll = Collator.getInstance(); 447 public int compare(String s1, String s2) { 448 return coll.compare(label(s1), label(s2)); 449 } 450 private String label(String c) { 451 Map <String ,String > m = configs.get(c); 452 String label = m.get("$label"); return label != null ? label : c; 454 } 455 }); 456 for (Map.Entry <String ,Map <String ,String >> entry : configs.entrySet()) { 457 String config = entry.getKey(); 458 if (config != null && entry.getValue() != null) { 459 alphaConfigs.add(config); 460 } 461 } 462 for (String c : alphaConfigs) { 463 model.addElement(c); 464 } 465 configCombo.setModel(model); 466 configCombo.setSelectedItem(activeConfig != null ? activeConfig : ""); 467 Map <String ,String > m = configs.get(activeConfig); 468 Map <String ,String > def = configs.get(null); 469 if (m != null) { 470 if (compProvider != null) { 471 compProvider.configUpdated(m); 472 } 473 for (int i = 0; i < data.length; i++) { 474 String v = m.get(keys[i]); 475 if (v == null) { 476 v = def.get(keys[i]); 478 } 479 data[i].setText(v); 480 } 481 } configDel.setEnabled(activeConfig != null); 483 } 484 485 486 private javax.swing.JComboBox configCombo; 488 private javax.swing.JButton configDel; 489 private javax.swing.JLabel configLabel; 490 private javax.swing.JButton configNew; 491 private javax.swing.JPanel configPanel; 492 private javax.swing.JSeparator configSep; 493 private javax.swing.JPanel extPanel; 494 private javax.swing.JButton jButtonMainClass; 495 private javax.swing.JButton jButtonWorkingDirectoryBrowse; 496 private javax.swing.JLabel jLabelArgs; 497 private javax.swing.JLabel jLabelMainClass; 498 private javax.swing.JLabel jLabelVMOptions; 499 private javax.swing.JLabel jLabelVMOptionsExample; 500 private javax.swing.JLabel jLabelWorkingDirectory; 501 private javax.swing.JTextField jTextFieldArgs; 502 private javax.swing.JTextField jTextFieldMainClass; 503 private javax.swing.JTextField jTextVMOptions; 504 private javax.swing.JTextField jTextWorkingDirectory; 505 private javax.swing.JPanel mainPanel; 506 508 509 511 private class MainClassListener implements ActionListener { 512 513 private final JButton okButton; 514 private SourceRoots sourceRoots; 515 private JTextField mainClassTextField; 516 517 MainClassListener( SourceRoots sourceRoots, JTextField mainClassTextField ) { 518 this.sourceRoots = sourceRoots; 519 this.mainClassTextField = mainClassTextField; 520 this.okButton = new JButton (NbBundle.getMessage (CustomizerRun.class, "LBL_ChooseMainClass_OK")); 521 this.okButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage (CustomizerRun.class, "AD_ChooseMainClass_OK")); 522 } 523 524 526 528 public void actionPerformed( ActionEvent e ) { 529 530 532 final MainClassChooser panel = new MainClassChooser (sourceRoots.getRoots()); 533 Object [] options = new Object [] { 534 okButton, 535 DialogDescriptor.CANCEL_OPTION 536 }; 537 panel.addChangeListener (new ChangeListener () { 538 public void stateChanged(ChangeEvent e) { 539 if (e.getSource () instanceof MouseEvent && MouseUtils.isDoubleClick (((MouseEvent )e.getSource ()))) { 540 okButton.doClick (); 542 } else { 543 okButton.setEnabled (panel.getSelectedMainClass () != null); 544 } 545 } 546 }); 547 okButton.setEnabled (false); 548 DialogDescriptor desc = new DialogDescriptor ( 549 panel, 550 NbBundle.getMessage (CustomizerRun.class, "LBL_ChooseMainClass_Title" ), 551 true, 552 options, 553 options[0], 554 DialogDescriptor.BOTTOM_ALIGN, 555 null, 556 null); 557 Dialog dlg = DialogDisplayer.getDefault ().createDialog (desc); 559 dlg.setVisible (true); 560 if (desc.getValue() == options[0]) { 561 mainClassTextField.setText (panel.getSelectedMainClass ()); 562 } 563 dlg.dispose(); 564 } 565 566 } 567 568 private final class ConfigListCellRenderer extends JLabel implements ListCellRenderer , UIResource { 569 570 public ConfigListCellRenderer () { 571 setOpaque(true); 572 } 573 574 public Component getListCellRendererComponent(JList list, Object value, int index, boolean isSelected, boolean cellHasFocus) { 575 setName("ComboBox.listRenderer"); 578 String config = (String ) value; 579 String label; 580 if (config == null) { 581 label = null; 583 } else if (config.length() > 0) { 584 Map <String ,String > m = configs.get(config); 585 label = m != null ? m.get("$label") : null; 586 if (label == null) { 587 label = config; 588 } 589 } else { 590 label = NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.default"); 591 } 592 setText(label); 593 594 if ( isSelected ) { 595 setBackground(list.getSelectionBackground()); 596 setForeground(list.getSelectionForeground()); 597 } 598 else { 599 setBackground(list.getBackground()); 600 setForeground(list.getForeground()); 601 } 602 603 return this; 604 } 605 606 public String getName() { 608 String name = super.getName(); 609 return name == null ? "ComboBox.renderer" : name; } 611 612 } 613 614 615 } 616 | Popular Tags |