KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > apisupport > project > ui > customizer > CustomizerPackaging


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.customizer;
21
22 import java.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import javax.swing.event.DocumentEvent JavaDoc;
25 import org.netbeans.modules.apisupport.project.ui.UIUtil;
26 import org.netbeans.spi.project.support.ant.PropertyUtils;
27 import org.netbeans.spi.project.ui.support.ProjectCustomizer;
28 import org.openide.util.NbBundle;
29
30 /**
31  * Represents <em>Packaging</em> panel in Netbeans Module customizer.
32  *
33  * @author Martin Krauskopf
34  */

35 final class CustomizerPackaging extends NbPropertyPanel.Single {
36     private ProjectCustomizer.Category cat;
37     /** Creates new form CustomizerPackaging */
38     CustomizerPackaging(final SingleModuleProperties props, ProjectCustomizer.Category cat) {
39         super(props, CustomizerPackaging.class);
40         this.cat = cat;
41         initComponents();
42         initAccesibility();
43         refresh();
44         if (!getProperties().isNetBeansOrg()) {
45             licenseValue.getDocument().addDocumentListener(new UIUtil.DocumentAdapter() {
46                 public void insertUpdate(DocumentEvent JavaDoc e) {
47                     checkValidity();
48                 }
49             });
50         } else {
51             license.setEnabled(false);
52             licenseValue.setEnabled(false);
53             browseLicense.setEnabled(false);
54         }
55         checkValidity();
56     }
57     
58     
59     private void checkValidity() {
60         File JavaDoc currentLicenceF = getCurrentLicenceFile();
61         if (currentLicenceF != null && !currentLicenceF.isFile()) {
62             cat.setErrorMessage(NbBundle.getMessage(CustomizerPackaging.class, "MSG_LicenceFileDoesNotExist"));
63             cat.setValid(false);
64         } else {
65             cat.setErrorMessage(null);
66             cat.setValid(true);
67         }
68     }
69     
70     void refresh() {
71         UIUtil.setText(jarFileValue, getProperties().getJarFile());
72         needsRestart.setSelected(getBooleanProperty(SingleModuleProperties.NBM_NEEDS_RESTART));
73         UIUtil.setText(homePageValue, getProperty(SingleModuleProperties.NBM_HOMEPAGE));
74         UIUtil.setText(authorValue, getProperty(SingleModuleProperties.NBM_MODULE_AUTHOR));
75         if (!getProperties().isNetBeansOrg()) {
76             UIUtil.setText(licenseValue, getProperty(SingleModuleProperties.LICENSE_FILE));
77         }
78     }
79     
80     public void store() {
81         setBooleanProperty(SingleModuleProperties.NBM_NEEDS_RESTART, needsRestart.isSelected());
82         setProperty(SingleModuleProperties.NBM_HOMEPAGE, homePageValue.getText());
83         setProperty(SingleModuleProperties.NBM_MODULE_AUTHOR, authorValue.getText());
84         if (!getProperties().isNetBeansOrg()) {
85             setProperty(SingleModuleProperties.LICENSE_FILE, licenseValue.getText());
86         }
87     }
88     
89     private String JavaDoc getCurrentLicence() {
90         return licenseValue.getText().trim();
91     }
92     
93     private File JavaDoc getCurrentLicenceFile() {
94         File JavaDoc file = null;
95         String JavaDoc currentLicence = getCurrentLicence();
96         if (!currentLicence.equals("")) {
97             file = getProperties().evaluateFile(currentLicence);
98         }
99         return file;
100     }
101     
102     /** This method is called from within the constructor to
103      * initialize the form.
104      * WARNING: Do NOT modify this code. The content of this method is
105      * always regenerated by the Form Editor.
106      */

107     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
108
private void initComponents() {
109         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
110
111         license = new javax.swing.JLabel JavaDoc();
112         licenseValue = new javax.swing.JTextField JavaDoc();
113         homePage = new javax.swing.JLabel JavaDoc();
114         homePageValue = new javax.swing.JTextField JavaDoc();
115         nbmPkgMetadata = new javax.swing.JLabel JavaDoc();
116         author = new javax.swing.JLabel JavaDoc();
117         authorValue = new javax.swing.JTextField JavaDoc();
118         jarFile = new javax.swing.JLabel JavaDoc();
119         jarFileValue = new javax.swing.JTextField JavaDoc();
120         sep1 = new javax.swing.JSeparator JavaDoc();
121         needsRestart = new javax.swing.JCheckBox JavaDoc();
122         filler = new javax.swing.JLabel JavaDoc();
123         browseLicense = new javax.swing.JButton JavaDoc();
124
125         setLayout(new java.awt.GridBagLayout JavaDoc());
126
127         license.setLabelFor(licenseValue);
128         org.openide.awt.Mnemonics.setLocalizedText(license, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_License")); // NOI18N
129
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
130         gridBagConstraints.gridx = 0;
131         gridBagConstraints.gridy = 5;
132         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 6);
134         add(license, gridBagConstraints);
135
136         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
137         gridBagConstraints.gridx = 1;
138         gridBagConstraints.gridy = 5;
139         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
140         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
141         gridBagConstraints.weightx = 1.0;
142         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
143         add(licenseValue, gridBagConstraints);
144
145         homePage.setLabelFor(homePageValue);
146         org.openide.awt.Mnemonics.setLocalizedText(homePage, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_HomePage")); // NOI18N
147
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridx = 0;
149         gridBagConstraints.gridy = 6;
150         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
151         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
152         add(homePage, gridBagConstraints);
153
154         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
155         gridBagConstraints.gridx = 1;
156         gridBagConstraints.gridy = 6;
157         gridBagConstraints.gridwidth = 2;
158         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
159         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
160         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
161         add(homePageValue, gridBagConstraints);
162
163         org.openide.awt.Mnemonics.setLocalizedText(nbmPkgMetadata, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_NBMPackageMetadata")); // NOI18N
164
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
165         gridBagConstraints.gridx = 0;
166         gridBagConstraints.gridy = 1;
167         gridBagConstraints.gridwidth = 3;
168         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
169         gridBagConstraints.insets = new java.awt.Insets JavaDoc(18, 0, 0, 0);
170         add(nbmPkgMetadata, gridBagConstraints);
171
172         author.setLabelFor(authorValue);
173         org.openide.awt.Mnemonics.setLocalizedText(author, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_Author")); // NOI18N
174
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 0;
176         gridBagConstraints.gridy = 7;
177         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
178         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 6);
179         add(author, gridBagConstraints);
180
181         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
182         gridBagConstraints.gridx = 1;
183         gridBagConstraints.gridy = 7;
184         gridBagConstraints.gridwidth = 2;
185         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
186         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
187         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 6, 0);
188         add(authorValue, gridBagConstraints);
189
190         jarFile.setLabelFor(jarFileValue);
191         org.openide.awt.Mnemonics.setLocalizedText(jarFile, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "LBL_JarFile")); // NOI18N
192
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
193         gridBagConstraints.gridx = 0;
194         gridBagConstraints.gridy = 0;
195         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
196         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 0, 12);
197         add(jarFile, gridBagConstraints);
198
199         jarFileValue.setEditable(false);
200         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
201         gridBagConstraints.gridx = 1;
202         gridBagConstraints.gridy = 0;
203         gridBagConstraints.gridwidth = 2;
204         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
205         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
206         add(jarFileValue, gridBagConstraints);
207
208         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
209         gridBagConstraints.gridx = 0;
210         gridBagConstraints.gridy = 2;
211         gridBagConstraints.gridwidth = 3;
212         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
213         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
214         add(sep1, gridBagConstraints);
215
216         org.openide.awt.Mnemonics.setLocalizedText(needsRestart, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "CTL_NeedsRestartOnInstall")); // NOI18N
217
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
218         gridBagConstraints.gridx = 0;
219         gridBagConstraints.gridy = 3;
220         gridBagConstraints.gridwidth = 3;
221         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
222         add(needsRestart, gridBagConstraints);
223
224         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
225         gridBagConstraints.gridx = 0;
226         gridBagConstraints.gridy = 8;
227         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
228         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
229         gridBagConstraints.weighty = 1.0;
230         add(filler, gridBagConstraints);
231
232         org.openide.awt.Mnemonics.setLocalizedText(browseLicense, org.openide.util.NbBundle.getMessage(CustomizerPackaging.class, "CTL_BrowseButton")); // NOI18N
233
browseLicense.addActionListener(new java.awt.event.ActionListener JavaDoc() {
234             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
235                 browseLicense(evt);
236             }
237         });
238
239         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
240         gridBagConstraints.gridx = 2;
241         gridBagConstraints.gridy = 5;
242         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 12, 6, 0);
243         add(browseLicense, gridBagConstraints);
244
245     }// </editor-fold>//GEN-END:initComponents
246

247     private void browseLicense(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseLicense
248
String JavaDoc startDir;
249         File JavaDoc currentLicenceF = getCurrentLicenceFile();
250         if (currentLicenceF != null && currentLicenceF.exists() && currentLicenceF.getParent() != null) {
251             startDir = currentLicenceF.getParent();
252         } else {
253             startDir = getProperties().getProjectDirectory();
254         }
255         JFileChooser JavaDoc chooser = new JFileChooser JavaDoc(startDir);
256         chooser.setFileSelectionMode(JFileChooser.FILES_ONLY);
257         int ret = chooser.showOpenDialog(this);
258         if (ret == JFileChooser.APPROVE_OPTION) {
259             String JavaDoc relPath = PropertyUtils.relativizeFile(
260                     getProperties().getProjectDirectoryFile(), chooser.getSelectedFile());
261             licenseValue.setText(relPath);
262         }
263     }//GEN-LAST:event_browseLicense
264

265     // Variables declaration - do not modify//GEN-BEGIN:variables
266
private javax.swing.JLabel JavaDoc author;
267     private javax.swing.JTextField JavaDoc authorValue;
268     private javax.swing.JButton JavaDoc browseLicense;
269     private javax.swing.JLabel JavaDoc filler;
270     private javax.swing.JLabel JavaDoc homePage;
271     private javax.swing.JTextField JavaDoc homePageValue;
272     private javax.swing.JLabel JavaDoc jarFile;
273     private javax.swing.JTextField JavaDoc jarFileValue;
274     private javax.swing.JLabel JavaDoc license;
275     private javax.swing.JTextField JavaDoc licenseValue;
276     private javax.swing.JLabel JavaDoc nbmPkgMetadata;
277     private javax.swing.JCheckBox JavaDoc needsRestart;
278     private javax.swing.JSeparator JavaDoc sep1;
279     // End of variables declaration//GEN-END:variables
280

281     private static String JavaDoc getMessage(String JavaDoc key) {
282         return NbBundle.getMessage(CustomizerPackaging.class, key);
283     }
284     
285     private void initAccesibility() {
286         browseLicense.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_BrowseLicense"));
287         needsRestart.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_NeedsRestart"));
288         authorValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_AuthorValue"));
289         homePageValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_HomePageValue"));
290         jarFileValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_JarFileValue"));
291         licenseValue.getAccessibleContext().setAccessibleDescription(getMessage("ACSD_LicenseValue"));
292     }
293     
294 }
295
Popular Tags