2
* DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
4
* Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
6
* The contents of this file are subject to the terms of either the GNU
7
* General Public License Version 2 only ("GPL") or the Common
8
* Development and Distribution License("CDDL") (collectively, the
9
* "License"). You may not use this file except in compliance with the
10
* License. You can obtain a copy of the License at
11
* http://www.netbeans.org/cddl-gplv2.html
12
* or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
13
* specific language governing permissions and limitations under the
14
* License. When distributing the software, include this License Header
15
* Notice in each file and include the License file at
16
* nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
17
* particular file as subject to the "Classpath" exception as provided
18
* by Sun in the GPL Version 2 section of the License file that
19
* accompanied this code. If applicable, add the following below the
20
* License Header, with the fields enclosed by brackets [] replaced by
21
* your own identifying information:
22
* "Portions Copyrighted [year] [name of copyright owner]"
26
* The Original Software is NetBeans. The Initial Developer of the Original
27
* Software is Sun Microsystems, Inc. Portions Copyright 1997-2006 Sun
28
* Microsystems, Inc. All Rights Reserved.
30
* If you wish your version of this file to be governed by only the CDDL
31
* or only the GPL Version 2, indicate your decision by adding
32
* "[Contributor] elects to include this software in this distribution
33
* under the [CDDL or GPL Version 2] license." If you do not indicate a
34
* single choice of license, a recipient has the option to distribute
35
* your version of this file under either the CDDL, the GPL Version 2 or
36
* to extend the choice of license to its licensees as provided above.
37
* However, if you add GPL Version 2 code and therefore, elected the GPL
38
* Version 2 license, then the option applies only if the new code is
39
* made subject to such option by the copyright holder.
42
package org.netbeans.modules.javawebstart.ui.customizer;
46
import javax.swing.JFileChooser;
47
import javax.swing.JPanel;
48
import javax.swing.filechooser.FileFilter;
50
import org.openide.filesystems.FileUtil;
51
import org.openide.util.HelpCtx;
52
import org.openide.util.NbBundle;
54
import org.netbeans.modules.javawebstart.ui.customizer.JWSProjectProperties.CodebaseComboBoxModel;
55
import org.netbeans.modules.javawebstart.CustomizerRunComponent;
61
public class JWSCustomizerPanel extends JPanel implements HelpCtx.Provider {
63
private JWSProjectProperties jwsProps;
64
private File lastImageFolder = null;
66
public static CustomizerRunComponent runComponent;
68
runComponent = new CustomizerRunComponent();
71
/** Creates new form JWSCustomizerPanel */
72
public JWSCustomizerPanel(JWSProjectProperties props) {
74
this.jwsProps = props;
78
enableCheckBox.setModel(jwsProps.enabledModel);
79
enableCheckBox.setMnemonic(NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.enableCheckBox.mnemonic").toCharArray()[0]);
80
offlineCheckBox.setModel(jwsProps.allowOfflineModel);
81
offlineCheckBox.setMnemonic(NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.offlineCheckBox.mnemonic").toCharArray()[0]);
82
signedCheckBox.setModel(jwsProps.signedModel);
83
signedCheckBox.setMnemonic(NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.signedCheckBox.mnemonic").toCharArray()[0]);
84
iconTextField.setDocument(jwsProps.iconDocument);
85
codebaseComboBox.setModel(jwsProps.codebaseModel);
86
codebaseTextField.setDocument(jwsProps.codebaseURLDocument);
88
setCodebaseComponents();
89
boolean enableSelected = enableCheckBox.getModel().isSelected();
90
setEnabledAllComponents(enableSelected);
91
setEnabledRunComponent(enableSelected);
95
private static void setEnabledRunComponent(boolean enable) {
96
runComponent.setCheckboxEnabled(enable);
97
runComponent.setHintVisible(!enable);
100
/** This method is called from within the constructor to
101
* initialize the form.
102
* WARNING: Do NOT modify this code. The content of this method is
103
* always regenerated by the Form Editor.
105
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
106
private void initComponents() {
107
java.awt.GridBagConstraints gridBagConstraints;
109
enableCheckBox = new javax.swing.JCheckBox();
110
iconLabel = new javax.swing.JLabel();
111
codebaseLabel = new javax.swing.JLabel();
112
iconTextField = new javax.swing.JTextField();
113
browseButton = new javax.swing.JButton();
114
codebaseComboBox = new javax.swing.JComboBox();
115
codebaseTextField = new javax.swing.JTextField();
116
offlineCheckBox = new javax.swing.JCheckBox();
117
panelDescLabel = new javax.swing.JLabel();
118
signedCheckBox = new javax.swing.JCheckBox();
120
setLayout(new java.awt.GridBagLayout());
122
org.openide.awt.Mnemonics.setLocalizedText(enableCheckBox, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.enableCheckBox.text")); // NOI18N
123
enableCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
124
enableCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 2));
125
enableCheckBox.addActionListener(new java.awt.event.ActionListener() {
126
public void actionPerformed(java.awt.event.ActionEvent evt) {
127
enableCheckBoxActionPerformed(evt);
130
gridBagConstraints = new java.awt.GridBagConstraints();
131
gridBagConstraints.gridx = 0;
132
gridBagConstraints.gridy = 1;
133
gridBagConstraints.gridwidth = 2;
134
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135
gridBagConstraints.insets = new java.awt.Insets(6, 0, 6, 0);
136
add(enableCheckBox, gridBagConstraints);
137
enableCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_EnableWebStart_CheckBox")); // NOI18N
138
enableCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_EnableWebStart_Label")); // NOI18N
140
iconLabel.setLabelFor(iconTextField);
141
org.openide.awt.Mnemonics.setLocalizedText(iconLabel, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.iconLabel.text")); // NOI18N
142
gridBagConstraints = new java.awt.GridBagConstraints();
143
gridBagConstraints.gridx = 0;
144
gridBagConstraints.gridy = 2;
145
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
146
gridBagConstraints.insets = new java.awt.Insets(11, 0, 0, 0);
147
add(iconLabel, gridBagConstraints);
148
iconLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_Icon_Label")); // NOI18N
149
iconLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_Icon_Label")); // NOI18N
151
codebaseLabel.setLabelFor(codebaseComboBox);
152
org.openide.awt.Mnemonics.setLocalizedText(codebaseLabel, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.codebaseLabel.text")); // NOI18N
153
gridBagConstraints = new java.awt.GridBagConstraints();
154
gridBagConstraints.gridx = 0;
155
gridBagConstraints.gridy = 3;
156
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
157
gridBagConstraints.insets = new java.awt.Insets(8, 0, 0, 0);
158
add(codebaseLabel, gridBagConstraints);
159
codebaseLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_Codebase_Label")); // NOI18N
160
codebaseLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_Codebase_Label")); // NOI18N
162
gridBagConstraints = new java.awt.GridBagConstraints();
163
gridBagConstraints.gridx = 1;
164
gridBagConstraints.gridy = 2;
165
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
166
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
167
gridBagConstraints.insets = new java.awt.Insets(8, 6, 0, 0);
168
add(iconTextField, gridBagConstraints);
169
iconTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_Icon_TextField")); // NOI18N
170
iconTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_Icon_TextField")); // NOI18N
172
org.openide.awt.Mnemonics.setLocalizedText(browseButton, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.browseButton.text")); // NOI18N
173
browseButton.addActionListener(new java.awt.event.ActionListener() {
174
public void actionPerformed(java.awt.event.ActionEvent evt) {
175
browseButtonActionPerformed(evt);
178
gridBagConstraints = new java.awt.GridBagConstraints();
179
gridBagConstraints.gridx = 2;
180
gridBagConstraints.gridy = 2;
181
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
182
gridBagConstraints.insets = new java.awt.Insets(6, 6, 0, 0);
183
add(browseButton, gridBagConstraints);
184
browseButton.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_Browse_Button")); // NOI18N
185
browseButton.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_Browse_Button")); // NOI18N
187
codebaseComboBox.addActionListener(new java.awt.event.ActionListener() {
188
public void actionPerformed(java.awt.event.ActionEvent evt) {
189
codebaseComboBoxActionPerformed(evt);
192
gridBagConstraints = new java.awt.GridBagConstraints();
193
gridBagConstraints.gridx = 1;
194
gridBagConstraints.gridy = 3;
195
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
196
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
197
gridBagConstraints.weightx = 1.0;
198
gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 0);
199
add(codebaseComboBox, gridBagConstraints);
200
codebaseComboBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_Codebase_Combobox")); // NOI18N
201
codebaseComboBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_Codebase_Combobox")); // NOI18N
203
gridBagConstraints = new java.awt.GridBagConstraints();
204
gridBagConstraints.gridx = 1;
205
gridBagConstraints.gridy = 4;
206
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
207
gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
208
gridBagConstraints.insets = new java.awt.Insets(5, 6, 0, 0);
209
add(codebaseTextField, gridBagConstraints);
210
codebaseTextField.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_Codebase_TextField")); // NOI18N
211
codebaseTextField.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_Codebase_TextField")); // NOI18N
213
org.openide.awt.Mnemonics.setLocalizedText(offlineCheckBox, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.offlineCheckBox.text")); // NOI18N
214
offlineCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
215
offlineCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
216
gridBagConstraints = new java.awt.GridBagConstraints();
217
gridBagConstraints.gridx = 0;
218
gridBagConstraints.gridy = 5;
219
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
220
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
221
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
222
gridBagConstraints.insets = new java.awt.Insets(11, 4, 0, 0);
223
add(offlineCheckBox, gridBagConstraints);
224
offlineCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_AllowOffline_Checkbox")); // NOI18N
225
offlineCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_AllowOffline_Checkbox")); // NOI18N
227
org.openide.awt.Mnemonics.setLocalizedText(panelDescLabel, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.panelDescLabel.text")); // NOI18N
228
gridBagConstraints = new java.awt.GridBagConstraints();
229
gridBagConstraints.gridx = 0;
230
gridBagConstraints.gridy = 0;
231
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
232
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
233
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
234
gridBagConstraints.insets = new java.awt.Insets(0, 0, 10, 0);
235
add(panelDescLabel, gridBagConstraints);
236
panelDescLabel.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_WebStartTitle_Label")); // NOI18N
237
panelDescLabel.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_WebStartTitle_Label")); // NOI18N
239
org.openide.awt.Mnemonics.setLocalizedText(signedCheckBox, org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "JWSCustomizerPanel.signedCheckBox.text")); // NOI18N
240
signedCheckBox.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
241
signedCheckBox.setMargin(new java.awt.Insets(0, 0, 0, 0));
242
gridBagConstraints = new java.awt.GridBagConstraints();
243
gridBagConstraints.gridx = 0;
244
gridBagConstraints.gridy = 6;
245
gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
246
gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
247
gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
248
gridBagConstraints.anchor = java.awt.GridBagConstraints.NORTHWEST;
249
gridBagConstraints.weighty = 1.0;
250
gridBagConstraints.insets = new java.awt.Insets(11, 4, 0, 0);
251
add(signedCheckBox, gridBagConstraints);
252
signedCheckBox.getAccessibleContext().setAccessibleName(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSN_SelfSigned_Checkbox")); // NOI18N
253
signedCheckBox.getAccessibleContext().setAccessibleDescription(org.openide.util.NbBundle.getMessage(JWSCustomizerPanel.class, "ACSD_SelfSigned_Checkbox")); // NOI18N
254
}// </editor-fold>//GEN-END:initComponents
256
private void codebaseComboBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_codebaseComboBoxActionPerformed
257
setCodebaseComponents();
258
}//GEN-LAST:event_codebaseComboBoxActionPerformed
260
private void enableCheckBoxActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_enableCheckBoxActionPerformed
261
boolean isSelected = enableCheckBox.getModel().isSelected();
262
setEnabledAllComponents(isSelected);
263
setEnabledRunComponent(isSelected);
264
}//GEN-LAST:event_enableCheckBoxActionPerformed
266
private void browseButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_browseButtonActionPerformed
267
JFileChooser chooser = new JFileChooser();
268
FileUtil.preventFileChooserSymlinkTraversal(chooser, null);
269
chooser.setFileSelectionMode (JFileChooser.FILES_AND_DIRECTORIES);
270
chooser.setMultiSelectionEnabled(false);
271
chooser.setFileFilter(new IconFileFilter());
272
if (lastImageFolder != null) {
273
chooser.setSelectedFile(lastImageFolder);
275
// workDir = FileUtil.toFile(project.getProjectDirectory()).getAbsolutePath();
276
// chooser.setSelectedFile(new File(workDir));
278
chooser.setDialogTitle(NbBundle.getMessage(JWSCustomizerPanel.class, "LBL_Select_Icon_Image"));
279
if (JFileChooser.APPROVE_OPTION == chooser.showOpenDialog(this)) {
280
File file = FileUtil.normalizeFile(chooser.getSelectedFile());
281
iconTextField.setText(file.getAbsolutePath());
282
lastImageFolder = file.getParentFile();
284
}//GEN-LAST:event_browseButtonActionPerformed
286
public HelpCtx getHelpCtx() {
287
return new HelpCtx(JWSCustomizerPanel.class);
290
private static class IconFileFilter extends FileFilter {
292
// XXX should check size of images?
293
public boolean accept(File f) {
294
if (f.isDirectory()) {
297
String name = f.getName();
298
int index = name.lastIndexOf('.');
299
if (index > 0 && index < name.length() - 1) {
300
String ext = name.substring(index+1).toLowerCase();
301
if ("gif".equals(ext) || "png".equals(ext) || "jpg".equals(ext)) { // NOI18N
308
public String getDescription() {
309
return NbBundle.getMessage(JWSCustomizerPanel.class, "MSG_IconFileFilter_Description");
314
private CodebaseComboBoxModel getCBModel() {
315
return (CodebaseComboBoxModel) codebaseComboBox.getModel();
318
private void setCodebaseComponents() {
319
String value = getCBModel().getSelectedCodebaseItem();
320
if (JWSProjectProperties.CB_TYPE_LOCAL.equals(value)) {
321
codebaseTextField.setText(jwsProps.getProjectDistDir());
322
codebaseTextField.setEditable(false);
323
} else if (JWSProjectProperties.CB_TYPE_WEB.equals(value)) {
324
codebaseTextField.setText(JWSProjectProperties.CB_URL_WEB);
325
codebaseTextField.setEditable(false);
326
} else if (JWSProjectProperties.CB_TYPE_USER.equals(value)) {
327
codebaseTextField.setText(jwsProps.getCodebaseLocation());
328
codebaseTextField.setEditable(true);
332
private void setEnabledAllComponents(boolean b) {
333
iconLabel.setEnabled(b);
334
iconTextField.setEnabled(b);
335
browseButton.setEnabled(b);
336
codebaseLabel.setEnabled(b);
337
codebaseComboBox.setEnabled(b);
338
codebaseTextField.setEnabled(b);
339
offlineCheckBox.setEnabled(b);
340
signedCheckBox.setEnabled(b);
343
// Variables declaration - do not modify//GEN-BEGIN:variables
344
private javax.swing.JButton browseButton;
345
private javax.swing.JComboBox codebaseComboBox;
346
private javax.swing.JLabel codebaseLabel;
347
private javax.swing.JTextField codebaseTextField;
348
private javax.swing.JCheckBox enableCheckBox;
349
private javax.swing.JLabel iconLabel;
350
private javax.swing.JTextField iconTextField;
351
private javax.swing.JCheckBox offlineCheckBox;
352
private javax.swing.JLabel panelDescLabel;
353
private javax.swing.JCheckBox signedCheckBox;
354
// End of variables declaration//GEN-END:variables