Changeset 7434 in josm for trunk/src/org/openstreetmap/josm/Main.java
- Timestamp:
- 2014-08-20T03:07:15+02:00 (10 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r7420 r7434 25 25 import java.util.Collections; 26 26 import java.util.HashMap; 27 import java.util.HashSet; 27 28 import java.util.Iterator; 28 29 import java.util.List; 29 30 import java.util.Map; 30 31 import java.util.Objects; 32 import java.util.Set; 31 33 import java.util.StringTokenizer; 32 34 import java.util.concurrent.Callable; … … 91 93 import org.openstreetmap.josm.gui.widgets.JMultilineLabel; 92 94 import org.openstreetmap.josm.io.FileWatcher; 95 import org.openstreetmap.josm.io.OnlineResource; 93 96 import org.openstreetmap.josm.io.OsmApi; 94 97 import org.openstreetmap.josm.tools.CheckParameterUtil; … … 219 222 private static final List<String> ERRORS_AND_WARNINGS = Collections.<String>synchronizedList(new ArrayList<String>()); 220 223 224 private static final Set<OnlineResource> OFFLINE_RESOURCES = new HashSet<>(); 225 221 226 /** 222 227 * Logging level (5 = trace, 4 = debug, 3 = info, 2 = warn, 1 = error, 0 = none). … … 543 548 List<Callable<Void>> tasks = new ArrayList<>(); 544 549 545 tasks.add(new InitializationTask(tr("Initializing OSM API")) { 546 547 @Override 548 public void initialize() throws Exception { 549 // We try to establish an API connection early, so that any API 550 // capabilities are already known to the editor instance. However 551 // if it goes wrong that's not critical at this stage. 552 try { 553 OsmApi.getOsmApi().initialize(null, true); 554 } catch (Exception e) { 555 Main.warn(getErrorMessage(Utils.getRootCause(e))); 550 if (isOffline(OnlineResource.OSM_API)) { 551 Main.warn(tr("{0} not available (offline mode)", tr("OSM API"))); 552 } else { 553 tasks.add(new InitializationTask(tr("Initializing OSM API")) { 554 555 @Override 556 public void initialize() throws Exception { 557 // We try to establish an API connection early, so that any API 558 // capabilities are already known to the editor instance. However 559 // if it goes wrong that's not critical at this stage. 560 try { 561 OsmApi.getOsmApi().initialize(null, true); 562 } catch (Exception e) { 563 Main.warn(getErrorMessage(Utils.getRootCause(e))); 564 } 556 565 } 557 } 558 } );566 }); 567 } 559 568 560 569 tasks.add(new InitializationTask(tr("Initializing validator")) { … … 1553 1562 return Main.platform instanceof PlatformHookWindows; 1554 1563 } 1564 1565 /** 1566 * Determines if the given online resource is currently offline. 1567 * @param r the online resource 1568 * @return {@code true} if {@code r} is offline and should not be accessed 1569 * @since 7434 1570 */ 1571 public static boolean isOffline(OnlineResource r) { 1572 return OFFLINE_RESOURCES.contains(r) || OFFLINE_RESOURCES.contains(OnlineResource.ALL); 1573 } 1574 1575 /** 1576 * Sets the given online resource to offline state. 1577 * @param r the online resource 1578 * @return {@code true} if {@code r} was not already offline 1579 * @since 7434 1580 */ 1581 public static boolean setOffline(OnlineResource r) { 1582 return OFFLINE_RESOURCES.add(r); 1583 } 1584 1585 /** 1586 * Replies the set of online resources currently offline. 1587 * @return the set of online resources currently offline 1588 * @since 7434 1589 */ 1590 public static Set<OnlineResource> getOfflineResources() { 1591 return new HashSet<>(OFFLINE_RESOURCES); 1592 } 1555 1593 }
Note:
See TracChangeset
for help on using the changeset viewer.