KickJava   Java API By Example, From Geeks To Geeks.

Java > Open Source Codes > org > netbeans > modules > websvc > registry > ui > ProxySelectionDialog


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.websvc.registry.ui;
21
22 import org.netbeans.modules.websvc.registry.util.WebProxySetter;
23 import java.awt.Dialog JavaDoc;
24 import java.awt.event.ActionEvent JavaDoc;
25 import java.awt.event.ActionListener JavaDoc;
26 import java.awt.event.WindowAdapter JavaDoc;
27 import java.awt.event.WindowEvent JavaDoc;
28 import java.awt.Font JavaDoc;
29 import java.lang.ClassLoader JavaDoc;
30 import java.lang.reflect.Method JavaDoc;
31 import javax.swing.JDialog JavaDoc;
32 import javax.swing.JButton JavaDoc;
33 import javax.swing.JPanel JavaDoc;
34 import javax.swing.SwingUtilities JavaDoc;
35 import org.openide.DialogDescriptor;
36 import org.openide.DialogDisplayer;
37 import org.openide.ErrorManager;
38 import org.openide.NotifyDescriptor;
39 import org.openide.util.Lookup;
40 import org.openide.util.SharedClassObject;
41 import org.openide.util.NbBundle;
42
43 /**
44  *
45  * @author Winston Prakash
46  */

47 public class ProxySelectionDialog extends javax.swing.JPanel JavaDoc implements ActionListener JavaDoc {
48     
49     DialogDescriptor dlg = null;
50     Dialog JavaDoc dialog = null;
51     
52     private javax.swing.JLabel JavaDoc headerLabel;
53     private javax.swing.JTextField JavaDoc portText;
54     private javax.swing.JLabel JavaDoc portlabel;
55     private javax.swing.JTextField JavaDoc serverText;
56     private javax.swing.JLabel JavaDoc serverlabel;
57     
58     private JButton JavaDoc okButton;
59     private JButton JavaDoc cancelButton;
60     
61     private String JavaDoc okString = NbBundle.getMessage(this.getClass(), "OPTION_OK");
62     private String JavaDoc cancelString = NbBundle.getMessage(this.getClass(), "OPTION_CANCEL");
63     
64     public ProxySelectionDialog() {
65         initComponents();
66     }
67     
68     public void show(){
69         dlg = new DialogDescriptor(this, NbBundle.getMessage(this.getClass(), "SET_PROXY"),
70         true, NotifyDescriptor.OK_CANCEL_OPTION, DialogDescriptor.CANCEL_OPTION,this);
71         dlg.setOptions(new Object JavaDoc[] {okButton, cancelButton});
72         dialog = DialogDisplayer.getDefault().createDialog(dlg);
73         dialog.setVisible(true);
74         
75         /**
76          * After the window is opened, set the focus to the Get information button.
77          */

78         
79         final JPanel JavaDoc thisPanel = this;
80         dialog.addWindowListener( new WindowAdapter JavaDoc(){
81             public void windowOpened( WindowEvent JavaDoc e ){
82                 SwingUtilities.invokeLater(
83                 new Runnable JavaDoc() {
84                     public void run() {
85                         okButton.requestFocus();
86                         thisPanel.getRootPane().setDefaultButton(okButton);
87                     }
88                 });
89             }
90         });
91         
92         
93         /*JDialog dialog = new JDialog();
94         dialog.addWindowListener(new WindowAdapter(){
95             public void windowClosing(WindowEvent e){
96                 System.setProperty("http.proxyHost", serverText.getText());
97                 System.out.println(System.getProperty("http.proxyHost"));
98                 System.setProperty("http.proxyPort", portText.getText());
99                 System.out.println(System.getProperty("http.proxyPort"));
100             }
101         });
102         dialog.getContentPane().add(this);
103         dialog.pack();
104         dialog.show();*/

105     }
106     
107     private void initComponents() {
108         java.awt.GridBagConstraints JavaDoc gridBagConstraints;
109         
110         serverlabel = new javax.swing.JLabel JavaDoc();
111         serverText = new javax.swing.JTextField JavaDoc();
112         portlabel = new javax.swing.JLabel JavaDoc();
113         portText = new javax.swing.JTextField JavaDoc();
114         headerLabel = new javax.swing.JLabel JavaDoc();
115         
116         okButton = new JButton JavaDoc(okString);
117         cancelButton = new JButton JavaDoc(cancelString);
118         
119         setLayout(new java.awt.GridBagLayout JavaDoc());
120         
121         setBorder(new javax.swing.border.EmptyBorder JavaDoc(new java.awt.Insets JavaDoc(10, 10, 10, 10)));
122         serverlabel.setText(NbBundle.getMessage(this.getClass(), "LBL_HTTP_PROXY_SERVER"));
123         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
124         gridBagConstraints.gridx = 0;
125         gridBagConstraints.gridy = 1;
126         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
127         gridBagConstraints.insets = new java.awt.Insets JavaDoc(1, 0, 1, 0);
128         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
129         add(serverlabel, gridBagConstraints);
130         
131         serverText.setText(WebProxySetter.getInstance().getProxyHost());
132         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
133         gridBagConstraints.gridx = 1;
134         gridBagConstraints.gridy = 1;
135         gridBagConstraints.gridwidth = java.awt.GridBagConstraints.REMAINDER;
136         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
137         gridBagConstraints.ipadx = 5;
138         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 0);
139         gridBagConstraints.weightx = 1.0;
140         add(serverText, gridBagConstraints);
141         
142         portlabel.setText(NbBundle.getMessage(this.getClass(), "LBL_HTTP_PROXY_PORT"));
143         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
144         gridBagConstraints.gridx = 0;
145         gridBagConstraints.gridy = 2;
146         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
147         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 1, 6, 1);
148         gridBagConstraints.anchor = java.awt.GridBagConstraints.WEST;
149         add(portlabel, gridBagConstraints);
150         
151         portText.setText(WebProxySetter.getInstance().getProxyPort());
152         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
153         gridBagConstraints.gridx = 1;
154         gridBagConstraints.gridy = 2;
155         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
156         gridBagConstraints.ipadx = 5;
157         gridBagConstraints.insets = new java.awt.Insets JavaDoc(0, 5, 0, 0);
158         gridBagConstraints.weightx = 1.0;
159         add(portText, gridBagConstraints);
160         
161         headerLabel.setText(NbBundle.getMessage(this.getClass(), "LBL_MANUAL_PROXY_SETTING"));
162         Font JavaDoc currentFont = headerLabel.getFont();
163         Font JavaDoc boldFont = currentFont.deriveFont(Font.BOLD);
164         headerLabel.setFont(boldFont);
165         gridBagConstraints = new java.awt.GridBagConstraints JavaDoc();
166         gridBagConstraints.gridx = 0;
167         gridBagConstraints.gridy = 0;
168         gridBagConstraints.gridwidth = 3;
169         gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL;
170         gridBagConstraints.insets = new java.awt.Insets JavaDoc(12, 0, 12, 0);
171         gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER;
172         add(headerLabel, gridBagConstraints);
173         
174         
175     }
176     
177     public void actionPerformed(ActionEvent JavaDoc evt) {
178         String JavaDoc actionCommand = evt.getActionCommand();
179         if(actionCommand.equalsIgnoreCase(okString)) {
180             WebProxySetter.getInstance().setProxyConfiguration(serverText.getText().trim(), portText.getText().trim());
181             dialog.dispose();
182         } else if(actionCommand.equalsIgnoreCase(cancelString)) {
183             dialog.dispose();
184         }
185         
186     }
187     
188 }
189
Popular Tags