KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > java > j2seproject > ui > customizer > CustomizerRun


1 /*
2  * The contents of this file are subject to the terms of the Common Development
3  * and Distribution License (the License). You may not use this file except in
4  * compliance with the License.
5  *
6  * You can obtain a copy of the License at http://www.netbeans.org/cddl.html
7  * or http://www.netbeans.org/cddl.txt.
8  *
9  * When distributing Covered Code, include this CDDL Header Notice in each file
10  * and include the License file at http://www.netbeans.org/cddl.txt.
11  * If applicable, add the following below the CDDL Header, with the fields
12  * enclosed by brackets [] replaced by your own identifying information:
13  * "Portions Copyrighted [year] [name of copyright owner]"
14  *
15  * The Original Software is NetBeans. The Initial Developer of the Original
16  * Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
17  * Microsystems, Inc. All Rights Reserved.
18  */

19
20 package org.netbeans.modules.java.j2seproject.ui.customizer;
21
22 import java.awt.Component JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Font JavaDoc;
25 import java.awt.event.ActionEvent JavaDoc;
26 import java.awt.event.ActionListener JavaDoc;
27 import java.awt.event.MouseEvent JavaDoc;
28 import java.io.File JavaDoc;
29 import java.text.Collator JavaDoc;
30 import java.util.Comparator JavaDoc;
31 import java.util.HashMap JavaDoc;
32 import java.util.Map JavaDoc;
33 import java.util.SortedSet JavaDoc;
34 import java.util.TreeSet JavaDoc;
35 import javax.swing.DefaultComboBoxModel JavaDoc;
36 import javax.swing.DefaultListCellRenderer JavaDoc;
37 import javax.swing.JButton JavaDoc;
38 import javax.swing.JComponent JavaDoc;
39 import javax.swing.JFileChooser JavaDoc;
40 import javax.swing.JLabel JavaDoc;
41 import javax.swing.JList JavaDoc;
42 import javax.swing.JPanel JavaDoc;
43 import javax.swing.JTextField JavaDoc;
44 import javax.swing.ListCellRenderer JavaDoc;
45 import javax.swing.event.ChangeEvent JavaDoc;
46 import javax.swing.event.ChangeListener JavaDoc;
47 import javax.swing.event.DocumentEvent JavaDoc;
48 import javax.swing.event.DocumentListener JavaDoc;
49 import javax.swing.plaf.UIResource JavaDoc;
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 JavaDoc implements HelpCtx.Provider {
65     
66     private J2SEProject project;
67     
68     private JTextField JavaDoc[] data;
69     private JLabel JavaDoc[] dataLabels;
70     private String JavaDoc[] keys;
71     private Map JavaDoc<String JavaDoc/*|null*/,Map JavaDoc<String JavaDoc,String JavaDoc/*|null*/>/*|null*/> 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 JavaDoc[] {
88             jTextFieldMainClass,
89             jTextFieldArgs,
90             jTextVMOptions,
91             jTextWorkingDirectory,
92         };
93         dataLabels = new JLabel JavaDoc[] {
94             jLabelMainClass,
95             jLabelArgs,
96             jLabelVMOptions,
97             jLabelWorkingDirectory,
98         };
99         keys = new String JavaDoc[] {
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 JavaDoc field = data[i];
113             final String JavaDoc prop = keys[i];
114             final JLabel JavaDoc label = dataLabels[i];
115             field.getDocument().addDocumentListener(new DocumentListener JavaDoc() {
116                 Font JavaDoc basefont = label.getFont();
117                 Font JavaDoc boldfont = basefont.deriveFont(Font.BOLD);
118                 {
119                     updateFont();
120                 }
121                 public void insertUpdate(DocumentEvent JavaDoc e) {
122                     changed();
123                 }
124                 public void removeUpdate(DocumentEvent JavaDoc e) {
125                     changed();
126                 }
127                 public void changedUpdate(DocumentEvent JavaDoc e) {}
128                 void changed() {
129                     String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
130                     if (config.length() == 0) {
131                         config = null;
132                     }
133                     String JavaDoc v = field.getText();
134                     if (v != null && config != null && v.equals(configs.get(null).get(prop))) {
135                         // default value, do not store as such
136
v = null;
137                     }
138                     configs.get(config).put(prop, v);
139                     updateFont();
140                 }
141                 void updateFont() {
142                     String JavaDoc v = field.getText();
143                     String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
144                     if (config.length() == 0) {
145                         config = null;
146                     }
147                     String JavaDoc 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     /** This method is called from within the constructor to
161      * initialize the form.
162      * WARNING: Do NOT modify this code. The content of this method is
163      * always regenerated by the Form Editor.
164      */

165     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
166
private void initComponents() {
167         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
168
169         configSep = new javax.swing.JSeparator JavaDoc();
170         configPanel = new javax.swing.JPanel JavaDoc();
171         configLabel = new javax.swing.JLabel JavaDoc();
172         configCombo = new javax.swing.JComboBox JavaDoc();
173         configNew = new javax.swing.JButton JavaDoc();
174         configDel = new javax.swing.JButton JavaDoc();
175         mainPanel = new javax.swing.JPanel JavaDoc();
176         jLabelMainClass = new javax.swing.JLabel JavaDoc();
177         jTextFieldMainClass = new javax.swing.JTextField JavaDoc();
178         jButtonMainClass = new javax.swing.JButton JavaDoc();
179         jLabelArgs = new javax.swing.JLabel JavaDoc();
180         jTextFieldArgs = new javax.swing.JTextField JavaDoc();
181         jLabelWorkingDirectory = new javax.swing.JLabel JavaDoc();
182         jTextWorkingDirectory = new javax.swing.JTextField JavaDoc();
183         jButtonWorkingDirectoryBrowse = new javax.swing.JButton JavaDoc();
184         jLabelVMOptions = new javax.swing.JLabel JavaDoc();
185         jTextVMOptions = new javax.swing.JTextField JavaDoc();
186         jLabelVMOptionsExample = new javax.swing.JLabel JavaDoc();
187         extPanel = new javax.swing.JPanel JavaDoc();
188
189         setLayout(new java.awt.GridBagLayout JavaDoc());
190         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 6, 0);
196         add(configSep, gridBagConstraints);
197
198         configPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
199
200         configLabel.setLabelFor(configCombo);
201         org.openide.awt.Mnemonics.setLocalizedText(configLabel, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "CustomizerRun.configLabel")); // NOI18N
202
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
203         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
204         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 2, 0);
205         configPanel.add(configLabel, gridBagConstraints);
206
207         configCombo.setModel(new javax.swing.DefaultComboBoxModel JavaDoc(new String JavaDoc[] { "<default>" }));
208         configCombo.addActionListener(new java.awt.event.ActionListener JavaDoc() {
209             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
210                 configComboActionPerformed(evt);
211             }
212         });
213         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(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")); // NOI18N
221
configNew.addActionListener(new java.awt.event.ActionListener JavaDoc() {
222             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
223                 configNewActionPerformed(evt);
224             }
225         });
226         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
227         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
228         gridBagConstraints.insets = new java.awt.Insets JavaDoc(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")); // NOI18N
232
configDel.addActionListener(new java.awt.event.ActionListener JavaDoc() {
233             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
234                 configDelActionPerformed(evt);
235             }
236         });
237         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
238         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
239         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 2, 0);
240         configPanel.add(configDel, gridBagConstraints);
241
242         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
243         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
244         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
245         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
246         add(configPanel, gridBagConstraints);
247
248         mainPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
249
250         jLabelMainClass.setLabelFor(jTextFieldMainClass);
251         org.openide.awt.Mnemonics.setLocalizedText(jLabelMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JLabel")); // NOI18N
252
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
253         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
254         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
255         mainPanel.add(jLabelMainClass, gridBagConstraints);
256         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
257         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
258         gridBagConstraints.weightx = 1.0;
259         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 5, 0);
260         mainPanel.add(jTextFieldMainClass, gridBagConstraints);
261         jTextFieldMainClass.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jTextFieldMainClass")); // NOI18N
262

263         org.openide.awt.Mnemonics.setLocalizedText(jButtonMainClass, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_MainClass_JButton")); // NOI18N
264
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
265         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
266         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
267         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 5, 0);
268         mainPanel.add(jButtonMainClass, gridBagConstraints);
269         jButtonMainClass.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jButtonMainClass")); // NOI18N
270

271         jLabelArgs.setLabelFor(jTextFieldArgs);
272         org.openide.awt.Mnemonics.setLocalizedText(jLabelArgs, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Args_JLabel")); // NOI18N
273
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
274         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
275         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 12, 0);
276         mainPanel.add(jLabelArgs, gridBagConstraints);
277         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 12, 12, 0);
282         mainPanel.add(jTextFieldArgs, gridBagConstraints);
283         jTextFieldArgs.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getBundle(CustomizerRun.class).getString("AD_jTextFieldArgs")); // NOI18N
284

285         jLabelWorkingDirectory.setLabelFor(jTextWorkingDirectory);
286         org.openide.awt.Mnemonics.setLocalizedText(jLabelWorkingDirectory, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory")); // NOI18N
287
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
288         gridBagConstraints.gridy = 2;
289         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
290         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
291         mainPanel.add(jLabelWorkingDirectory, gridBagConstraints);
292         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 12, 5, 0);
298         mainPanel.add(jTextWorkingDirectory, gridBagConstraints);
299         java.util.ResourceBundle JavaDoc bundle = java.util.ResourceBundle.getBundle("org/netbeans/modules/java/j2seproject/ui/customizer/Bundle"); // NOI18N
300
jTextWorkingDirectory.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_Working_Directory ")); // NOI18N
301

302         org.openide.awt.Mnemonics.setLocalizedText(jButtonWorkingDirectoryBrowse, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse")); // NOI18N
303
jButtonWorkingDirectoryBrowse.addActionListener(new java.awt.event.ActionListener JavaDoc() {
304             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
305                 jButtonWorkingDirectoryBrowseActionPerformed(evt);
306             }
307         });
308         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 6, 5, 0);
313         mainPanel.add(jButtonWorkingDirectoryBrowse, gridBagConstraints);
314         jButtonWorkingDirectoryBrowse.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_Working_Directory_Browse")); // NOI18N
315

316         jLabelVMOptions.setLabelFor(jTextVMOptions);
317         org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptions, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options")); // NOI18N
318
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
319         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
320         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 5, 0);
321         mainPanel.add(jLabelVMOptions, gridBagConstraints);
322         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
323         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
324         gridBagConstraints.weightx = 1.0;
325         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 12, 0, 0);
326         mainPanel.add(jTextVMOptions, gridBagConstraints);
327         jTextVMOptions.getAccessibleContext().setAccessibleDescription(bundle.getString("AD_CustomizeRun_Run_VM_Options")); // NOI18N
328

329         jLabelVMOptionsExample.setLabelFor(jTextFieldMainClass);
330         org.openide.awt.Mnemonics.setLocalizedText(jLabelVMOptionsExample, org.openide.util.NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_VM_Options_Example")); // NOI18N
331
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(0, 12, 12, 0);
337         mainPanel.add(jLabelVMOptionsExample, gridBagConstraints);
338         jLabelVMOptionsExample.getAccessibleContext().setAccessibleDescription(bundle.getString("LBL_CustomizeRun_Run_VM_Options_Example")); // NOI18N
339

340         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc(6, 0, 6, 0);
347         add(mainPanel, gridBagConstraints);
348
349         extPanel.setLayout(new java.awt.GridBagLayout JavaDoc());
350         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
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     }// </editor-fold>//GEN-END:initComponents
360

361     private void initExtPanel(Project p) {
362         if (compProvider != null) {
363             J2SERunConfigProvider.ConfigChangeListener ccl = new J2SERunConfigProvider.ConfigChangeListener() {
364                 public void propertiesChanged(Map JavaDoc<String JavaDoc, String JavaDoc> updates) {
365                     // update active configuration
366
Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(uiProperties.activeConfig);
367                     m.putAll(updates);
368                 }
369             };
370             JComponent JavaDoc comp = compProvider.createComponent(p, ccl);
371             if (comp != null) {
372                 java.awt.GridBagConstraints JavaDoc constraints = new java.awt.GridBagConstraints JavaDoc();
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 JavaDoc evt) {//GEN-FIRST:event_configDelActionPerformed
384
String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
385         assert config != null;
386         configs.put(config, null);
387         configChanged(null);
388         uiProperties.activeConfig = null;
389     }//GEN-LAST:event_configDelActionPerformed
390

391     private void configNewActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_configNewActionPerformed
392
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 JavaDoc name = d.getInputText();
399         String JavaDoc config = name.replaceAll("[^a-zA-Z0-9_.-]", "_"); // NOI18N
400
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 JavaDoc<String JavaDoc,String JavaDoc> m = new HashMap JavaDoc<String JavaDoc,String JavaDoc>();
407         if (!name.equals(config)) {
408             m.put("$label", name); // NOI18N
409
}
410         configs.put(config, m);
411         configChanged(config);
412         uiProperties.activeConfig = config;
413     }//GEN-LAST:event_configNewActionPerformed
414

415     private void configComboActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_configComboActionPerformed
416
String JavaDoc config = (String JavaDoc) configCombo.getSelectedItem();
417         if (config.length() == 0) {
418             config = null;
419         }
420         configChanged(config);
421         uiProperties.activeConfig = config;
422     }//GEN-LAST:event_configComboActionPerformed
423

424     private void jButtonWorkingDirectoryBrowseActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_jButtonWorkingDirectoryBrowseActionPerformed
425
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
426         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
427         chooser.setFileSelectionMode (JFileChooser.DIRECTORIES_ONLY);
428         chooser.setMultiSelectionEnabled(false);
429         
430         String JavaDoc workDir = jTextWorkingDirectory.getText();
431         if (workDir.equals("")) {
432             workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
433         }
434         chooser.setSelectedFile(new File JavaDoc(workDir));
435         chooser.setDialogTitle(NbBundle.getMessage(CustomizerRun.class, "LBL_CustomizeRun_Run_Working_Directory_Browse_Title"));
436         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) { //NOI18N
437
File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
438             jTextWorkingDirectory.setText(file.getAbsolutePath());
439         }
440     }//GEN-LAST:event_jButtonWorkingDirectoryBrowseActionPerformed
441

442     private void configChanged(String JavaDoc activeConfig) {
443         DefaultComboBoxModel JavaDoc model = new DefaultComboBoxModel JavaDoc();
444         model.addElement("");
445         SortedSet JavaDoc<String JavaDoc> alphaConfigs = new TreeSet JavaDoc<String JavaDoc>(new Comparator JavaDoc<String JavaDoc>() {
446             Collator JavaDoc coll = Collator.getInstance();
447             public int compare(String JavaDoc s1, String JavaDoc s2) {
448                 return coll.compare(label(s1), label(s2));
449             }
450             private String JavaDoc label(String JavaDoc c) {
451                 Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(c);
452                 String JavaDoc label = m.get("$label"); // NOI18N
453
return label != null ? label : c;
454             }
455         });
456         for (Map.Entry JavaDoc<String JavaDoc,Map JavaDoc<String JavaDoc,String JavaDoc>> entry : configs.entrySet()) {
457             String JavaDoc config = entry.getKey();
458             if (config != null && entry.getValue() != null) {
459                 alphaConfigs.add(config);
460             }
461         }
462         for (String JavaDoc c : alphaConfigs) {
463             model.addElement(c);
464         }
465         configCombo.setModel(model);
466         configCombo.setSelectedItem(activeConfig != null ? activeConfig : "");
467         Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(activeConfig);
468         Map JavaDoc<String JavaDoc,String JavaDoc> 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 JavaDoc v = m.get(keys[i]);
475                 if (v == null) {
476                     // display default value
477
v = def.get(keys[i]);
478                 }
479                 data[i].setText(v);
480             }
481         } // else ??
482
configDel.setEnabled(activeConfig != null);
483     }
484     
485     
486     // Variables declaration - do not modify//GEN-BEGIN:variables
487
private javax.swing.JComboBox JavaDoc configCombo;
488     private javax.swing.JButton JavaDoc configDel;
489     private javax.swing.JLabel JavaDoc configLabel;
490     private javax.swing.JButton JavaDoc configNew;
491     private javax.swing.JPanel JavaDoc configPanel;
492     private javax.swing.JSeparator JavaDoc configSep;
493     private javax.swing.JPanel JavaDoc extPanel;
494     private javax.swing.JButton JavaDoc jButtonMainClass;
495     private javax.swing.JButton JavaDoc jButtonWorkingDirectoryBrowse;
496     private javax.swing.JLabel JavaDoc jLabelArgs;
497     private javax.swing.JLabel JavaDoc jLabelMainClass;
498     private javax.swing.JLabel JavaDoc jLabelVMOptions;
499     private javax.swing.JLabel JavaDoc jLabelVMOptionsExample;
500     private javax.swing.JLabel JavaDoc jLabelWorkingDirectory;
501     private javax.swing.JTextField JavaDoc jTextFieldArgs;
502     private javax.swing.JTextField JavaDoc jTextFieldMainClass;
503     private javax.swing.JTextField JavaDoc jTextVMOptions;
504     private javax.swing.JTextField JavaDoc jTextWorkingDirectory;
505     private javax.swing.JPanel JavaDoc mainPanel;
506     // End of variables declaration//GEN-END:variables
507

508     
509     // Innercasses -------------------------------------------------------------
510

511     private class MainClassListener implements ActionListener JavaDoc /*, DocumentListener */ {
512         
513         private final JButton JavaDoc okButton;
514         private SourceRoots sourceRoots;
515         private JTextField JavaDoc mainClassTextField;
516         
517         MainClassListener( SourceRoots sourceRoots, JTextField JavaDoc mainClassTextField ) {
518             this.sourceRoots = sourceRoots;
519             this.mainClassTextField = mainClassTextField;
520             this.okButton = new JButton JavaDoc (NbBundle.getMessage (CustomizerRun.class, "LBL_ChooseMainClass_OK"));
521             this.okButton.getAccessibleContext().setAccessibleDescription (NbBundle.getMessage (CustomizerRun.class, "AD_ChooseMainClass_OK"));
522         }
523         
524         // Implementation of ActionListener ------------------------------------
525

526         /** Handles button events
527          */

528         public void actionPerformed( ActionEvent JavaDoc e ) {
529             
530             // only chooseMainClassButton can be performed
531

532             final MainClassChooser panel = new MainClassChooser (sourceRoots.getRoots());
533             Object JavaDoc[] options = new Object JavaDoc[] {
534                 okButton,
535                 DialogDescriptor.CANCEL_OPTION
536             };
537             panel.addChangeListener (new ChangeListener JavaDoc () {
538                public void stateChanged(ChangeEvent JavaDoc e) {
539                    if (e.getSource () instanceof MouseEvent JavaDoc && MouseUtils.isDoubleClick (((MouseEvent JavaDoc)e.getSource ()))) {
540                        // click button and finish the dialog with selected class
541
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             //desc.setMessageType (DialogDescriptor.INFORMATION_MESSAGE);
558
Dialog JavaDoc 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 JavaDoc implements ListCellRenderer JavaDoc, UIResource JavaDoc {
569         
570         public ConfigListCellRenderer () {
571             setOpaque(true);
572         }
573         
574         public Component JavaDoc getListCellRendererComponent(JList JavaDoc list, Object JavaDoc value, int index, boolean isSelected, boolean cellHasFocus) {
575             // #93658: GTK needs name to render cell renderer "natively"
576
setName("ComboBox.listRenderer"); // NOI18N
577

578             String JavaDoc config = (String JavaDoc) value;
579             String JavaDoc label;
580             if (config == null) {
581                 // uninitialized?
582
label = null;
583             } else if (config.length() > 0) {
584                 Map JavaDoc<String JavaDoc,String JavaDoc> m = configs.get(config);
585                 label = m != null ? m.get("$label") : /* temporary? */ 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         // #93658: GTK needs name to render cell renderer "natively"
607
public String JavaDoc getName() {
608             String JavaDoc name = super.getName();
609             return name == null ? "ComboBox.renderer" : name; // NOI18N
610
}
611         
612     }
613     
614     
615 }
616
Popular Tags