1 19 20 package org.netbeans.modules.websvc.registry.ui; 21 22 import org.netbeans.modules.websvc.registry.util.WebProxySetter; 23 import java.awt.Dialog ; 24 import java.awt.event.ActionEvent ; 25 import java.awt.event.ActionListener ; 26 import java.awt.event.WindowAdapter ; 27 import java.awt.event.WindowEvent ; 28 import java.awt.Font ; 29 import java.lang.ClassLoader ; 30 import java.lang.reflect.Method ; 31 import javax.swing.JDialog ; 32 import javax.swing.JButton ; 33 import javax.swing.JPanel ; 34 import javax.swing.SwingUtilities ; 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 47 public class ProxySelectionDialog extends javax.swing.JPanel implements ActionListener { 48 49 DialogDescriptor dlg = null; 50 Dialog dialog = null; 51 52 private javax.swing.JLabel headerLabel; 53 private javax.swing.JTextField portText; 54 private javax.swing.JLabel portlabel; 55 private javax.swing.JTextField serverText; 56 private javax.swing.JLabel serverlabel; 57 58 private JButton okButton; 59 private JButton cancelButton; 60 61 private String okString = NbBundle.getMessage(this.getClass(), "OPTION_OK"); 62 private String 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 [] {okButton, cancelButton}); 72 dialog = DialogDisplayer.getDefault().createDialog(dlg); 73 dialog.setVisible(true); 74 75 78 79 final JPanel thisPanel = this; 80 dialog.addWindowListener( new WindowAdapter (){ 81 public void windowOpened( WindowEvent e ){ 82 SwingUtilities.invokeLater( 83 new Runnable () { 84 public void run() { 85 okButton.requestFocus(); 86 thisPanel.getRootPane().setDefaultButton(okButton); 87 } 88 }); 89 } 90 }); 91 92 93 105 } 106 107 private void initComponents() { 108 java.awt.GridBagConstraints gridBagConstraints; 109 110 serverlabel = new javax.swing.JLabel (); 111 serverText = new javax.swing.JTextField (); 112 portlabel = new javax.swing.JLabel (); 113 portText = new javax.swing.JTextField (); 114 headerLabel = new javax.swing.JLabel (); 115 116 okButton = new JButton (okString); 117 cancelButton = new JButton (cancelString); 118 119 setLayout(new java.awt.GridBagLayout ()); 120 121 setBorder(new javax.swing.border.EmptyBorder (new java.awt.Insets (10, 10, 10, 10))); 122 serverlabel.setText(NbBundle.getMessage(this.getClass(), "LBL_HTTP_PROXY_SERVER")); 123 gridBagConstraints = new java.awt.GridBagConstraints (); 124 gridBagConstraints.gridx = 0; 125 gridBagConstraints.gridy = 1; 126 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 127 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (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 (); 144 gridBagConstraints.gridx = 0; 145 gridBagConstraints.gridy = 2; 146 gridBagConstraints.fill = java.awt.GridBagConstraints.HORIZONTAL; 147 gridBagConstraints.insets = new java.awt.Insets (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 (); 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 (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 currentFont = headerLabel.getFont(); 163 Font boldFont = currentFont.deriveFont(Font.BOLD); 164 headerLabel.setFont(boldFont); 165 gridBagConstraints = new java.awt.GridBagConstraints (); 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 (12, 0, 12, 0); 171 gridBagConstraints.anchor = java.awt.GridBagConstraints.CENTER; 172 add(headerLabel, gridBagConstraints); 173 174 175 } 176 177 public void actionPerformed(ActionEvent evt) { 178 String 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 |