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.core.ui.options.general;
44
import java.awt.Component;
45
import java.awt.event.ActionEvent;
46
import java.awt.event.ActionListener;
47
import javax.swing.AbstractButton;
48
import javax.swing.ButtonGroup;
49
import javax.swing.JLabel;
50
import javax.swing.JPanel;
51
import org.netbeans.beaninfo.editors.HtmlBrowser;
52
import org.openide.DialogDescriptor;
53
import org.openide.DialogDisplayer;
54
import org.openide.awt.Mnemonics;
55
import org.openide.util.Lookup;
56
import org.openide.util.NbBundle;
59
* Implementation of one panel in Options Dialog.
63
public class GeneralOptionsPanel extends JPanel implements ActionListener {
65
private boolean changed = false;
66
private GeneralOptionsModel model;
67
private HtmlBrowser.FactoryEditor editor;
68
private AdvancedProxyPanel advancedPanel;
72
* Creates new form GeneralOptionsPanel.
74
public GeneralOptionsPanel () {
77
loc (lWebBrowser, "Web_Browser");
78
loc (lWebProxy, "Web_Proxy");
79
loc (lProxyHost, "Proxy_Host");
80
loc (lProxyPort, "Proxy_Port");
83
cbWebBrowser.getAccessibleContext ().setAccessibleName (loc ("AN_Web_Browser"));
84
cbWebBrowser.getAccessibleContext ().setAccessibleDescription (loc ("AD_Web_Browser"));
85
tfProxyHost.getAccessibleContext ().setAccessibleName (loc ("AN_Host"));
86
tfProxyHost.getAccessibleContext ().setAccessibleDescription (loc ("AD_Host"));
87
tfProxyPort.getAccessibleContext ().setAccessibleName (loc ("AN_Port"));
88
tfProxyPort.getAccessibleContext ().setAccessibleDescription (loc ("AD_Port"));
89
rbNoProxy.addActionListener (this);
90
rbUseSystemProxy.addActionListener (this);
91
rbHTTPProxy.addActionListener (this);
92
cbWebBrowser.addActionListener (this);
93
tfProxyHost.addActionListener (this);
94
tfProxyPort.addActionListener (this);
96
ButtonGroup bgProxy = new ButtonGroup ();
97
bgProxy.add (rbNoProxy);
98
bgProxy.add (rbUseSystemProxy);
99
bgProxy.add (rbHTTPProxy);
100
loc (rbNoProxy, "No_Proxy");
101
loc (rbUseSystemProxy, "Use_System_Proxy_Settings");
102
loc (rbHTTPProxy, "Use_HTTP_Proxy");
104
// if system proxy setting is not detectable, disable this radio
106
if (System.getProperty("netbeans.system_http_proxy") == null) // NOI18N
107
rbUseSystemProxy.setEnabled(false);
110
/** This method is called from within the constructor to
111
* initialize the form.
112
* WARNING: Do NOT modify this code. The content of this method is
113
* always regenerated by the Form Editor.
115
// <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
116
private void initComponents() {
118
lWebBrowser = new javax.swing.JLabel();
119
cbWebBrowser = new javax.swing.JComboBox();
120
jSeparator2 = new javax.swing.JSeparator();
121
lWebProxy = new javax.swing.JLabel();
122
rbNoProxy = new javax.swing.JRadioButton();
123
rbUseSystemProxy = new javax.swing.JRadioButton();
124
rbHTTPProxy = new javax.swing.JRadioButton();
125
lProxyHost = new javax.swing.JLabel();
126
tfProxyHost = new javax.swing.JTextField();
127
lProxyPort = new javax.swing.JLabel();
128
tfProxyPort = new javax.swing.JTextField();
129
bMoreProxy = new javax.swing.JButton();
130
editBrowserButton = new javax.swing.JButton();
132
lWebBrowser.setLabelFor(cbWebBrowser);
133
org.openide.awt.Mnemonics.setLocalizedText(lWebBrowser, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.lWebBrowser.text")); // NOI18N
135
org.openide.awt.Mnemonics.setLocalizedText(lWebProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_lWebProxy")); // NOI18N
137
org.openide.awt.Mnemonics.setLocalizedText(rbNoProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbNoProxy.text")); // NOI18N
138
rbNoProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
140
org.openide.awt.Mnemonics.setLocalizedText(rbUseSystemProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.rbUseSystemProxy.text")); // NOI18N
141
rbUseSystemProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
143
org.openide.awt.Mnemonics.setLocalizedText(rbHTTPProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "CTL_Use_HTTP_Proxy", new Object[] {})); // NOI18N
144
rbHTTPProxy.setBorder(javax.swing.BorderFactory.createEmptyBorder(0, 0, 0, 0));
146
lProxyHost.setLabelFor(tfProxyHost);
147
org.openide.awt.Mnemonics.setLocalizedText(lProxyHost, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "CTL_Proxy_Host", new Object[] {})); // NOI18N
149
tfProxyHost.addFocusListener(new java.awt.event.FocusAdapter() {
150
public void focusGained(java.awt.event.FocusEvent evt) {
151
tfProxyHostFocusGained(evt);
153
public void focusLost(java.awt.event.FocusEvent evt) {
154
tfProxyHostFocusLost(evt);
158
lProxyPort.setLabelFor(tfProxyPort);
159
org.openide.awt.Mnemonics.setLocalizedText(lProxyPort, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "CTL_Proxy_Port", new Object[] {})); // NOI18N
161
tfProxyPort.setColumns(4);
162
tfProxyPort.addFocusListener(new java.awt.event.FocusAdapter() {
163
public void focusGained(java.awt.event.FocusEvent evt) {
164
tfProxyPortFocusGained(evt);
166
public void focusLost(java.awt.event.FocusEvent evt) {
167
tfProxyPortFocusLost(evt);
171
org.openide.awt.Mnemonics.setLocalizedText(bMoreProxy, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "LBL_GeneralOptionsPanel_bMoreProxy")); // NOI18N
172
bMoreProxy.addActionListener(new java.awt.event.ActionListener() {
173
public void actionPerformed(java.awt.event.ActionEvent evt) {
174
bMoreProxyActionPerformed(evt);
178
org.openide.awt.Mnemonics.setLocalizedText(editBrowserButton, org.openide.util.NbBundle.getMessage(GeneralOptionsPanel.class, "GeneralOptionsPanel.editBrowserButton.text")); // NOI18N
179
editBrowserButton.addActionListener(new java.awt.event.ActionListener() {
180
public void actionPerformed(java.awt.event.ActionEvent evt) {
181
editBrowserButtonActionPerformed(evt);
185
org.jdesktop.layout.GroupLayout layout = new org.jdesktop.layout.GroupLayout(this);
186
this.setLayout(layout);
187
layout.setHorizontalGroup(
188
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
189
.add(layout.createSequentialGroup()
191
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
192
.add(org.jdesktop.layout.GroupLayout.TRAILING, layout.createSequentialGroup()
195
.add(cbWebBrowser, 0, 903, Short.MAX_VALUE)
196
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
197
.add(editBrowserButton))
198
.add(jSeparator2, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 1058, Short.MAX_VALUE)
199
.add(layout.createSequentialGroup()
202
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
204
.add(rbUseSystemProxy)
206
.add(layout.createSequentialGroup()
208
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
210
.add(layout.createSequentialGroup()
212
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
213
.add(tfProxyHost, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, 795, Short.MAX_VALUE)
216
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
217
.add(tfProxyPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)))))))
220
layout.setVerticalGroup(
221
layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
222
.add(layout.createSequentialGroup()
224
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
226
.add(cbWebBrowser, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
227
.add(editBrowserButton))
229
.add(jSeparator2, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, 10, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
230
.addPreferredGap(org.jdesktop.layout.LayoutStyle.UNRELATED)
231
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.LEADING)
232
.add(layout.createSequentialGroup()
234
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
235
.add(rbUseSystemProxy)
236
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
239
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
240
.add(layout.createParallelGroup(org.jdesktop.layout.GroupLayout.BASELINE)
242
.add(tfProxyPort, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
243
.add(tfProxyHost, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE, org.jdesktop.layout.GroupLayout.DEFAULT_SIZE, org.jdesktop.layout.GroupLayout.PREFERRED_SIZE)
245
.addPreferredGap(org.jdesktop.layout.LayoutStyle.RELATED)
247
.addContainerGap(161, Short.MAX_VALUE))
249
}// </editor-fold>//GEN-END:initComponents
251
private void editBrowserButtonActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_editBrowserButtonActionPerformed
252
WebBrowsersOptionsModel wbModel = new WebBrowsersOptionsModel();
253
WebBrowsersOptionsPanel wbPanel = new WebBrowsersOptionsPanel(wbModel);
254
DialogDescriptor dialogDesc = new DialogDescriptor (wbPanel, loc("LBL_WebBrowsersPanel_Title"));
255
DialogDisplayer.getDefault().createDialog(dialogDesc).setVisible(true);
256
if (dialogDesc.getValue().equals(DialogDescriptor.OK_OPTION)) {
257
wbModel.applyChanges();
259
for (int i = 0, items = cbWebBrowser.getItemCount(); i < items; i++) {
260
Object item = cbWebBrowser.getItemAt(i);
261
if (item.equals(wbModel.getSelectedValue())) {
262
cbWebBrowser.setSelectedItem(item);
267
wbModel.discardChanges();
269
}//GEN-LAST:event_editBrowserButtonActionPerformed
271
private void bMoreProxyActionPerformed(java.awt.event.ActionEvent evt) {//GEN-FIRST:event_bMoreProxyActionPerformed
272
assert model != null : "Model found when AdvancedProxyPanel is created";
273
if (advancedPanel == null) {
274
advancedPanel = new AdvancedProxyPanel (model);
276
DialogDescriptor dd = new DialogDescriptor (advancedPanel, loc ("LBL_AdvancedProxyPanel_Title"));
277
advancedPanel.update (tfProxyHost.getText (), tfProxyPort.getText ());
278
DialogDisplayer.getDefault ().createDialog (dd).setVisible (true);
279
if (DialogDescriptor.OK_OPTION.equals (dd.getValue ())) {
280
advancedPanel.applyChanges ();
281
tfProxyHost.setText (model.getHttpProxyHost ());
282
tfProxyPort.setText (model.getHttpProxyPort ());
285
}//GEN-LAST:event_bMoreProxyActionPerformed
287
private void tfProxyPortFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfProxyPortFocusLost
288
tfProxyPort.select (0, 0);
289
}//GEN-LAST:event_tfProxyPortFocusLost
291
private void tfProxyHostFocusLost (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfProxyHostFocusLost
292
tfProxyHost.select (0, 0);
293
}//GEN-LAST:event_tfProxyHostFocusLost
295
private void tfProxyPortFocusGained (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfProxyPortFocusGained
296
tfProxyPort.setCaretPosition (0);
297
tfProxyPort.selectAll ();
298
}//GEN-LAST:event_tfProxyPortFocusGained
300
private void tfProxyHostFocusGained (java.awt.event.FocusEvent evt) {//GEN-FIRST:event_tfProxyHostFocusGained
301
tfProxyHost.setCaretPosition (0);
302
tfProxyHost.selectAll ();
303
}//GEN-LAST:event_tfProxyHostFocusGained
306
// Variables declaration - do not modify//GEN-BEGIN:variables
307
private javax.swing.JButton bMoreProxy;
308
private javax.swing.JComboBox cbWebBrowser;
309
private javax.swing.JButton editBrowserButton;
310
private javax.swing.JSeparator jSeparator2;
311
private javax.swing.JLabel lProxyHost;
312
private javax.swing.JLabel lProxyPort;
313
private javax.swing.JLabel lWebBrowser;
314
private javax.swing.JLabel lWebProxy;
315
private javax.swing.JRadioButton rbHTTPProxy;
316
private javax.swing.JRadioButton rbNoProxy;
317
private javax.swing.JRadioButton rbUseSystemProxy;
318
private javax.swing.JTextField tfProxyHost;
319
private javax.swing.JTextField tfProxyPort;
320
// End of variables declaration//GEN-END:variables
323
private static String loc (String key) {
324
return NbBundle.getMessage (GeneralOptionsPanel.class, key);
327
private static void loc (Component c, String key) {
328
if (!(c instanceof JLabel)) {
329
c.getAccessibleContext ().setAccessibleName (loc ("AN_" + key));
330
c.getAccessibleContext ().setAccessibleDescription (loc ("AD_" + key));
332
if (c instanceof AbstractButton) {
333
Mnemonics.setLocalizedText (
338
Mnemonics.setLocalizedText (
346
model = new GeneralOptionsModel ();
349
switch (model.getProxyType ()) {
351
rbNoProxy.setSelected (true);
352
tfProxyHost.setEnabled (false);
353
tfProxyPort.setEnabled (false);
354
bMoreProxy.setEnabled (false);
357
rbUseSystemProxy.setSelected (true);
358
tfProxyHost.setEnabled (false);
359
tfProxyPort.setEnabled (false);
360
bMoreProxy.setEnabled (false);
363
rbHTTPProxy.setSelected (true);
364
tfProxyHost.setEnabled (true);
365
tfProxyPort.setEnabled (true);
366
bMoreProxy.setEnabled (true);
369
tfProxyHost.setText (model.getHttpProxyHost ());
370
tfProxyPort.setText (model.getHttpProxyPort ());
377
private void updateWebBrowsers() {
378
if (editor == null) {
379
editor = Lookup.getDefault().lookup(HtmlBrowser.FactoryEditor.class);
381
cbWebBrowser.removeAllItems ();
382
String[] tags = editor.getTags ();
383
int i, k = tags.length;
384
for (i = 0; i < k; i++) {
385
cbWebBrowser.addItem (tags [i]);
387
cbWebBrowser.setSelectedItem (editor.getAsText ());
390
void applyChanges () {
391
// listening on JTextFields dont work!
392
// if (!changed) return;
394
if (model == null) return;
397
if (rbNoProxy.isSelected ()) {
398
model.setProxyType (0);
400
if (rbUseSystemProxy.isSelected ()) {
401
model.setProxyType (1);
403
model.setProxyType (2);
406
model.setHttpProxyHost (tfProxyHost.getText ());
407
model.setHttpProxyPort (tfProxyPort.getText ());
409
// web browser settings
410
if (editor == null) {
411
editor = Lookup.getDefault().lookup(HtmlBrowser.FactoryEditor.class);
413
editor.setAsText ((String) cbWebBrowser.getSelectedItem ());
419
boolean dataValid () {
423
boolean isChanged () {
424
if (model == null) return false;
425
if (!tfProxyHost.getText ().equals (model.getHttpProxyHost ())) return true;
426
if (!tfProxyPort.getText ().equals (model.getHttpProxyPort ())) return true;
430
public void actionPerformed (ActionEvent e) {
432
tfProxyHost.setEnabled (rbHTTPProxy.isSelected ());
433
tfProxyPort.setEnabled (rbHTTPProxy.isSelected ());
434
bMoreProxy.setEnabled (rbHTTPProxy.isSelected ());