diff --git a/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java b/src/org/openstreetmap/josm/gui/preferences/server/ProxyPreferencesPanel.java
index dad6e01..08a8b77 100644
a
|
b
|
|
11 | 11 | import java.awt.Insets; |
12 | 12 | import java.awt.event.ItemEvent; |
13 | 13 | import java.awt.event.ItemListener; |
| 14 | import java.io.IOException; |
14 | 15 | import java.net.Authenticator.RequestorType; |
15 | 16 | import java.net.PasswordAuthentication; |
16 | 17 | import java.net.ProxySelector; |
… |
… |
|
20 | 21 | |
21 | 22 | import javax.swing.BorderFactory; |
22 | 23 | import javax.swing.ButtonGroup; |
| 24 | import javax.swing.JButton; |
23 | 25 | import javax.swing.JLabel; |
24 | 26 | import javax.swing.JPanel; |
25 | 27 | import javax.swing.JRadioButton; |
… |
… |
|
35 | 37 | import org.openstreetmap.josm.io.auth.CredentialsAgentException; |
36 | 38 | import org.openstreetmap.josm.io.auth.CredentialsManager; |
37 | 39 | import org.openstreetmap.josm.tools.GBC; |
| 40 | import org.openstreetmap.josm.tools.WikiReader; |
38 | 41 | |
39 | 42 | /** |
40 | 43 | * Component allowing input of proxy settings. |
… |
… |
|
54 | 57 | /** Use HTTP proxy: JOSM will use the given SOCKS proxy */ |
55 | 58 | USE_SOCKS_PROXY("use-socks-proxy"); |
56 | 59 | |
57 | | private String policyName; |
| 60 | private final String policyName; |
58 | 61 | ProxyPolicy(String policyName) { |
59 | 62 | this.policyName = policyName; |
60 | 63 | } |
… |
… |
public static ProxyPolicy fromName(String policyName) {
|
111 | 114 | private JPanel pnlHttpProxyConfigurationPanel; |
112 | 115 | private JPanel pnlSocksProxyConfigurationPanel; |
113 | 116 | |
| 117 | private final JButton bSaveAndTest = new JButton(tr("Save and test the settings")); |
| 118 | private final JLabel lTestConnectionResult = new JLabel(); |
| 119 | |
114 | 120 | /** |
115 | | * Builds the panel for the HTTP proxy configuration |
| 121 | * Builds the panel for the HTTP proxy configuration. |
116 | 122 | * |
117 | 123 | * @return panel with HTTP proxy configuration |
118 | 124 | */ |
… |
… |
public Dimension getMinimumSize() {
|
232 | 238 | return pnl; |
233 | 239 | } |
234 | 240 | |
| 241 | /** |
| 242 | * Builds the panel for the various proxy configurations and their options. |
| 243 | * |
| 244 | * @return panel with the different proxy configurations and their options |
| 245 | */ |
235 | 246 | protected final JPanel buildProxySettingsPanel() { |
236 | 247 | JPanel pnl = new JPanel(new GridBagLayout()); |
237 | 248 | GridBagConstraints gc = new GridBagConstraints(); |
… |
… |
protected final JPanel buildProxySettingsPanel() {
|
312 | 323 | pnlSocksProxyConfigurationPanel = buildSocksProxyConfigurationPanel(); |
313 | 324 | pnl.add(pnlSocksProxyConfigurationPanel, gc); |
314 | 325 | |
| 326 | // A button to save the settings and test the connection |
| 327 | gc.gridx = 1; |
| 328 | gc.gridy = 8; |
| 329 | gc.weighty = 0.0; |
| 330 | bSaveAndTest.addActionListener(action -> saveSettingsAndTestConnection()); |
| 331 | pnl.add(bSaveAndTest, gc); |
| 332 | |
| 333 | // A label below the test button to report the test result |
| 334 | gc.gridx = 1; |
| 335 | gc.gridy = 9; |
| 336 | gc.weighty = 0.0; |
| 337 | pnl.add(lTestConnectionResult, gc); |
| 338 | |
315 | 339 | return pnl; |
316 | 340 | } |
317 | 341 | |
318 | 342 | /** |
319 | | * Initializes the panel with the values from the preferences |
| 343 | * Initializes the panel with the values from the preferences. |
320 | 344 | */ |
321 | 345 | public final void initFromPreferences() { |
322 | 346 | String policy = Main.pref.get(PROXY_POLICY, null); |
… |
… |
public final void initFromPreferences() {
|
371 | 395 | } |
372 | 396 | |
373 | 397 | protected final void updateEnabledState() { |
| 398 | lTestConnectionResult.setText(""); |
374 | 399 | boolean isHttpProxy = rbProxyPolicy.get(ProxyPolicy.USE_HTTP_PROXY).isSelected(); |
375 | 400 | for (Component c: pnlHttpProxyConfigurationPanel.getComponents()) { |
376 | 401 | c.setEnabled(isHttpProxy); |
… |
… |
public void itemStateChanged(ItemEvent arg0) {
|
392 | 417 | } |
393 | 418 | |
394 | 419 | /** |
| 420 | * Tests the stored proxy configuration by loading data from the wiki startup page. |
| 421 | * |
| 422 | * @return {@code true} if the connection was successful, {@code false} otherwise |
| 423 | */ |
| 424 | protected final boolean testConnection() { |
| 425 | try { |
| 426 | // Let's try by loading something from the wiki |
| 427 | return !new WikiReader().readLang("StartupPage").isEmpty(); |
| 428 | } catch (IOException ex) { |
| 429 | return false; |
| 430 | } |
| 431 | } |
| 432 | |
| 433 | /** |
| 434 | * Saves the current settings and performs a connection test. |
| 435 | */ |
| 436 | protected final void saveSettingsAndTestConnection() { |
| 437 | saveToPreferences(); |
| 438 | final String report; |
| 439 | if (testConnection()) { |
| 440 | report = tr("The settings are OK and JOSM was able to connect to the Internet."); |
| 441 | } else { |
| 442 | report = tr("Unable to connect, please check your settings and your internet connection."); |
| 443 | } |
| 444 | lTestConnectionResult.setText(report); |
| 445 | } |
| 446 | |
| 447 | /** |
395 | 448 | * Constructs a new {@code ProxyPreferencesPanel}. |
396 | 449 | */ |
397 | 450 | public ProxyPreferencesPanel() { |
… |
… |
public ProxyPreferencesPanel() {
|
406 | 459 | } |
407 | 460 | |
408 | 461 | /** |
409 | | * Saves the current values to the preferences |
| 462 | * Saves the current values to the preferences. |
410 | 463 | */ |
411 | 464 | public void saveToPreferences() { |
412 | 465 | ProxyPolicy policy = null; |