001: /*
002: * DO NOT ALTER OR REMOVE COPYRIGHT NOTICES OR THIS HEADER.
003: *
004: * Copyright 1997-2007 Sun Microsystems, Inc. All rights reserved.
005: *
006: * The contents of this file are subject to the terms of either the GNU General
007: * Public License Version 2 only ("GPL") or the Common Development and Distribution
008: * License("CDDL") (collectively, the "License"). You may not use this file except in
009: * compliance with the License. You can obtain a copy of the License at
010: * http://www.netbeans.org/cddl-gplv2.html or nbbuild/licenses/CDDL-GPL-2-CP. See the
011: * License for the specific language governing permissions and limitations under the
012: * License. When distributing the software, include this License Header Notice in
013: * each file and include the License file at nbbuild/licenses/CDDL-GPL-2-CP. Sun
014: * designates this particular file as subject to the "Classpath" exception as
015: * provided by Sun in the GPL Version 2 section of the License file that
016: * accompanied this code. If applicable, add the following below the License Header,
017: * with the fields enclosed by brackets [] replaced by your own identifying
018: * information: "Portions Copyrighted [year] [name of copyright owner]"
019: *
020: * Contributor(s):
021: *
022: * The Original Software is NetBeans. The Initial Developer of the Original Software
023: * is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun Microsystems, Inc. All
024: * Rights Reserved.
025: *
026: * If you wish your version of this file to be governed by only the CDDL or only the
027: * GPL Version 2, indicate your decision by adding "[Contributor] elects to include
028: * this software in this distribution under the [CDDL or GPL Version 2] license." If
029: * you do not indicate a single choice of license, a recipient has the option to
030: * distribute your version of this file under either the CDDL, the GPL Version 2 or
031: * to extend the choice of license to its licensees as provided above. However, if
032: * you add GPL Version 2 code and therefore, elected the GPL Version 2 license, then
033: * the option applies only if the new code is made subject to such option by the
034: * copyright holder.
035: */
036:
037: package org.netbeans.installer.downloader.ui;
038:
039: import java.awt.GridBagConstraints;
040: import java.awt.GridBagLayout;
041: import java.awt.Insets;
042: import java.awt.event.ActionEvent;
043: import java.awt.event.ActionListener;
044: import java.net.InetSocketAddress;
045: import java.net.Proxy;
046: import java.net.Proxy.Type;
047: import org.netbeans.installer.downloader.DownloadManager;
048: import org.netbeans.installer.downloader.connector.MyProxy;
049: import org.netbeans.installer.downloader.connector.MyProxyType;
050: import org.netbeans.installer.downloader.connector.URLConnector;
051: import org.netbeans.installer.utils.ErrorManager;
052: import org.netbeans.installer.utils.StringUtils;
053: import org.netbeans.installer.utils.helper.swing.NbiButton;
054: import org.netbeans.installer.utils.helper.swing.NbiCheckBox;
055: import org.netbeans.installer.utils.helper.swing.NbiDialog;
056: import org.netbeans.installer.utils.helper.swing.NbiLabel;
057: import org.netbeans.installer.utils.helper.swing.NbiTextField;
058: import org.netbeans.installer.utils.helper.swing.NbiTextPane;
059:
060: /**
061: *
062: * @author Danila_Dugurov
063: */
064: public class ProxySettingsDialog extends NbiDialog {
065: private URLConnector connector = URLConnector.getConnector();
066:
067: private NbiTextPane messagePane;
068:
069: private NbiLabel proxyHostLabel;
070: private NbiTextField proxyHostField;
071: private NbiLabel proxyPortLabel;
072: private NbiTextField proxyPortField;
073: private NbiLabel ignoreListLabel;
074: private NbiTextField ignoreListField;
075:
076: private NbiCheckBox useProxyCheckBox;
077:
078: private NbiButton applyButton;
079: private NbiButton closeButton;
080:
081: public ProxySettingsDialog() {
082: super ();
083:
084: initComponents();
085: }
086:
087: public void execute() {
088: setVisible(true);
089:
090: while (isVisible()) {
091: try {
092: Thread.sleep(100);
093: } catch (InterruptedException e) {
094: ErrorManager.notifyDebug("Interrupted", e);
095: }
096: }
097: }
098:
099: private void initComponents() {
100: Proxy proxy = connector.getProxy(MyProxyType.HTTP);
101: InetSocketAddress address = proxy != null ? (InetSocketAddress) proxy
102: .address()
103: : null;
104:
105: setTitle("Connectivity Problems");
106: setLayout(new GridBagLayout());
107:
108: messagePane = new NbiTextPane();
109: messagePane
110: .setText("The installation wizard failed to "
111: + "connect to the registry server. Most likely this is "
112: + "caused by proxies misconfiguration. Please check the "
113: + "HTTP proxy settings below and click Apply to change "
114: + "them. Click Close to exit the installer.");
115:
116: useProxyCheckBox = new NbiCheckBox();
117: useProxyCheckBox.setText("Use proxy");
118: useProxyCheckBox.addActionListener(new ActionListener() {
119: public void actionPerformed(ActionEvent event) {
120: if (useProxyCheckBox.isSelected()) {
121: proxyHostField.setEnabled(true);
122: proxyPortField.setEnabled(true);
123: ignoreListField.setEnabled(true);
124: } else {
125: proxyHostField.setEnabled(false);
126: proxyPortField.setEnabled(false);
127: ignoreListField.setEnabled(false);
128: }
129: }
130: });
131: useProxyCheckBox.setSelected(connector.getUseProxy());
132:
133: proxyHostField = new NbiTextField();
134: if (address != null) {
135: proxyHostField.setText(address.getHostName());
136: }
137:
138: proxyHostLabel = new NbiLabel();
139: proxyHostLabel.setLabelFor(proxyHostField);
140: proxyHostLabel.setText("Host:");
141:
142: proxyPortField = new NbiTextField();
143: if (address != null) {
144: proxyPortField.setText(Integer.toString(address.getPort()));
145: }
146:
147: proxyPortLabel = new NbiLabel();
148: proxyPortLabel.setLabelFor(proxyPortField);
149: proxyPortLabel.setText("Port:");
150:
151: ignoreListField = new NbiTextField();
152:
153: if (address != null) {
154: ignoreListField.setText(StringUtils.asString(connector
155: .getByPassHosts(), ","));
156: }
157:
158: ignoreListLabel = new NbiLabel();
159: ignoreListLabel.setLabelFor(ignoreListField);
160: ignoreListLabel.setText("Bypass proxy for:");
161:
162: applyButton = new NbiButton();
163: applyButton.setText("&Apply");
164: applyButton.addActionListener(new ActionListener() {
165: public void actionPerformed(ActionEvent event) {
166: Proxy proxy = null;
167:
168: if (useProxyCheckBox.isSelected()) {
169: proxy = new Proxy(
170: Type.HTTP,
171: new InetSocketAddress(proxyHostField
172: .getText(), Integer
173: .parseInt(proxyPortField.getText())));
174:
175: connector.addProxy(new MyProxy(proxy,
176: MyProxyType.HTTP));
177:
178: connector.clearByPassList();
179: for (String host : StringUtils.asList(
180: ignoreListField.getText(), ",")) {
181: connector.addByPassHost(host);
182: }
183: }
184:
185: connector.setUseProxy(useProxyCheckBox.isSelected());
186:
187: setVisible(false);
188: }
189: });
190:
191: closeButton = new NbiButton();
192: closeButton.setText("&Close");
193: closeButton.addActionListener(new ActionListener() {
194: public void actionPerformed(ActionEvent event) {
195: DownloadManager.getInstance().getFinishHandler()
196: .criticalExit();
197: }
198: });
199:
200: if (useProxyCheckBox.isSelected()) {
201: proxyHostField.setEnabled(true);
202: proxyPortField.setEnabled(true);
203: ignoreListField.setEnabled(true);
204: } else {
205: proxyHostField.setEnabled(false);
206: proxyPortField.setEnabled(false);
207: ignoreListField.setEnabled(false);
208: }
209:
210: add(messagePane, new GridBagConstraints(0, 0, // x, y
211: 3, 1, // width, height
212: 1.0, 0.0, // weight-x, weight-y
213: GridBagConstraints.LINE_START, // anchor
214: GridBagConstraints.HORIZONTAL, // fill
215: new Insets(11, 11, 0, 11), // padding
216: 0, 0)); // padx, pady - ???
217:
218: add(useProxyCheckBox, new GridBagConstraints(0, 1, // x, y
219: 3, 1, // width, height
220: 1.0, 0.0, // weight-x, weight-y
221: GridBagConstraints.LINE_START, // anchor
222: GridBagConstraints.HORIZONTAL, // fill
223: new Insets(11, 11, 0, 11), // padding
224: 0, 0)); // padx, pady - ???
225:
226: add(proxyHostLabel, new GridBagConstraints(0, 2, // x, y
227: 1, 1, // width, height
228: 0.0, 0.0, // weight-x, weight-y
229: GridBagConstraints.LINE_START, // anchor
230: GridBagConstraints.HORIZONTAL, // fill
231: new Insets(6, 11, 0, 0), // padding
232: 0, 0)); // padx, pady - ???
233:
234: add(proxyHostField, new GridBagConstraints(1, 2, // x, y
235: 2, 1, // width, height
236: 1.0, 0.0, // weight-x, weight-y
237: GridBagConstraints.LINE_START, // anchor
238: GridBagConstraints.HORIZONTAL, // fill
239: new Insets(6, 6, 0, 11), // padding
240: 0, 0)); // padx, pady - ???
241:
242: add(proxyPortLabel, new GridBagConstraints(0, 3, // x, y
243: 1, 1, // width, height
244: 0.0, 0.0, // weight-x, weight-y
245: GridBagConstraints.LINE_START, // anchor
246: GridBagConstraints.HORIZONTAL, // fill
247: new Insets(6, 11, 0, 0), // padding
248: 0, 0)); // padx, pady - ???
249:
250: add(proxyPortField, new GridBagConstraints(1, 3, // x, y
251: 2, 1, // width, height
252: 1.0, 0.0, // weight-x, weight-y
253: GridBagConstraints.LINE_START, // anchor
254: GridBagConstraints.HORIZONTAL, // fill
255: new Insets(6, 6, 0, 11), // padding
256: 0, 0)); // padx, pady - ???
257:
258: add(ignoreListLabel, new GridBagConstraints(0, 4, // x, y
259: 1, 1, // width, height
260: 0.0, 0.0, // weight-x, weight-y
261: GridBagConstraints.LINE_START, // anchor
262: GridBagConstraints.HORIZONTAL, // fill
263: new Insets(6, 11, 0, 0), // padding
264: 0, 0)); // padx, pady - ???
265:
266: add(ignoreListField, new GridBagConstraints(1, 4, // x, y
267: 2, 1, // width, height
268: 1.0, 0.0, // weight-x, weight-y
269: GridBagConstraints.LINE_START, // anchor
270: GridBagConstraints.HORIZONTAL, // fill
271: new Insets(6, 6, 0, 11), // padding
272: 0, 0)); // padx, pady - ???
273:
274: add(applyButton, new GridBagConstraints(1, 5, // x, y
275: 1, 1, // width, height
276: 1.0, 1.0, // weight-x, weight-y
277: GridBagConstraints.SOUTHEAST, // anchor
278: GridBagConstraints.NONE, // fill
279: new Insets(17, 11, 11, 0), // padding
280: 0, 0)); // padx, pady - ???
281: add(closeButton, new GridBagConstraints(2, 5, // x, y
282: 1, 1, // width, height
283: 0.0, 1.0, // weight-x, weight-y
284: GridBagConstraints.SOUTHEAST, // anchor
285: GridBagConstraints.NONE, // fill
286: new Insets(17, 6, 11, 11), // padding
287: 0, 0)); // padx, pady - ???
288: }
289: }
|