@ -55,6 +55,26 @@ public class GlobalProxyConfigForm
* /
private JPasswordField passwordField = new JPasswordField ( ) ;
/ * *
* The dns forward global checkbox , hides / shows the panel with values .
* /
private JCheckBox dnsForwardCheck = new JCheckBox ( ) ;
/ * *
* Dns server address initially filled with the value of the proxy .
* /
private JTextField dnsForwardServerAddressField = new JTextField ( ) ;
/ * *
* Dns server port , initially filled with the value of the proxy .
* /
private JTextField dnsForwardPortField = new JTextField ( ) ;
/ * *
* Tha panel containing address and port for dns forwarding .
* /
private TransparentPanel dnsAddressPane ;
/ * *
* Creates the form .
* /
@ -63,7 +83,6 @@ public GlobalProxyConfigForm()
super ( new BorderLayout ( ) ) ;
init ( ) ;
loadValues ( ) ;
}
/ * *
@ -71,11 +90,6 @@ public GlobalProxyConfigForm()
* /
private void init ( )
{
serverAddressField . addKeyListener ( this ) ;
portField . addKeyListener ( this ) ;
usernameField . addKeyListener ( this ) ;
passwordField . addKeyListener ( this ) ;
TransparentPanel centerPanel = new TransparentPanel ( new GridBagLayout ( ) ) ;
GridBagConstraints constraints = new GridBagConstraints ( ) ;
@ -108,7 +122,6 @@ private void init()
constraints . gridy = 0 ;
constraints . gridwidth = 3 ;
typeCombo = new JComboBox ( ProxyInfo . ProxyType . values ( ) ) ;
typeCombo . addActionListener ( this ) ;
typeCombo . setEditable ( false ) ;
centerPanel . add ( typeCombo , constraints ) ;
@ -136,7 +149,7 @@ private void init()
constraints . gridy = 4 ;
constraints . gridwidth = 4 ;
constraints . gridheight = 2 ;
constraints . insets = new Insets ( 20, 15 , 2 0, 15 ) ;
constraints . insets = new Insets ( 15, 15 , 0, 15 ) ;
JTextPane pane = new JTextPane ( ) ;
pane . setEditable ( false ) ;
pane . setOpaque ( false ) ;
@ -167,7 +180,60 @@ private void init()
table ,
constraints ) ;
constraints . weightx = 0 ;
constraints . gridx = 0 ;
constraints . gridy = 9 ;
constraints . gridwidth = 4 ;
constraints . gridheight = 1 ;
constraints . insets = new Insets ( 5 , 10 , 0 , 0 ) ;
dnsForwardCheck . setText ( Resources . getResources ( )
. getI18NString ( "plugin.globalproxy.FWD_DNS" ) ) ;
centerPanel . add ( dnsForwardCheck , constraints ) ;
constraints . gridy = 10 ;
constraints . insets = new Insets ( 0 , 38 , 0 , 0 ) ;
String dnsForwardLabelText = Resources . getResources ( )
. getI18NString ( "plugin.globalproxy.FWD_DNS_NOTE" ) ;
JTextPane dnspane = new JTextPane ( ) ;
dnspane . setEditable ( false ) ;
dnspane . setOpaque ( false ) ;
dnspane . setText ( dnsForwardLabelText ) ;
dnspane . setForeground ( Color . GRAY ) ;
dnspane . setFont ( dnspane . getFont ( ) . deriveFont ( 8 ) ) ;
centerPanel . add ( dnspane , constraints ) ;
constraints . gridy = 11 ;
constraints . gridwidth = 4 ;
constraints . gridheight = 2 ;
dnsAddressPane =
new TransparentPanel ( new GridLayout ( 2 , 2 ) ) ;
dnsAddressPane . add ( new JLabel ( Resources . getResources ( )
. getI18NString ( "plugin.globalproxy.FWD_DNS_ADDR" ) ) ) ;
dnsAddressPane . add ( dnsForwardServerAddressField ) ;
dnsAddressPane . add ( new JLabel ( Resources . getResources ( )
. getI18NString ( "plugin.globalproxy.FWD_DNS_PORT" ) ) ) ;
dnsAddressPane . add ( dnsForwardPortField ) ;
dnsAddressPane . setVisible ( false ) ;
centerPanel . add ( dnsAddressPane , constraints ) ;
add ( centerPanel , BorderLayout . NORTH ) ;
loadValues ( ) ;
// now after loading has finished we can add all the listeners
// so we can get further changes
serverAddressField . addKeyListener ( this ) ;
portField . addKeyListener ( this ) ;
usernameField . addKeyListener ( this ) ;
passwordField . addKeyListener ( this ) ;
typeCombo . addActionListener ( this ) ;
dnsForwardServerAddressField . addKeyListener ( this ) ;
dnsForwardPortField . addKeyListener ( this ) ;
dnsForwardCheck . addActionListener ( this ) ;
}
/ * *
@ -219,6 +285,23 @@ private void loadValues()
usernameField . setEnabled ( false ) ;
passwordField . setEnabled ( false ) ;
}
// load dns forward values
if ( configService . getBoolean (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME ,
false ) )
{
dnsForwardCheck . setSelected ( true ) ;
dnsForwardServerAddressField . setText (
( String ) configService . getProperty (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME ) ) ;
dnsForwardPortField . setText (
( String ) configService . getProperty (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME ) ) ;
dnsAddressPane . setVisible ( true ) ;
}
}
/ * *
@ -244,47 +327,72 @@ private void saveValues()
ProxyInfo . CONNECTION_PROXY_USERNAME_PROPERTY_NAME ) ;
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_PASSWORD_PROPERTY_NAME ) ;
return ;
}
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_TYPE_PROPERTY_NAME ,
( ( ProxyInfo . ProxyType ) typeCombo . getSelectedItem ( ) ) . name ( ) ) ;
String serverAddress = serverAddressField . getText ( ) ;
if ( serverAddress ! = null & & serverAddress . length ( ) > 0 )
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_ADDRESS_PROPERTY_NAME , serverAddress ) ;
String port = portField . getText ( ) ;
if ( port ! = null & & port . length ( ) > 0 )
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_PORT_PROPERTY_NAME , port ) ;
String username = usernameField . getText ( ) ;
if ( username ! = null & & username . length ( ) > 0 )
{
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_USERNAME_PROPERTY_NAME , username ) ;
}
else
{
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_USERNAME_PROPERTY_NAME ) ;
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_TYPE_PROPERTY_NAME ,
( ( ProxyInfo . ProxyType ) typeCombo . getSelectedItem ( ) ) . name ( ) ) ;
String serverAddress = serverAddressField . getText ( ) ;
if ( serverAddress ! = null & & serverAddress . length ( ) > 0 )
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_ADDRESS_PROPERTY_NAME ,
serverAddress ) ;
String port = portField . getText ( ) ;
if ( port ! = null & & port . length ( ) > 0 )
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_PORT_PROPERTY_NAME , port ) ;
String username = usernameField . getText ( ) ;
if ( username ! = null & & username . length ( ) > 0 )
{
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_USERNAME_PROPERTY_NAME ,
username ) ;
}
else
{
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_USERNAME_PROPERTY_NAME ) ;
}
char [ ] password = passwordField . getPassword ( ) ;
if ( password . length > 0 )
{
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_PASSWORD_PROPERTY_NAME ,
new String ( password ) ) ;
}
else
{
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_PASSWORD_PROPERTY_NAME ) ;
}
}
char [ ] password = passwordField . getPassword ( ) ;
if ( password . length > 0 )
// save dns forward values
if ( dnsForwardCheck. isSelected ( ) )
{
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_PASSWORD_PROPERTY_NAME ,
new String ( password ) ) ;
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME ,
Boolean . TRUE ) ;
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME ,
dnsForwardServerAddressField . getText ( ) . trim ( ) ) ;
configService . setProperty (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME ,
dnsForwardPortField . getText ( ) . trim ( ) ) ;
}
else
{
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_PASSWORD_PROPERTY_NAME ) ;
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_PROPERTY_NAME ) ;
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_ADDRESS_PROPERTY_NAME ) ;
configService . removeProperty (
ProxyInfo . CONNECTION_PROXY_FORWARD_DNS_PORT_PROPERTY_NAME ) ;
}
GlobalProxyPluginActivator . initProperties ( ) ;
@ -296,6 +404,32 @@ private void saveValues()
* /
public void actionPerformed ( ActionEvent e )
{
if ( e . getSource ( ) . equals ( dnsForwardCheck ) )
{
// lets show or hide the fields
dnsAddressPane . setVisible ( dnsForwardCheck . isSelected ( ) ) ;
if ( dnsForwardCheck . isSelected ( ) )
{
if ( dnsForwardServerAddressField . getText ( ) . length ( ) = = 0 )
dnsForwardServerAddressField . setText (
serverAddressField . getText ( ) ) ;
if ( dnsForwardPortField . getText ( ) . length ( ) = = 0 )
dnsForwardPortField . setText ( "53" ) ;
}
revalidate ( ) ;
repaint ( ) ;
// and save initial values
saveValues ( ) ;
return ;
}
// else this is the typeCombo action
if ( typeCombo . getSelectedItem ( ) . equals ( ProxyInfo . ProxyType . NONE ) )
{
serverAddressField . setEnabled ( false ) ;