Changeset 9414 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2016-01-11T19:07:11+01:00 (9 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/imagery/ImageryLayerInfo.java
r9412 r9414 63 63 } 64 64 65 public void load() { 65 /** 66 * Loads the custom as well as default imagery entries. 67 * @param fastFail whether opening HTTP connections should fail fast, see {@link ImageryReader#setFastFail(boolean)} 68 */ 69 public void load(boolean fastFail) { 66 70 clear(); 67 71 List<ImageryPreferenceEntry> entries = Main.pref.getListOfStructs("imagery.entries", null, ImageryPreferenceEntry.class); … … 77 81 Collections.sort(layers); 78 82 } 79 loadDefaults(false, true );83 loadDefaults(false, true, fastFail); 80 84 } 81 85 … … 89 93 * @param clearCache if true, clear the cache and start a fresh download. 90 94 * @param quiet whether not the loading should be performed using a {@link PleaseWaitRunnable} in the background 91 */ 92 public void loadDefaults(boolean clearCache, boolean quiet) { 93 final DefaultEntryLoader loader = new DefaultEntryLoader(clearCache); 95 * @param fastFail whether opening HTTP connections should fail fast, see {@link ImageryReader#setFastFail(boolean)} 96 */ 97 public void loadDefaults(boolean clearCache, boolean quiet, boolean fastFail) { 98 final DefaultEntryLoader loader = new DefaultEntryLoader(clearCache, fastFail); 94 99 if (quiet) { 95 100 loader.realRun(); 96 101 loader.finish(); 97 102 } else { 98 Main.worker.execute(new DefaultEntryLoader(clearCache ));103 Main.worker.execute(new DefaultEntryLoader(clearCache, fastFail)); 99 104 } 100 105 } … … 106 111 107 112 private final boolean clearCache; 113 private final boolean fastFail; 108 114 private final List<ImageryInfo> newLayers = new ArrayList<>(); 109 115 private transient ImageryReader reader; 110 116 private transient boolean canceled; 111 117 112 DefaultEntryLoader(boolean clearCache ) {118 DefaultEntryLoader(boolean clearCache, boolean fastFail) { 113 119 super(tr("Update default entries")); 114 120 this.clearCache = clearCache; 121 this.fastFail = fastFail; 115 122 } 116 123 … … 144 151 try { 145 152 reader = new ImageryReader(source); 153 reader.setFastFail(fastFail); 146 154 Collection<ImageryInfo> result = reader.parse(); 147 155 newLayers.addAll(result); -
trunk/src/org/openstreetmap/josm/gui/preferences/imagery/ImageryPreference.java
r9412 r9414 156 156 layerInfo.save(); 157 157 ImageryLayerInfo.instance.clear(); 158 ImageryLayerInfo.instance.load( );158 ImageryLayerInfo.instance.load(false); 159 159 Main.main.menu.imageryMenu.refreshOffsetMenu(); 160 160 OffsetBookmark.saveBookmarks(); … … 642 642 @Override 643 643 public void actionPerformed(ActionEvent evt) { 644 layerInfo.loadDefaults(true, false );644 layerInfo.loadDefaults(true, false, false); 645 645 defaultModel.fireTableDataChanged(); 646 646 defaultTable.getSelectionModel().clearSelection(); … … 946 946 */ 947 947 public static void initialize() { 948 ImageryLayerInfo.instance.load( );948 ImageryLayerInfo.instance.load(true); 949 949 OffsetBookmark.loadBookmarks(); 950 950 Main.main.menu.imageryMenu.refreshImageryMenu(); -
trunk/src/org/openstreetmap/josm/io/CachedFile.java
r9411 r9414 69 69 protected CachingStrategy cachingStrategy; 70 70 71 private transient boolean fastFail; 71 72 private transient HttpClient activeConnection; 72 73 protected File cacheFile; … … 159 160 this.httpHeaders.putAll(headers); 160 161 return this; 162 } 163 164 /** 165 * Sets whether opening HTTP connections should fail fast, i.e., whether a 166 * {@link HttpClient#setConnectTimeout(int) low connect timeout} should be used. 167 * @param fastFail whether opening HTTP connections should fail fast 168 */ 169 public void setFastFail(boolean fastFail) { 170 this.fastFail = fastFail; 161 171 } 162 172 … … 433 443 .setIfModifiedSince(ifModifiedSince == null ? 0L : ifModifiedSince) 434 444 .setHeaders(httpHeaders); 445 if (fastFail) { 446 activeConnection.setReadTimeout(1000); 447 } 435 448 final HttpClient.Response con = activeConnection.connect(); 436 449 if (ifModifiedSince != null && con.getResponseCode() == HttpURLConnection.HTTP_NOT_MODIFIED) { -
trunk/src/org/openstreetmap/josm/io/imagery/ImageryReader.java
r9412 r9414 21 21 import org.openstreetmap.josm.data.imagery.Shape; 22 22 import org.openstreetmap.josm.io.CachedFile; 23 import org.openstreetmap.josm. io.UTFInputStreamReader;23 import org.openstreetmap.josm.tools.HttpClient; 24 24 import org.openstreetmap.josm.tools.LanguageInfo; 25 25 import org.openstreetmap.josm.tools.Utils; … … 33 33 private final String source; 34 34 private transient CachedFile cachedFile; 35 private transient boolean fastFail; 35 36 36 37 private enum State { … … 56 57 try { 57 58 cachedFile = new CachedFile(source); 59 cachedFile.setFastFail(fastFail); 58 60 try (BufferedReader in = cachedFile 59 61 .setMaxAge(CachedFile.DAYS) … … 359 361 } 360 362 363 /** 364 * Sets whether opening HTTP connections should fail fast, i.e., whether a 365 * {@link HttpClient#setConnectTimeout(int) low connect timeout} should be used. 366 * @param fastFail whether opening HTTP connections should fail fast 367 * @see CachedFile#setFastFail(boolean) 368 */ 369 public void setFastFail(boolean fastFail) { 370 this.fastFail = fastFail; 371 } 372 361 373 @Override 362 374 public void close() throws IOException {
Note:
See TracChangeset
for help on using the changeset viewer.