Changeset 6523 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2013-12-24T20:26:51+01:00 (11 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 added
- 5 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r6474 r6523 409 409 } 410 410 411 /** 412 * Constructs new {@code Main} object. A lot of global variables are initialized here. 413 */ 411 414 public Main() { 412 415 main = this; -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r6471 r6523 7 7 import gnu.getopt.LongOpt; 8 8 9 import java.awt.Dimension; 9 10 import java.awt.Image; 10 11 import java.awt.Toolkit; … … 28 29 29 30 import javax.swing.JFrame; 31 import javax.swing.JOptionPane; 30 32 import javax.swing.RepaintManager; 31 33 import javax.swing.SwingUtilities; … … 33 35 import org.jdesktop.swinghelper.debug.CheckThreadViolationRepaintManager; 34 36 import org.openstreetmap.josm.Main; 37 import org.openstreetmap.josm.actions.PreferencesAction; 35 38 import org.openstreetmap.josm.data.AutosaveTask; 36 39 import org.openstreetmap.josm.data.CustomConfigurator; 37 import org.openstreetmap.josm.data.Preferences;38 40 import org.openstreetmap.josm.data.Version; 39 41 import org.openstreetmap.josm.gui.download.DownloadDialog; 40 42 import org.openstreetmap.josm.gui.preferences.server.OAuthAccessTokenHolder; 43 import org.openstreetmap.josm.gui.preferences.server.ProxyPreference; 41 44 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 42 45 import org.openstreetmap.josm.gui.util.GuiHelper; … … 340 343 DefaultAuthenticator.createInstance(); 341 344 Authenticator.setDefault(DefaultAuthenticator.getInstance()); 342 ProxySelector.setDefault(new DefaultProxySelector(ProxySelector.getDefault())); 345 DefaultProxySelector proxySelector = new DefaultProxySelector(ProxySelector.getDefault()); 346 ProxySelector.setDefault(proxySelector); 343 347 OAuthAccessTokenHolder.getInstance().init(Main.pref, CredentialsManager.getInstance()); 344 348 … … 407 411 } 408 412 409 final Map<Option, Collection<String>> args_final = args; 410 411 SwingUtilities.invokeLater(new Runnable() { 412 @Override 413 public void run() { 414 if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) { 415 AutosaveTask autosaveTask = new AutosaveTask(); 416 List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles(); 417 if (!unsavedLayerFiles.isEmpty()) { 418 ExtendedDialog dialog = new ExtendedDialog( 419 Main.parent, 420 tr("Unsaved osm data"), 421 new String[] {tr("Restore"), tr("Cancel"), tr("Discard")} 422 ); 423 dialog.setContent( 424 trn("JOSM found {0} unsaved osm data layer. ", 425 "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) + 426 tr("It looks like JOSM crashed last time. Would you like to restore the data?")); 427 dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/delete"}); 428 int selection = dialog.showDialog().getValue(); 429 if (selection == 1) { 430 autosaveTask.recoverUnsavedLayers(); 431 } else if (selection == 3) { 432 autosaveTask.dicardUnsavedLayers(); 433 } 434 } 435 autosaveTask.schedule(); 436 } 437 438 postConstructorProcessCmdLine(args_final); 439 440 DownloadDialog.autostartIfNeeded(); 441 } 442 }); 413 SwingUtilities.invokeLater(new GuiFinalizationWorker(args, proxySelector)); 443 414 444 415 if (RemoteControl.PROP_REMOTECONTROL_ENABLED.get()) { … … 456 427 } 457 428 } 429 430 private static class GuiFinalizationWorker implements Runnable { 431 432 private final Map<Option, Collection<String>> args; 433 private final DefaultProxySelector proxySelector; 434 435 public GuiFinalizationWorker(Map<Option, Collection<String>> args, DefaultProxySelector proxySelector) { 436 this.args = args; 437 this.proxySelector = proxySelector; 438 } 439 440 @Override 441 public void run() { 442 443 // Handle proxy errors early to inform user he should change settings to be able to use JOSM correctly 444 handleProxyErrors(); 445 446 // Restore autosave layers after crash and start autosave thread 447 handleAutosave(); 448 449 // Handle command line instructions 450 postConstructorProcessCmdLine(args); 451 452 // Show download dialog if autostart is enabled 453 DownloadDialog.autostartIfNeeded(); 454 } 455 456 private void handleAutosave() { 457 if (AutosaveTask.PROP_AUTOSAVE_ENABLED.get()) { 458 AutosaveTask autosaveTask = new AutosaveTask(); 459 List<File> unsavedLayerFiles = autosaveTask.getUnsavedLayersFiles(); 460 if (!unsavedLayerFiles.isEmpty()) { 461 ExtendedDialog dialog = new ExtendedDialog( 462 Main.parent, 463 tr("Unsaved osm data"), 464 new String[] {tr("Restore"), tr("Cancel"), tr("Discard")} 465 ); 466 dialog.setContent( 467 trn("JOSM found {0} unsaved osm data layer. ", 468 "JOSM found {0} unsaved osm data layers. ", unsavedLayerFiles.size(), unsavedLayerFiles.size()) + 469 tr("It looks like JOSM crashed last time. Would you like to restore the data?")); 470 dialog.setButtonIcons(new String[] {"ok", "cancel", "dialogs/delete"}); 471 int selection = dialog.showDialog().getValue(); 472 if (selection == 1) { 473 autosaveTask.recoverUnsavedLayers(); 474 } else if (selection == 3) { 475 autosaveTask.dicardUnsavedLayers(); 476 } 477 } 478 autosaveTask.schedule(); 479 } 480 } 481 482 private static String getHtmlList(Collection<String> set) { 483 StringBuilder sb = new StringBuilder("<ul>"); 484 for (String s : set) { 485 sb.append("<li>"+s+"</li>"); 486 } 487 return sb.append("</ul>").toString(); 488 } 489 490 private void handleProxyErrors() { 491 if (proxySelector.hasErrors()) { 492 ExtendedDialog ed = new ExtendedDialog( 493 Main.parent, tr("Proxy errors occured"), 494 new String[]{tr("Change proxy settings"), tr("Cancel")}); 495 ed.setButtonIcons(new String[]{"dialogs/settings.png", "cancel.png"}).setCancelButton(2); 496 ed.setMinimumSize(new Dimension(460, 260)); 497 ed.setIcon(JOptionPane.WARNING_MESSAGE); 498 ed.setContent(tr("JOSM tried to access the following resources:")+ 499 "<br>"+getHtmlList(proxySelector.getErrorResources())+ 500 tr("but <b>failed</b> to do so, because of the following proxy errors:")+ 501 "<br>"+getHtmlList(proxySelector.getErrorMessages())+ 502 tr("Would you like to change your proxy settings now ?") 503 ); 504 505 if (ed.showDialog().getValue() == 1) { 506 PreferencesAction.forPreferenceSubTab(null, null, ProxyPreference.class).run(); 507 } 508 } 509 } 510 } 458 511 } -
trunk/src/org/openstreetmap/josm/gui/preferences/PreferenceTabbedPane.java
r6380 r6523 45 45 import org.openstreetmap.josm.gui.preferences.map.TaggingPresetPreference; 46 46 import org.openstreetmap.josm.gui.preferences.projection.ProjectionPreference; 47 import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreference; 48 import org.openstreetmap.josm.gui.preferences.server.ProxyPreference; 47 49 import org.openstreetmap.josm.gui.preferences.shortcut.ShortcutPreference; 48 50 import org.openstreetmap.josm.plugins.PluginDownloadTask; … … 229 231 } 230 232 233 /** 234 * Returns the {@code DisplayPreference} object. 235 * @return the {@code DisplayPreference} object. 236 */ 231 237 public final DisplayPreference getDisplayPreference() { 232 238 return getSetting(DisplayPreference.class); 233 239 } 234 240 241 /** 242 * Returns the {@code MapPreference} object. 243 * @return the {@code MapPreference} object. 244 */ 235 245 public final MapPreference getMapPreference() { 236 246 return getSetting(MapPreference.class); 237 247 } 238 248 249 /** 250 * Returns the {@code PluginPreference} object. 251 * @return the {@code PluginPreference} object. 252 */ 239 253 public final PluginPreference getPluginPreference() { 240 254 return getSetting(PluginPreference.class); 241 255 } 242 256 257 /** 258 * Returns the {@code ImageryPreference} object. 259 * @return the {@code ImageryPreference} object. 260 */ 243 261 public final ImageryPreference getImageryPreference() { 244 262 return getSetting(ImageryPreference.class); 245 263 } 246 264 265 /** 266 * Returns the {@code ShortcutPreference} object. 267 * @return the {@code ShortcutPreference} object. 268 */ 247 269 public final ShortcutPreference getShortcutPreference() { 248 270 return getSetting(ShortcutPreference.class); 249 271 } 250 272 273 /** 274 * Returns the {@code ServerAccessPreference} object. 275 * @return the {@code ServerAccessPreference} object. 276 * @since 6523 277 */ 278 public final ServerAccessPreference getServerPreference() { 279 return getSetting(ServerAccessPreference.class); 280 } 281 282 /** 283 * Saves preferences. 284 */ 251 285 public void savePreferences() { 252 286 if(Main.applet) … … 450 484 settingsFactory.add(new LanguagePreference.Factory()); 451 485 settingsFactory.add(new ServerAccessPreference.Factory()); 486 settingsFactory.add(new AuthenticationPreference.Factory()); 487 settingsFactory.add(new ProxyPreference.Factory()); 452 488 settingsFactory.add(new MapPreference.Factory()); 453 489 settingsFactory.add(new ProjectionPreference.Factory()); -
trunk/src/org/openstreetmap/josm/gui/preferences/ServerAccessPreference.java
r6380 r6523 8 8 import java.awt.GridBagLayout; 9 9 import java.awt.Insets; 10 import java.beans.PropertyChangeListener; 10 11 11 12 import javax.swing.JPanel; … … 14 15 15 16 import org.openstreetmap.josm.gui.help.HelpUtil; 16 import org.openstreetmap.josm.gui.preferences.server.AuthenticationPreferencesPanel;17 17 import org.openstreetmap.josm.gui.preferences.server.OsmApiUrlInputPanel; 18 import org.openstreetmap.josm.gui.preferences.server.ProxyPreferencesPanel;19 18 import org.openstreetmap.josm.gui.widgets.VerticallyScrollablePanel; 20 19 20 /** 21 * Connection preferences, including authentication and proxy sub-preferences. 22 */ 21 23 public final class ServerAccessPreference extends DefaultTabPreferenceSetting { 22 24 25 /** 26 * Factory used to create a new {@code ServerAccessPreference}. 27 */ 23 28 public static class Factory implements PreferenceSettingFactory { 24 29 @Override … … 32 37 } 33 38 39 /** indicates whether to use the default OSM URL or not */ 34 40 private OsmApiUrlInputPanel pnlApiUrlPreferences; 35 36 /** indicates whether to use the default OSM URL or not */37 /** panel for configuring authentication preferences */38 private AuthenticationPreferencesPanel pnlAuthPreferences;39 /** panel for configuring proxy preferences */40 private ProxyPreferencesPanel pnlProxyPreferences;41 41 42 42 /** … … 59 59 protected JPanel buildTabbedServerPreferences() { 60 60 JPanel pnl = new JPanel(new BorderLayout()); 61 62 JTabbedPane tpServerPreferences = getTabPane(); 63 pnlAuthPreferences = new AuthenticationPreferencesPanel(); 64 tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlAuthPreferences)); 65 pnlProxyPreferences = new ProxyPreferencesPanel(); 66 tpServerPreferences.add(wrapVerticallyScrollablePanel(pnlProxyPreferences)); 67 68 tpServerPreferences.setTitleAt(0, tr("Authentication")); 69 tpServerPreferences.setTitleAt(1, tr("Proxy settings")); 70 tpServerPreferences.setToolTipTextAt(0, tr("Configure your identity and how to authenticate at the OSM server")); 71 tpServerPreferences.setToolTipTextAt(1, tr("Configure whether to use a proxy server")); 72 73 pnl.add(tpServerPreferences, BorderLayout.CENTER); 61 pnl.add(getTabPane(), BorderLayout.CENTER); 74 62 return pnl; 75 63 } … … 99 87 pnl.add(buildTabbedServerPreferences(), gc); 100 88 101 // let the AuthPreferencesPanel know when the API URL changes102 //103 pnlApiUrlPreferences.addPropertyChangeListener(pnlAuthPreferences);104 105 89 HelpUtil.setHelpContext(pnl, HelpUtil.ht("/Preferences/Connection")); 106 90 return pnl; 91 } 92 93 /** 94 * Adds a listener that will be notified of API URL change. 95 * @param listener the listener 96 * @since 6523 97 */ 98 public final void addApiUrlChangeListener(PropertyChangeListener listener) { 99 pnlApiUrlPreferences.addPropertyChangeListener(listener); 107 100 } 108 101 … … 124 117 public void initFromPreferences() { 125 118 pnlApiUrlPreferences.initFromPreferences(); 126 pnlAuthPreferences.initFromPreferences();127 pnlProxyPreferences.initFromPreferences();128 119 } 129 120 … … 134 125 public boolean ok() { 135 126 pnlApiUrlPreferences.saveToPreferences(); 136 pnlAuthPreferences.saveToPreferences();137 pnlProxyPreferences.saveToPreferences();138 127 return false; 139 128 } -
trunk/src/org/openstreetmap/josm/io/DefaultProxySelector.java
r6348 r6523 12 12 import java.net.URI; 13 13 import java.util.Collections; 14 import java.util.HashSet; 14 15 import java.util.List; 16 import java.util.Set; 17 import java.util.TreeSet; 15 18 16 19 import org.openstreetmap.josm.Main; … … 56 59 private InetSocketAddress socksProxySocketAddress; 57 60 private ProxySelector delegate; 61 62 private final Set<String> errorResources = new HashSet<String>(); 63 private final Set<String> errorMessages = new HashSet<String>(); 58 64 59 65 /** … … 134 140 public void connectFailed(URI uri, SocketAddress sa, IOException ioe) { 135 141 // Just log something. The network stack will also throw an exception which will be caught somewhere else 136 //137 142 Main.error(tr("Connection to proxy ''{0}'' for URI ''{1}'' failed. Exception was: {2}", sa.toString(), uri.toString(), ioe.toString())); 143 // Remember errors to give a friendly user message asking to review proxy configuration 144 errorResources.add(uri.toString()); 145 errorMessages.add(ioe.toString()); 146 } 147 148 /** 149 * Returns the set of current proxy resources that failed to be retrieved. 150 * @return the set of current proxy resources that failed to be retrieved 151 * @since 6523 152 */ 153 public final Set<String> getErrorResources() { 154 return new TreeSet<String>(errorResources); 155 } 156 157 /** 158 * Returns the set of current proxy error messages. 159 * @return the set of current proxy error messages 160 * @since 6523 161 */ 162 public final Set<String> getErrorMessages() { 163 return new TreeSet<String>(errorMessages); 164 } 165 166 /** 167 * Clear the sets of failed resources and error messages. 168 * @since 6523 169 */ 170 public final void clearErrors() { 171 errorResources.clear(); 172 errorMessages.clear(); 173 } 174 175 /** 176 * Determines if proxy errors have occured. 177 * @return {@code true} if errors have occured, {@code false} otherwise. 178 * @since 6523 179 */ 180 public final boolean hasErrors() { 181 return !errorResources.isEmpty(); 138 182 } 139 183
Note:
See TracChangeset
for help on using the changeset viewer.