KickJava   Java API By Example, From Geeks To Geeks.

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


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.io.File JavaDoc;
23 import javax.swing.JFileChooser JavaDoc;
24 import javax.swing.filechooser.FileFilter JavaDoc;
25 import org.openide.filesystems.FileUtil;
26 import org.openide.util.HelpCtx;
27 import org.openide.util.NbBundle;
28
29 /**
30  * Customizer panel for general application information (title, vendor, description,
31  * homepage and splash screen)
32  *
33  * @author Milan Kubec
34  */

35 public class CustomizerApplication extends javax.swing.JPanel JavaDoc implements HelpCtx.Provider {
36     
37     private File JavaDoc lastImageFolder;
38     
39     /** Creates new form CustomizerApplication */
40     public CustomizerApplication(J2SEProjectProperties props) {
41         initComponents();
42         titleTextField.setDocument(props.APPLICATION_TITLE_DOC);
43         vendorTextField.setDocument(props.APPLICATION_VENDOR_DOC);
44         descTextArea.setDocument(props.APPLICATION_DESC_DOC);
45         homepageTextField.setDocument(props.APPLICATION_HOMEPAGE_DOC);
46         splashTextField.setDocument(props.APPLICATION_SPLASH_DOC);
47     }
48     
49     /** This method is called from within the constructor to
50      * initialize the form.
51      * WARNING: Do NOT modify this code. The content of this method is
52      * always regenerated by the Form Editor.
53      */

54     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
55
private void initComponents() {
56         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
57
58         panelDescLabel = new javax.swing.JLabel JavaDoc();
59         titleLabel = new javax.swing.JLabel JavaDoc();
60         vendorLabel = new javax.swing.JLabel JavaDoc();
61         descLabel = new javax.swing.JLabel JavaDoc();
62         homepageLabel = new javax.swing.JLabel JavaDoc();
63         splashLabel = new javax.swing.JLabel JavaDoc();
64         titleTextField = new javax.swing.JTextField JavaDoc();
65         vendorTextField = new javax.swing.JTextField JavaDoc();
66         homepageTextField = new javax.swing.JTextField JavaDoc();
67         splashTextField = new javax.swing.JTextField JavaDoc();
68         browseButton = new javax.swing.JButton JavaDoc();
69         jScrollPane1 = new javax.swing.JScrollPane JavaDoc();
70         descTextArea = new javax.swing.JTextArea JavaDoc();
71
72         setLayout(new java.awt.GridBagLayout JavaDoc());
73
74         panelDescLabel.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.panelDescLabel.text")); // NOI18N
75
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
76         gridBagConstraints.gridx = 0;
77         gridBagConstraints.gridy = 0;
78         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
79         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
80         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
81         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 10, 0);
82         add(panelDescLabel, gridBagConstraints);
83
84         titleLabel.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.titleLabel.text")); // NOI18N
85
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
86         gridBagConstraints.gridx = 0;
87         gridBagConstraints.gridy = 1;
88         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
89         gridBagConstraints.insets = new java.awt.Insets JavaDoc(9, 0, 0, 0);
90         add(titleLabel, gridBagConstraints);
91
92         vendorLabel.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.vendorLabel.text")); // NOI18N
93
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
94         gridBagConstraints.gridx = 0;
95         gridBagConstraints.gridy = 2;
96         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
97         gridBagConstraints.insets = new java.awt.Insets JavaDoc(7, 0, 0, 0);
98         add(vendorLabel, gridBagConstraints);
99
100         descLabel.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.descLabel.text")); // NOI18N
101
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
102         gridBagConstraints.gridx = 0;
103         gridBagConstraints.gridy = 3;
104         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
105         gridBagConstraints.insets = new java.awt.Insets JavaDoc(7, 0, 0, 0);
106         add(descLabel, gridBagConstraints);
107
108         homepageLabel.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.homepageLabel.text")); // NOI18N
109
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
110         gridBagConstraints.gridx = 0;
111         gridBagConstraints.gridy = 4;
112         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
113         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 0, 0, 0);
114         add(homepageLabel, gridBagConstraints);
115
116         splashLabel.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.splashLabel.text")); // NOI18N
117
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
118         gridBagConstraints.gridx = 0;
119         gridBagConstraints.gridy = 5;
120         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
121         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
122         gridBagConstraints.weighty = 1.0;
123         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 0, 0, 0);
124         add(splashLabel, gridBagConstraints);
125
126         titleTextField.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.titleTextField.text")); // NOI18N
127
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
128         gridBagConstraints.gridx = 1;
129         gridBagConstraints.gridy = 1;
130         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
131         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
132         gridBagConstraints.weightx = 1.0;
133         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
134         add(titleTextField, gridBagConstraints);
135
136         vendorTextField.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.vendorTextField.text")); // NOI18N
137
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
138         gridBagConstraints.gridx = 1;
139         gridBagConstraints.gridy = 2;
140         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
141         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
142         gridBagConstraints.weightx = 1.0;
143         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 0, 0);
144         add(vendorTextField, gridBagConstraints);
145
146         homepageTextField.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.homepageTextField.text")); // NOI18N
147
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
148         gridBagConstraints.gridx = 1;
149         gridBagConstraints.gridy = 4;
150         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
151         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
152         gridBagConstraints.weightx = 1.0;
153         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 0, 0);
154         add(homepageTextField, gridBagConstraints);
155
156         splashTextField.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.splashTextField.text")); // NOI18N
157
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
158         gridBagConstraints.gridx = 1;
159         gridBagConstraints.gridy = 5;
160         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
161         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
162         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
163         gridBagConstraints.weightx = 1.0;
164         gridBagConstraints.weighty = 1.0;
165         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 0, 0);
166         add(splashTextField, gridBagConstraints);
167
168         browseButton.setText(org.openide.util.NbBundle.getMessage(CustomizerApplication.class, "CustomizerApplication.browseButton.text")); // NOI18N
169
browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
170             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
171                 browseButtonActionPerformed(evt);
172             }
173         });
174         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
175         gridBagConstraints.gridx = 2;
176         gridBagConstraints.gridy = 5;
177         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
178         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTH;
180         gridBagConstraints.weighty = 1.0;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(3, 6, 0, 0);
182         add(browseButton, gridBagConstraints);
183
184         descTextArea.setColumns(20);
185         descTextArea.setRows(4);
186         jScrollPane1.setViewportView(descTextArea);
187
188         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
189         gridBagConstraints.gridx = 1;
190         gridBagConstraints.gridy = 3;
191         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
193         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
194         add(jScrollPane1, gridBagConstraints);
195     }// </editor-fold>//GEN-END:initComponents
196

197     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
198
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
199         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
200         chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
201         chooser.setMultiSelectionEnabled(false);
202         chooser.setFileFilter(new SplashFileFilter());
203         if (lastImageFolder != null) {
204             chooser.setSelectedFile(lastImageFolder);
205         } else {
206             // ???
207
}
208         chooser.setDialogTitle(NbBundle.getMessage(CustomizerApplication.class, "LBL_Select_Splash_Image"));
209         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
210             File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
211             splashTextField.setText(file.getAbsolutePath());
212             lastImageFolder = file.getParentFile();
213         }
214     }//GEN-LAST:event_browseButtonActionPerformed
215

216     private static class SplashFileFilter extends FileFilter JavaDoc {
217         
218         // XXX should check size of images?
219
public boolean accept(File JavaDoc f) {
220             if (f.isDirectory()) {
221                 return true;
222             }
223             String JavaDoc name = f.getName();
224             int index = name.lastIndexOf('.');
225             if (index > 0 && index < name.length() - 1) {
226                 String JavaDoc ext = name.substring(index+1).toLowerCase();
227                 if ("gif".equals(ext) || "png".equals(ext) || "jpg".equals(ext)) {
228                     return true;
229                 }
230             }
231             return false;
232         }
233         
234         public String JavaDoc getDescription() {
235             return "Splash image files";
236         }
237         
238     }
239     
240     // Variables declaration - do not modify//GEN-BEGIN:variables
241
private javax.swing.JButton JavaDoc browseButton;
242     private javax.swing.JLabel JavaDoc descLabel;
243     private javax.swing.JTextArea JavaDoc descTextArea;
244     private javax.swing.JLabel JavaDoc homepageLabel;
245     private javax.swing.JTextField JavaDoc homepageTextField;
246     private javax.swing.JScrollPane JavaDoc jScrollPane1;
247     private javax.swing.JLabel JavaDoc panelDescLabel;
248     private javax.swing.JLabel JavaDoc splashLabel;
249     private javax.swing.JTextField JavaDoc splashTextField;
250     private javax.swing.JLabel JavaDoc titleLabel;
251     private javax.swing.JTextField JavaDoc titleTextField;
252     private javax.swing.JLabel JavaDoc vendorLabel;
253     private javax.swing.JTextField JavaDoc vendorTextField;
254     // End of variables declaration//GEN-END:variables
255

256     public HelpCtx getHelpCtx() {
257         return new HelpCtx(CustomizerApplication.class);
258     }
259     
260 }
261
Popular Tags