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