# This patch file was generated by NetBeans IDE
# Following Index: paths are relative to: C:\Users\alexandre.nouvel\Documents\NetBeansProjects\trunk\src
# This patch can be applied using context Tools: Patch action on respective folder.
# It uses platform neutral UTF-8 encoding and \n newlines.
# Above lines and this line are ignored by the patching process.
Index: org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
--- org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java Base (BASE)
+++ org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java Locally Modified (Based On LOCAL)
@@ -9,8 +9,11 @@
 import java.awt.GridBagConstraints;
 import java.awt.GridBagLayout;
 import java.awt.Insets;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
 import java.awt.event.ItemEvent;
 import java.awt.event.ItemListener;
+import java.io.IOException;
 import java.net.Authenticator.RequestorType;
 import java.net.PasswordAuthentication;
 import java.net.ProxySelector;
@@ -20,6 +23,7 @@
 
 import javax.swing.BorderFactory;
 import javax.swing.ButtonGroup;
+import javax.swing.JButton;
 import javax.swing.JLabel;
 import javax.swing.JPanel;
 import javax.swing.JRadioButton;
@@ -35,6 +39,7 @@
 import org.openstreetmap.josm.io.auth.CredentialsAgentException;
 import org.openstreetmap.josm.io.auth.CredentialsManager;
 import org.openstreetmap.josm.tools.GBC;
+import org.openstreetmap.josm.tools.WikiReader;
 
 /**
  * Component allowing input of proxy settings.
@@ -54,7 +59,7 @@
         /** Use HTTP proxy: JOSM will use the given SOCKS proxy */
         USE_SOCKS_PROXY("use-socks-proxy");
 
-        private String policyName;
+        private final String policyName;
         ProxyPolicy(String policyName) {
             this.policyName = policyName;
         }
@@ -111,8 +116,11 @@
     private JPanel pnlHttpProxyConfigurationPanel;
     private JPanel pnlSocksProxyConfigurationPanel;
 
+    private final JButton bSaveAndTest = new JButton(tr("Save and test the settings"));
+    private final JLabel lTestConnectionResult = new JLabel();
+
     /**
-     * Builds the panel for the HTTP proxy configuration
+     * Builds the panel for the HTTP proxy configuration.
      *
      * @return panel with HTTP proxy configuration
      */
@@ -232,6 +240,11 @@
         return pnl;
     }
 
+    /**
+     * Builds the panel for the various proxy configurations and their options.
+     *
+     * @return panel with the different proxy configurations and their options
+     */
     protected final JPanel buildProxySettingsPanel() {
         JPanel pnl = new JPanel(new GridBagLayout());
         GridBagConstraints gc = new GridBagConstraints();
@@ -312,11 +325,24 @@
         pnlSocksProxyConfigurationPanel = buildSocksProxyConfigurationPanel();
         pnl.add(pnlSocksProxyConfigurationPanel, gc);
 
+        // A button to save the settings and test the connection
+        gc.gridx = 1;
+        gc.gridy = 8;
+        gc.weighty = 0.0;
+        bSaveAndTest.addActionListener(new ProxySaveAndTestListener());
+        pnl.add(bSaveAndTest, gc);
+        
+        // A label below the test button to report the test result
+        gc.gridx = 1;
+        gc.gridy = 9;
+        gc.weighty = 0.0;
+        pnl.add(lTestConnectionResult, gc);
+
         return pnl;
     }
 
     /**
-     * Initializes the panel with the values from the preferences
+     * Initializes the panel with the values from the preferences.
      */
     public final void initFromPreferences() {
         String policy = Main.pref.get(PROXY_POLICY, null);
@@ -371,6 +397,7 @@
     }
 
     protected final void updateEnabledState() {
+        lTestConnectionResult.setText("");
         boolean isHttpProxy = rbProxyPolicy.get(ProxyPolicy.USE_HTTP_PROXY).isSelected();
         for (Component c: pnlHttpProxyConfigurationPanel.getComponents()) {
             c.setEnabled(isHttpProxy);
@@ -392,6 +419,47 @@
     }
 
     /**
+     * Tests the stored proxy configuration by loading data from the wiki
+     * startup page.
+     * 
+     * @return {@code true} if the connection was successful, {@code false}
+     * otherwise
+     */
+    protected final boolean testConnection() {
+        try {
+            // Let's try by loading something from the wiki
+            String motd = "";
+            motd = new WikiReader().readLang("StartupPage");
+            return !"".equals(motd);
+        } catch (IOException ex) {
+            return false;
+        }
+    }
+    
+    /**
+     * Saves the current settings and performs a connection test.
+     */
+    protected final void saveSettingsAndTestConnection() {
+        saveToPreferences();
+        final String report;
+        if (testConnection()) {
+            report = tr(
+                "The settings are OK and JOSM was able to connect to the Internet.");
+        } else {
+            report = tr(
+                "Unable to connect, please check your settings and your internet connection.");
+        }
+        lTestConnectionResult.setText(report);
+    }
+
+    class ProxySaveAndTestListener implements ActionListener {
+        @Override
+        public void actionPerformed(ActionEvent arg0) {
+            saveSettingsAndTestConnection();
+        }
+    }
+
+    /**
      * Constructs a new {@code ProxyPreferencesPanel}.
      */
     public ProxyPreferencesPanel() {
@@ -406,7 +474,7 @@
     }
 
     /**
-     * Saves the current values to the preferences
+     * Saves the current values to the preferences.
      */
     public void saveToPreferences() {
         ProxyPolicy policy = null;
