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
007: * General Public License Version 2 only ("GPL") or the Common
008: * Development and Distribution License("CDDL") (collectively, the
009: * "License"). You may not use this file except in compliance with the
010: * License. You can obtain a copy of the License at
011: * http://www.netbeans.org/cddl-gplv2.html
012: * or nbbuild/licenses/CDDL-GPL-2-CP. See the License for the
013: * specific language governing permissions and limitations under the
014: * License. When distributing the software, include this License Header
015: * Notice in each file and include the License file at
016: * nbbuild/licenses/CDDL-GPL-2-CP. Sun designates this
017: * particular file as subject to the "Classpath" exception as provided
018: * by Sun in the GPL Version 2 section of the License file that
019: * accompanied this code. If applicable, add the following below the
020: * License Header, with the fields enclosed by brackets [] replaced by
021: * your own identifying information:
022: * "Portions Copyrighted [year] [name of copyright owner]"
023: *
024: * Contributor(s):
025: *
026: * The Original Software is NetBeans. The Initial Developer of the Original
027: * Software is Sun Microsystems, Inc. Portions Copyright 1997-2007 Sun
028: * Microsystems, Inc. All Rights Reserved.
029: *
030: * If you wish your version of this file to be governed by only the CDDL
031: * or only the GPL Version 2, indicate your decision by adding
032: * "[Contributor] elects to include this software in this distribution
033: * under the [CDDL or GPL Version 2] license." If you do not indicate a
034: * single choice of license, a recipient has the option to distribute
035: * your version of this file under either the CDDL, the GPL Version 2 or
036: * to extend the choice of license to its licensees as provided above.
037: * However, if you add GPL Version 2 code and therefore, elected the GPL
038: * Version 2 license, then the option applies only if the new code is
039: * made subject to such option by the copyright holder.
040: */
041:
042: package org.netbeans.projectopener;
043:
044: import java.awt.Dimension;
045: import java.awt.Point;
046: import java.awt.Toolkit;
047: import javax.swing.JFrame;
048: import javax.swing.UIManager;
049: import org.netbeans.projectopener.Utils.DialogDescriptor;
050: import org.netbeans.projectopener.Utils.ProxySettings;
051:
052: /**
053: *
054: * @author Milan Kubec
055: */
056: public class ProxySettingsDialog extends javax.swing.JDialog {
057:
058: private ProxySettings proxySettings;
059: private DialogDescriptor dialogDesc;
060:
061: /** Creates new form ProxySettingsDialog */
062: public ProxySettingsDialog(ProxySettings ps, DialogDescriptor dd) {
063: super ((JFrame) null, true);
064: proxySettings = ps;
065: dialogDesc = dd;
066: try {
067: UIManager.setLookAndFeel(UIManager
068: .getSystemLookAndFeelClassName());
069: } catch (Exception ex) {
070: //
071: }
072: initComponents();
073: getRootPane().setDefaultButton(contButton);
074: hostTextField.setText(proxySettings.getProxyHost());
075: portTextField.setText(proxySettings.getProxyPort());
076: setLocation(getCenterPoint());
077: }
078:
079: /** This method is called from within the constructor to
080: * initialize the form.
081: * WARNING: Do NOT modify this code. The content of this method is
082: * always regenerated by the Form Editor.
083: */
084: // <editor-fold defaultstate="collapsed" desc=" Generated Code ">//GEN-BEGIN:initComponents
085: private void initComponents() {
086: java.awt.GridBagConstraints gridBagConstraints;
087:
088: jPanel1 = new javax.swing.JPanel();
089: titleLabel = new javax.swing.JLabel();
090: hostLabel = new javax.swing.JLabel();
091: portLabel = new javax.swing.JLabel();
092: hostTextField = new javax.swing.JTextField();
093: portTextField = new javax.swing.JTextField();
094: jPanel2 = new javax.swing.JPanel();
095: contButton = new javax.swing.JButton();
096: exitButton = new javax.swing.JButton();
097:
098: setDefaultCloseOperation(javax.swing.WindowConstants.DISPOSE_ON_CLOSE);
099: java.util.ResourceBundle bundle = java.util.ResourceBundle
100: .getBundle("org/netbeans/projectopener/Bundle"); // NOI18N
101: setTitle(bundle.getString("BadProxyDialogTitle")); // NOI18N
102:
103: jPanel1.setLayout(new java.awt.GridBagLayout());
104:
105: titleLabel.setText(bundle.getString("BadProxyLabel")); // NOI18N
106: gridBagConstraints = new java.awt.GridBagConstraints();
107: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
108: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
109: gridBagConstraints.insets = new java.awt.Insets(8, 8, 12, 16);
110: jPanel1.add(titleLabel, gridBagConstraints);
111:
112: hostLabel.setText(bundle.getString("hostLabel")); // NOI18N
113: gridBagConstraints = new java.awt.GridBagConstraints();
114: gridBagConstraints.gridx = 0;
115: gridBagConstraints.gridy = 1;
116: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
117: gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
118: jPanel1.add(hostLabel, gridBagConstraints);
119:
120: portLabel.setText(bundle.getString("portLabel")); // NOI18N
121: gridBagConstraints = new java.awt.GridBagConstraints();
122: gridBagConstraints.gridx = 2;
123: gridBagConstraints.gridy = 1;
124: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
125: gridBagConstraints.insets = new java.awt.Insets(0, 8, 0, 0);
126: jPanel1.add(portLabel, gridBagConstraints);
127:
128: hostTextField.setMinimumSize(new java.awt.Dimension(200, 20));
129: hostTextField.setPreferredSize(new java.awt.Dimension(200, 20));
130: gridBagConstraints = new java.awt.GridBagConstraints();
131: gridBagConstraints.gridx = 1;
132: gridBagConstraints.gridy = 1;
133: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
134: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
135: gridBagConstraints.weightx = 0.8;
136: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 0);
137: jPanel1.add(hostTextField, gridBagConstraints);
138: gridBagConstraints = new java.awt.GridBagConstraints();
139: gridBagConstraints.gridx = 3;
140: gridBagConstraints.gridy = 1;
141: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
142: gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
143: gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
144: gridBagConstraints.insets = new java.awt.Insets(0, 4, 0, 8);
145: jPanel1.add(portTextField, gridBagConstraints);
146:
147: jPanel2.setLayout(new java.awt.GridBagLayout());
148:
149: contButton.setText(bundle.getString("contButtonLabel")); // NOI18N
150: contButton
151: .addActionListener(new java.awt.event.ActionListener() {
152: public void actionPerformed(
153: java.awt.event.ActionEvent evt) {
154: contButtonActionPerformed(evt);
155: }
156: });
157: gridBagConstraints = new java.awt.GridBagConstraints();
158: gridBagConstraints.insets = new java.awt.Insets(0, 0, 8, 0);
159: jPanel2.add(contButton, gridBagConstraints);
160:
161: exitButton.setText(bundle.getString("exitButtonLabel")); // NOI18N
162: exitButton
163: .addActionListener(new java.awt.event.ActionListener() {
164: public void actionPerformed(
165: java.awt.event.ActionEvent evt) {
166: exitButtonActionPerformed(evt);
167: }
168: });
169: gridBagConstraints = new java.awt.GridBagConstraints();
170: gridBagConstraints.insets = new java.awt.Insets(0, 8, 8, 8);
171: jPanel2.add(exitButton, gridBagConstraints);
172:
173: gridBagConstraints = new java.awt.GridBagConstraints();
174: gridBagConstraints.gridx = 2;
175: gridBagConstraints.gridy = 2;
176: gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
177: gridBagConstraints.gridheight = java.awt.GridBagConstraints.REMAINDER;
178: gridBagConstraints.anchor = java.awt.GridBagConstraints.EAST;
179: gridBagConstraints.insets = new java.awt.Insets(12, 0, 0, 0);
180: jPanel1.add(jPanel2, gridBagConstraints);
181:
182: getContentPane().add(jPanel1, java.awt.BorderLayout.CENTER);
183:
184: pack();
185: }// </editor-fold>//GEN-END:initComponents
186:
187: private void exitButtonActionPerformed(
188: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_exitButtonActionPerformed
189: dialogDesc.setValue(DialogDescriptor.EXIT);
190: setVisible(false);
191: }//GEN-LAST:event_exitButtonActionPerformed
192:
193: private void contButtonActionPerformed(
194: java.awt.event.ActionEvent evt) {//GEN-FIRST:event_contButtonActionPerformed
195: dialogDesc.setValue(DialogDescriptor.CONTINUE);
196: proxySettings.setProxyHost(stripHttp(hostTextField.getText()));
197: proxySettings.setProxyPort(portTextField.getText());
198: setVisible(false);
199: }//GEN-LAST:event_contButtonActionPerformed
200:
201: private String stripHttp(String s) {
202: if (s.startsWith("http://")) {
203: return s.substring("http://".length());
204: }
205: return s;
206: }
207:
208: private Point getCenterPoint() {
209: Toolkit toolkit = Toolkit.getDefaultToolkit();
210: Dimension screenSize = toolkit.getScreenSize();
211: int x = (screenSize.width - getWidth() - getInsets().left - getInsets().right) / 2;
212: int y = (screenSize.height - getHeight() - getInsets().top - getInsets().bottom) / 2;
213: return new Point(x, y);
214: }
215:
216: // Variables declaration - do not modify//GEN-BEGIN:variables
217: private javax.swing.JButton contButton;
218: private javax.swing.JButton exitButton;
219: private javax.swing.JLabel hostLabel;
220: private javax.swing.JTextField hostTextField;
221: private javax.swing.JPanel jPanel1;
222: private javax.swing.JPanel jPanel2;
223: private javax.swing.JLabel portLabel;
224: private javax.swing.JTextField portTextField;
225: private javax.swing.JLabel titleLabel;
226: // End of variables declaration//GEN-END:variables
227:
228: }
|