KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > javawebstart > ui > customizer > JWSCustomizerPanel


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.javawebstart.ui.customizer;
21
22 import java.io.File JavaDoc;
23
24 import javax.swing.JComponent JavaDoc;
25 import javax.swing.JFileChooser JavaDoc;
26 import javax.swing.JPanel JavaDoc;
27 import javax.swing.filechooser.FileFilter JavaDoc;
28
29 import org.openide.filesystems.FileUtil;
30 import org.openide.util.HelpCtx;
31 import org.openide.util.NbBundle;
32
33 import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectProperties.CodebaseComboBoxModel;
34 import org.netbeans.modules.javawebstart.CustomizerRunComponent;
35
36 /**
37  *
38  * @author Milan Kubec
39  */

40 public class JWSCustomizerPanel extends JPanel JavaDoc implements HelpCtx.Provider {
41     
42     private JWSProjectProperties jwsProps;
43     private File JavaDoc lastImageFolder = null;
44     
45     public static CustomizerRunComponent runComponent;
46     static {
47         runComponent = new CustomizerRunComponent();
48     }
49     
50     /** Creates new form JWSCustomizerPanel */
51     public JWSCustomizerPanel(JWSProjectProperties props) {
52         
53         this.jwsProps = props;
54         
55         initComponents();
56         
57         enableCheckBox.setModel(jwsProps.enabledModel);
58         offlineCheckBox.setModel(jwsProps.allowOfflineModel);
59         iconTextField.setDocument(jwsProps.iconDocument);
60         codebaseComboBox.setModel(jwsProps.codebaseModel);
61         codebaseTextField.setDocument(jwsProps.codebaseURLDocument);
62         
63         setCodebaseComponents();
64         boolean enableSelected = enableCheckBox.getModel().isSelected();
65         setEnabledAllComponents(enableSelected);
66         setEnabledRunComponent(enableSelected);
67         
68     }
69     
70     private static void setEnabledRunComponent(boolean enable) {
71         runComponent.setCheckboxEnabled(enable);
72         runComponent.setHintVisible(!enable);
73     }
74     
75     /** This method is called from within the constructor to
76      * initialize the form.
77      * WARNING: Do NOT modify this code. The content of this method is
78      * always regenerated by the Form Editor.
79      */

80     // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
81
private void initComponents() {
82         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
83
84         enableCheckBox = new javax.swing.JCheckBox JavaDoc();
85         iconLabel = new javax.swing.JLabel JavaDoc();
86         codebaseLabel = new javax.swing.JLabel JavaDoc();
87         iconTextField = new javax.swing.JTextField JavaDoc();
88         browseButton = new javax.swing.JButton JavaDoc();
89         codebaseComboBox = new javax.swing.JComboBox JavaDoc();
90         codebaseTextField = new javax.swing.JTextField JavaDoc();
91         offlineLabel = new javax.swing.JLabel JavaDoc();
92         offlineCheckBox = new javax.swing.JCheckBox JavaDoc();
93         panelDescLabel = new javax.swing.JLabel JavaDoc();
94
95         setLayout(new java.awt.GridBagLayout JavaDoc());
96
97         enableCheckBox.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.enableCheckBox.text")); // NOI18N
98
enableCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
99         enableCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
100         enableCheckBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
101             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
102                 enableCheckBoxActionPerformed(evt);
103             }
104         });
105         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
106         gridBagConstraints.gridx = 0;
107         gridBagConstraints.gridy = 1;
108         gridBagConstraints.gridwidth = 2;
109         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
110         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 0, 6, 0);
111         add(enableCheckBox, gridBagConstraints);
112
113         iconLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.iconLabel.text")); // NOI18N
114
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
115         gridBagConstraints.gridx = 0;
116         gridBagConstraints.gridy = 2;
117         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
118         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 0, 0, 0);
119         add(iconLabel, gridBagConstraints);
120
121         codebaseLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.codebaseLabel.text")); // NOI18N
122
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
123         gridBagConstraints.gridx = 0;
124         gridBagConstraints.gridy = 3;
125         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
126         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 0, 0, 0);
127         add(codebaseLabel, gridBagConstraints);
128
129         iconTextField.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.iconTextField.text")); // NOI18N
130
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
131         gridBagConstraints.gridx = 1;
132         gridBagConstraints.gridy = 2;
133         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135         gridBagConstraints.insets = new java.awt.Insets JavaDoc(8, 6, 0, 0);
136         add(iconTextField, gridBagConstraints);
137
138         browseButton.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.browseButton.text")); // NOI18N
139
browseButton.addActionListener(new java.awt.event.ActionListener JavaDoc() {
140             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
141                 browseButtonActionPerformed(evt);
142             }
143         });
144         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
145         gridBagConstraints.gridx = 2;
146         gridBagConstraints.gridy = 2;
147         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
148         gridBagConstraints.insets = new java.awt.Insets JavaDoc(6, 6, 0, 0);
149         add(browseButton, gridBagConstraints);
150
151         codebaseComboBox.addActionListener(new java.awt.event.ActionListener JavaDoc() {
152             public void actionPerformed(java.awt.event.ActionEvent JavaDoc evt) {
153                 codebaseComboBoxActionPerformed(evt);
154             }
155         });
156         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
157         gridBagConstraints.gridx = 1;
158         gridBagConstraints.gridy = 3;
159         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
160         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
161         gridBagConstraints.weightx = 1.0;
162         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 0, 0);
163         add(codebaseComboBox, gridBagConstraints);
164
165         codebaseTextField.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.codebaseTextField.text")); // NOI18N
166
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
167         gridBagConstraints.gridx = 1;
168         gridBagConstraints.gridy = 4;
169         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
170         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
171         gridBagConstraints.insets = new java.awt.Insets JavaDoc(5, 6, 0, 0);
172         add(codebaseTextField, gridBagConstraints);
173
174         offlineLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.offlineLabel.text")); // NOI18N
175
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
176         gridBagConstraints.gridx = 0;
177         gridBagConstraints.gridy = 5;
178         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
179         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
180         gridBagConstraints.weighty = 1.0;
181         gridBagConstraints.insets = new java.awt.Insets JavaDoc(10, 0, 0, 0);
182         add(offlineLabel, gridBagConstraints);
183
184         offlineCheckBox.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.offlineCheckBox.text")); // NOI18N
185
offlineCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
186         offlineCheckBox.setMargin(new java.awt.Insets JavaDoc(0, 0, 0, 0));
187         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
188         gridBagConstraints.gridx = 1;
189         gridBagConstraints.gridy = 5;
190         gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
191         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
192         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
193         gridBagConstraints.weighty = 1.0;
194         gridBagConstraints.insets = new java.awt.Insets JavaDoc(11, 7, 0, 0);
195         add(offlineCheckBox, gridBagConstraints);
196
197         panelDescLabel.setText(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.panelDescLabel.text")); // NOI18N
198
gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
199         gridBagConstraints.gridx = 0;
200         gridBagConstraints.gridy = 0;
201         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
202         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
203         gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
204         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 0, 10, 0);
205         add(panelDescLabel, gridBagConstraints);
206     }// </editor-fold>//GEN-END:initComponents
207

208     private void codebaseComboBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_codebaseComboBoxActionPerformed
209
setCodebaseComponents();
210     }//GEN-LAST:event_codebaseComboBoxActionPerformed
211

212     private void enableCheckBoxActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_enableCheckBoxActionPerformed
213
boolean isSelected = enableCheckBox.getModel().isSelected();
214         setEnabledAllComponents(isSelected);
215         setEnabledRunComponent(isSelected);
216     }//GEN-LAST:event_enableCheckBoxActionPerformed
217

218     private void browseButtonActionPerformed(java.awt.event.ActionEvent JavaDoc evt) {//GEN-FIRST:event_browseButtonActionPerformed
219
JFileChooser JavaDoc chooser = new JFileChooser JavaDoc();
220         FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
221         chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
222         chooser.setMultiSelectionEnabled(false);
223         chooser.setFileFilter(new IconFileFilter());
224         if (lastImageFolder != null) {
225             chooser.setSelectedFile(lastImageFolder);
226         } else { // ???
227
// workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
228
// chooser.setSelectedFile(new File(workDir));
229
}
230         chooser.setDialogTitle(NbBundle.getMessage(JWSCustomizerPanel.class, "LBL_Select_Icon_Image"));
231         if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
232             File JavaDoc file = FileUtil.normalizeFile(chooser.getSelectedFile());
233             iconTextField.setText(file.getAbsolutePath());
234             lastImageFolder = file.getParentFile();
235         }
236     }//GEN-LAST:event_browseButtonActionPerformed
237

238     public HelpCtx getHelpCtx() {
239         return new HelpCtx(JWSCustomizerPanel.class);
240     }
241     
242     private static class IconFileFilter extends FileFilter JavaDoc {
243         
244         // XXX should check size of images?
245
public boolean accept(File JavaDoc f) {
246             if (f.isDirectory()) {
247                 return true;
248             }
249             String JavaDoc name = f.getName();
250             int index = name.lastIndexOf('.');
251             if (index > 0 && index < name.length() - 1) {
252                 String JavaDoc ext = name.substring(index+1).toLowerCase();
253                 if ("gif".equals(ext) || "png".equals(ext) || "jpg".equals(ext)) {
254                     return true;
255                 }
256             }
257             return false;
258         }
259         
260         public String JavaDoc getDescription() {
261             return "Icon image files";
262         }
263         
264     }
265     
266     private CodebaseComboBoxModel getCBModel() {
267         return (CodebaseComboBoxModel) codebaseComboBox.getModel();
268     }
269     
270     private void setCodebaseComponents() {
271         String JavaDoc value = getCBModel().getSelectedCodebaseItem();
272         if (JWSProjectProperties.CB_TYPE_LOCAL.equals(value)) {
273             codebaseTextField.setText(jwsProps.getProjectDistDir());
274             codebaseTextField.setEditable(false);
275         } else if (JWSProjectProperties.CB_TYPE_WEB.equals(value)) {
276             codebaseTextField.setText(JWSProjectProperties.CB_URL_WEB);
277             codebaseTextField.setEditable(false);
278         } else if (JWSProjectProperties.CB_TYPE_USER.equals(value)) {
279             codebaseTextField.setText(jwsProps.getCodebaseLocation());
280             codebaseTextField.setEditable(true);
281         }
282     }
283     
284     private void setEnabledAllComponents(boolean b) {
285         iconLabel.setEnabled(b);
286         iconTextField.setEnabled(b);
287         browseButton.setEnabled(b);
288         codebaseLabel.setEnabled(b);
289         codebaseComboBox.setEnabled(b);
290         codebaseTextField.setEnabled(b);
291         offlineLabel.setEnabled(b);
292         offlineCheckBox.setEnabled(b);
293     }
294     
295     // Variables declaration - do not modify//GEN-BEGIN:variables
296
private javax.swing.JButton JavaDoc browseButton;
297     private javax.swing.JComboBox JavaDoc codebaseComboBox;
298     private javax.swing.JLabel JavaDoc codebaseLabel;
299     private javax.swing.JTextField JavaDoc codebaseTextField;
300     private javax.swing.JCheckBox JavaDoc enableCheckBox;
301     private javax.swing.JLabel JavaDoc iconLabel;
302     private javax.swing.JTextField JavaDoc iconTextField;
303     private javax.swing.JCheckBox JavaDoc offlineCheckBox;
304     private javax.swing.JLabel JavaDoc offlineLabel;
305     private javax.swing.JLabel JavaDoc panelDescLabel;
306     // End of variables declaration//GEN-END:variables
307

308 }
309
Popular Tags