KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > platform > NbPlatformCustomizer


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.apisupport.project.ui.platform;
21
22 import java.awt.Container JavaDoc;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.Window JavaDoc;
25 import java.text.MessageFormat JavaDoc;
26 import javax.swing.JButton JavaDoc;
27 import javax.swing.JComponent JavaDoc;
28 import javax.swing.JPanel JavaDoc;
29 import javax.swing.event.ListSelectionEvent JavaDoc;
30 import javax.swing.event.ListSelectionListener JavaDoc;
31 import org.netbeans.modules.apisupport.project.ui.wizard.BasicWizardPanel;
32 import org.netbeans.modules.apisupport.project.universe.NbPlatform;
33 import org.openide.DialogDescriptor;
34 import org.openide.DialogDisplayer;
35 import org.openide.WizardDescriptor;
36 import org.openide.awt.Mnemonics;
37 import org.openide.util.HelpCtx;
38 import org.openide.util.NbBundle;
39
40 /**
41  * Represents customizer for managing NetBeans platforms.
42  *
43  * @author Martin Krauskopf
44  */

45 public final class NbPlatformCustomizer extends JPanel JavaDoc {
46     
47     static final String JavaDoc CHOOSER_STEP = getMessage("MSG_ChoosePlatfrom"); // NOI18N
48
static final String JavaDoc INFO_STEP = getMessage("MSG_PlatformName"); // NOI18N
49

50     static final String JavaDoc PLAF_DIR_PROPERTY = "selectedPlafDir"; // NOI18N
51
static final String JavaDoc PLAF_LABEL_PROPERTY = "selectedPlafLabel"; // NOI18N
52

53     private NbPlatformCustomizerSources sourcesTab;
54     private NbPlatformCustomizerModules modulesTab;
55     private NbPlatformCustomizerJavadoc javadocTab;
56     private NbPlatformCustomizerHarness harnessTab;
57     
58     public static void showCustomizer() {
59         HarnessUpgrader.checkForUpgrade();
60         NbPlatformCustomizer customizer = new NbPlatformCustomizer();
61         JButton JavaDoc closeButton = new JButton JavaDoc();
62         Mnemonics.setLocalizedText(closeButton,
63                 NbBundle.getMessage(NbPlatformCustomizer.class, "CTL_Close"));
64         DialogDescriptor descriptor = new DialogDescriptor(
65                 customizer,
66                 getMessage("CTL_NbPlatformManager_Title"), // NOI18N
67
true,
68                 new Object JavaDoc[] {closeButton},
69                 closeButton,
70                 DialogDescriptor.DEFAULT_ALIGN,
71                 new HelpCtx(NbPlatformCustomizer.class),
72                 null);
73         Dialog JavaDoc dlg = DialogDisplayer.getDefault().createDialog(descriptor);
74         dlg.setVisible(true);
75         dlg.dispose();
76     }
77     
78     /**
79      * Creates new form NbPlatformCustomizer
80      */

81     private NbPlatformCustomizer() {
82         initComponents();
83         initAccessibility();
84         initTabs();
85         platformsList.addListSelectionListener(new ListSelectionListener JavaDoc() {
86             public void valueChanged(ListSelectionEvent JavaDoc e) {
87                 refreshPlatform();
88             }
89         });
90         refreshPlatform();
91     }
92     
93     private void initTabs() {
94         if (platformsList.getModel().getSize() > 0) {
95             platformsList.setSelectedIndex(0);
96             sourcesTab = new NbPlatformCustomizerSources();
97             modulesTab = new NbPlatformCustomizerModules();
98             javadocTab = new NbPlatformCustomizerJavadoc();
99             harnessTab = new NbPlatformCustomizerHarness();
100             detailPane.addTab(getMessage("CTL_ModulesTab"), modulesTab); // NOI18N
101
detailPane.addTab(getMessage("CTL_SourcesTab"), sourcesTab); // NOI18N
102
detailPane.addTab(getMessage("CTL_JavadocTab"), javadocTab); // NOI18N
103
detailPane.addTab(getMessage("CTL_HarnessTab"), harnessTab); // NOI18N
104
Container JavaDoc window = this.getTopLevelAncestor();
105             if (window != null && window instanceof Window JavaDoc) {
106                 ((Window JavaDoc) window).pack();
107             }
108         }
109     }
110     
111     private void refreshPlatform() {
112         NbPlatform plaf = (NbPlatform) platformsList.getSelectedValue();
113         if (plaf == null) {
114             removeButton.setEnabled(false);
115             return;
116         }
117         plfNameValue.setText(plaf.getLabel());
118         plfFolderValue.setText(plaf.getDestDir().getAbsolutePath());
119         boolean isValid = plaf.isValid();
120         if (isValid) {
121             if (sourcesTab == null) {
122                 initTabs();
123             }
124             if (sourcesTab != null) {
125                 modulesTab.setPlatform(plaf);
126                 sourcesTab.setPlatform(plaf);
127                 javadocTab.setPlatform(plaf);
128                 harnessTab.setPlatform(plaf);
129             }
130         } else {
131             modulesTab.reset();
132             detailPane.setSelectedIndex(0);
133         }
134         detailPane.setEnabledAt(0, isValid);
135         detailPane.setEnabledAt(1, isValid);
136         detailPane.setEnabledAt(2, isValid);
137         removeButton.setEnabled(!plaf.isDefault());
138     }
139     
140     private static String JavaDoc getMessage(String JavaDoc key) {
141         return NbBundle.getMessage(NbPlatformCustomizer.class, key);
142     }
143     
144     /** This method is called from within the constructor to
145      * initialize the form.
146      * WARNING: Do NOT modify this code. The content of this method is
147      * always regenerated by the Form Editor.
148      */

149     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
150
private void initComponents() {
151         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
152
153         platformLbl = new javax.swing.JLabel JavaDoc();
154         platformsListSP = new javax.swing.JScrollPane JavaDoc();
155         platformsList = PlatformComponentFactory.getNbPlatformsList();
156         addButton = new javax.swing.JButton JavaDoc();
157         removeButton = new javax.swing.JButton JavaDoc();
158         infoPane = new javax.swing.JPanel JavaDoc();
159         plfName = new javax.swing.JLabel JavaDoc();
160         pflFolder = new javax.swing.JLabel JavaDoc();
161         plfNameValue = new javax.swing.JTextField JavaDoc();
162         plfFolderValue = new javax.swing.JTextField JavaDoc();
163         detailPane = new javax.swing.JTabbedPane JavaDoc();
164
165         setLayout(new java.awt.GridBagLayout JavaDoc());
166
167         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(12, 12, 12, 12)));
168         platformLbl.setLabelFor(platformsList);
169         org.openide.awt.Mnemonics.setLocalizedText(platformLbl, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "LBL_Platforms"));
170         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
171         gridBagConstraints.gridx = 0;
172         gridBagConstraints.gridy = 0;
173         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
174         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
175         add(platformLbl, gridBagConstraints);
176
177         platformsList.setSelectionMode(javax.swing.ListSelectionModel.SINGLE_SELECTION);
178         platformsListSP.setViewportView(platformsList);
179
180         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
181         gridBagConstraints.gridx = 0;
182         gridBagConstraints.gridy = 1;
183         gridBagConstraints.gridwidth = 2;
184         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
185         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
186         gridBagConstraints.weighty = 1.0;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 0, 12, 6);
188         add(platformsListSP, gridBagConstraints);
189
190         org.openide.awt.Mnemonics.setLocalizedText(addButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "CTL_AddPlatform"));
191         addButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
192             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
193                 addPlatform(evt);
194             }
195         });
196
197         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
198         gridBagConstraints.gridx = 0;
199         gridBagConstraints.gridy = 2;
200         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
201         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 6);
202         add(addButton, gridBagConstraints);
203
204         org.openide.awt.Mnemonics.setLocalizedText(removeButton, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "CTL_RemovePlatfrom"));
205         removeButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
206             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
207                 removePlatform(evt);
208             }
209         });
210
211         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
212         gridBagConstraints.gridx = 1;
213         gridBagConstraints.gridy = 2;
214         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
215         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 6);
216         add(removeButton, gridBagConstraints);
217
218         infoPane.setLayout(new java.awt.GridBagLayout JavaDoc());
219
220         plfName.setLabelFor(plfNameValue);
221         org.openide.awt.Mnemonics.setLocalizedText(plfName, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "LBL_PlatformName_N"));
222         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
223         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
224         infoPane.add(plfName, gridBagConstraints);
225
226         pflFolder.setLabelFor(plfFolderValue);
227         org.openide.awt.Mnemonics.setLocalizedText(pflFolder, org.openide.util.NbBundle.getMessage(NbPlatformCustomizer.class, "LBL_PlatformFolder"));
228         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
229         gridBagConstraints.gridx = 0;
230         gridBagConstraints.gridy = 1;
231         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
232         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 0, 0);
233         infoPane.add(pflFolder, gridBagConstraints);
234
235         plfNameValue.setEditable(false);
236         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
237         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
238         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
239         gridBagConstraints.weightx = 1.0;
240         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 6, 0, 0);
241         infoPane.add(plfNameValue, gridBagConstraints);
242
243         plfFolderValue.setEditable(false);
244         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
245         gridBagConstraints.gridx = 1;
246         gridBagConstraints.gridy = 1;
247         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
248         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
249         gridBagConstraints.weightx = 1.0;
250         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
251         infoPane.add(plfFolderValue, gridBagConstraints);
252
253         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
254         gridBagConstraints.gridx = 0;
255         gridBagConstraints.gridy = 2;
256         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
257         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
258         gridBagConstraints.weightx = 1.0;
259         gridBagConstraints.weighty = 1.0;
260         infoPane.add(detailPane, gridBagConstraints);
261
262         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
263         gridBagConstraints.gridx = 2;
264         gridBagConstraints.gridy = 1;
265         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
266         gridBagConstraints.fill = java.awt.GridBagConstraints.BOTH;
267         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
268         gridBagConstraints.weightx = 1.0;
269         gridBagConstraints.insets = new java.awt.Insets JavaDoc(2, 6, 12, 0);
270         add(infoPane, gridBagConstraints);
271
272     }
273     // </editor-fold>//GEN-END:initComponents
274

275     private PlatformComponentFactory.NbPlatformListModel getPlafListModel() {
276         return (PlatformComponentFactory.NbPlatformListModel) platformsList.getModel();
277     }
278     
279     private void removePlatform(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_removePlatform
280
NbPlatform plaf = (NbPlatform) platformsList.getSelectedValue();
281         if (plaf != null) {
282             getPlafListModel().removePlatform(plaf);
283             platformsList.setSelectedValue(NbPlatform.getDefaultPlatform(), true);
284             refreshPlatform();
285         }
286     }//GEN-LAST:event_removePlatform
287

288     private void addPlatform(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_addPlatform
289
PlatformChooserWizardPanel chooser = new PlatformChooserWizardPanel(null);
290         PlatformInfoWizardPanel info = new PlatformInfoWizardPanel(null);
291         WizardDescriptor wd = new WizardDescriptor(new WizardDescriptor.Panel[] { chooser, info });
292         initPanel(chooser, wd, 0);
293         initPanel(info, wd, 1);
294         wd.setTitleFormat(new MessageFormat JavaDoc("{0}")); // NOI18N
295
Dialog JavaDoc dialog = DialogDisplayer.getDefault().createDialog(wd);
296         dialog.setTitle(getMessage("CTL_AddNetbeansPlatformTitle")); // NOI18N
297
dialog.setVisible(true);
298         dialog.toFront();
299         if (wd.getValue() == WizardDescriptor.FINISH_OPTION) {
300             String JavaDoc plafDir = (String JavaDoc) wd.getProperty(PLAF_DIR_PROPERTY);
301             String JavaDoc plafLabel = (String JavaDoc) wd.getProperty(PLAF_LABEL_PROPERTY);
302             String JavaDoc id = plafLabel.replace(' ', '_');
303             NbPlatform plaf = getPlafListModel().addPlatform(id, plafDir, plafLabel);
304             if (plaf != null) {
305                 platformsList.setSelectedValue(plaf, true);
306                 refreshPlatform();
307             }
308         }
309     }//GEN-LAST:event_addPlatform
310

311     private void initPanel(BasicWizardPanel panel, WizardDescriptor wd, int i) {
312         panel.setSettings(wd);
313         JComponent JavaDoc jc = (JComponent JavaDoc) panel.getComponent();
314         jc.putClientProperty("WizardPanel_autoWizardStyle", Boolean.TRUE); // NOI18N
315
jc.putClientProperty("WizardPanel_contentDisplayed", Boolean.TRUE); // NOI18N
316
jc.putClientProperty("WizardPanel_contentNumbered", Boolean.TRUE); // NOI18N
317
jc.putClientProperty("WizardPanel_contentSelectedIndex", new Integer JavaDoc(i)); // NOI18N
318
jc.putClientProperty("WizardPanel_contentData", new String JavaDoc[] { // NOI18N
319
CHOOSER_STEP, INFO_STEP
320         });
321     }
322     
323     // Variables declaration - do not modify//GEN-BEGIN:variables
324
private javax.swing.JButton JavaDoc addButton;
325     private javax.swing.JTabbedPane JavaDoc detailPane;
326     private javax.swing.JPanel JavaDoc infoPane;
327     private javax.swing.JLabel JavaDoc pflFolder;
328     private javax.swing.JLabel JavaDoc platformLbl;
329     private javax.swing.JList JavaDoc platformsList;
330     private javax.swing.JScrollPane JavaDoc platformsListSP;
331     private javax.swing.JTextField JavaDoc plfFolderValue;
332     private javax.swing.JLabel JavaDoc plfName;
333     private javax.swing.JTextField JavaDoc plfNameValue;
334     private javax.swing.JButton JavaDoc removeButton;
335     // End of variables declaration//GEN-END:variables
336

337     private void initAccessibility() {
338         this.getAccessibleContext().setAccessibleDescription(getMessage("ACS_NbPlatformCustomizer"));
339         platformsList.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_platformsList"));
340         plfFolderValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_plfFolderValue"));
341         plfNameValue.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_plfNameValue"));
342         removeButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_removeButton"));
343         addButton.getAccessibleContext().setAccessibleDescription(getMessage("ACS_CTL_addButton"));
344     }
345 }
346
Popular Tags