Changeset 1811 in josm for trunk/src/org/openstreetmap/josm/io
- Timestamp:
- 2009-07-19T17:38:55+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/io
- Files:
-
- 15 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r1772 r1811 8 8 9 9 import org.openstreetmap.josm.Main; 10 import org.openstreetmap.josm.data.gpx.GpxData; 10 11 import org.openstreetmap.josm.data.osm.DataSet; 11 import org.openstreetmap.josm. data.gpx.GpxData;12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 13 import org.xml.sax.SAXException; 13 14 … … 39 40 * ways. 40 41 */ 41 public GpxData parseRawGps() throws IOException, SAXException { 42 Main.pleaseWaitDlg.progress.setValue(0); 43 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 42 public GpxData parseRawGps(ProgressMonitor progressMonitor) throws IOException, SAXException { 43 progressMonitor.beginTask("", 1); 44 44 try { 45 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 45 46 String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 46 47 … … 48 49 GpxData result = null; 49 50 for (int i = 0;!done;++i) { 50 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));51 InputStream in = getInputStream(url+i, Main.pleaseWaitDlg);51 progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000))); 52 InputStream in = getInputStream(url+i, progressMonitor.createSubTaskMonitor(1, true)); 52 53 if (in == null) { 53 54 break; 54 55 } 56 progressMonitor.setTicks(0); 55 57 GpxData currentGpx = new GpxReader(in, null).data; 56 58 if (result == null) { … … 83 85 throw (RuntimeException)e; 84 86 throw new RuntimeException(e); 87 } finally { 88 progressMonitor.finishTask(); 85 89 } 86 90 } … … 91 95 */ 92 96 @Override 93 public DataSet parseOsm() throws OsmTransferException { 97 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 98 progressMonitor.beginTask(tr("Contacting OSM Server..."), 10); 94 99 try { 95 Main.pleaseWaitDlg.progress.setValue(0); 96 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 97 Main.pleaseWaitDlg.setIndeterminate(true); 98 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg); 99 Main.pleaseWaitDlg.setIndeterminate(false); 100 progressMonitor.indeterminateSubTask(null); 101 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, progressMonitor.createSubTaskMonitor(9, false)); 100 102 if (in == null) 101 103 return null; 102 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 103 final DataSet data = OsmReader.parseDataSet(in,Main.pleaseWaitDlg); 104 final DataSet data = OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 104 105 in.close(); 105 106 activeConnection = null; … … 117 118 return null; 118 119 throw new OsmTransferException(e); 120 } finally { 121 progressMonitor.finishTask(); 119 122 } 120 123 } -
trunk/src/org/openstreetmap/josm/io/DiffResultReader.java
r1523 r1811 18 18 import org.openstreetmap.josm.data.osm.Way; 19 19 import org.openstreetmap.josm.data.osm.visitor.AbstractVisitor; 20 import org.openstreetmap.josm.gui. PleaseWaitDialog;20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 21 import org.xml.sax.Attributes; 22 22 import org.xml.sax.InputSource; … … 64 64 * Parse the given input source and return the dataset. 65 65 */ 66 public static void parseDiffResult(String source, Collection<OsmPrimitive> osm, Collection<OsmPrimitive> processed, Map<OsmPrimitive,Long> newIdMap, P leaseWaitDialog pleaseWaitDlg)66 public static void parseDiffResult(String source, Collection<OsmPrimitive> osm, Collection<OsmPrimitive> processed, Map<OsmPrimitive,Long> newIdMap, ProgressMonitor progressMonitor) 67 67 throws SAXException, IOException { 68 68 69 DiffResultReader drr = new DiffResultReader(); 70 drr.processed = processed; 71 drr.newIdMap = newIdMap; 72 InputSource inputSource = new InputSource(new StringReader(source)); 73 try { 74 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, drr.new Parser()); 75 } catch (ParserConfigurationException e1) { 76 e1.printStackTrace(); // broken SAXException chaining 77 throw new SAXException(e1); 78 } 69 progressMonitor.beginTask(tr("Preparing data...")); 70 try { 79 71 80 if (pleaseWaitDlg != null) { 81 pleaseWaitDlg.progress.setValue(0); 82 pleaseWaitDlg.currentAction.setText(tr("Preparing data...")); 83 } 72 DiffResultReader drr = new DiffResultReader(); 73 drr.processed = processed; 74 drr.newIdMap = newIdMap; 75 InputSource inputSource = new InputSource(new StringReader(source)); 76 try { 77 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, drr.new Parser()); 78 } catch (ParserConfigurationException e1) { 79 e1.printStackTrace(); // broken SAXException chaining 80 throw new SAXException(e1); 81 } 84 82 85 for (OsmPrimitive p : osm) { 86 //System.out.println("old: "+ p); 87 p.visit(drr); 88 //System.out.println("new: "+ p); 89 //System.out.println(""); 90 } 83 for (OsmPrimitive p : osm) { 84 //System.out.println("old: "+ p); 85 p.visit(drr); 86 //System.out.println("new: "+ p); 87 //System.out.println(""); 88 } 89 } finally { 90 progressMonitor.finishTask(); 91 } 91 92 } 92 93 -
trunk/src/org/openstreetmap/josm/io/MultiFetchServerObjectReader.java
r1790 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException;7 6 import java.io.InputStream; 8 7 import java.net.HttpURLConnection; … … 14 13 import java.util.logging.Logger; 15 14 16 import org.openstreetmap.josm.Main;17 15 import org.openstreetmap.josm.data.osm.DataSet; 18 16 import org.openstreetmap.josm.data.osm.Node; … … 23 21 import org.openstreetmap.josm.data.osm.Way; 24 22 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 25 import org.xml.sax.SAXException; 23 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 24 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 26 25 27 26 /** 28 27 * Retrieves a set of {@see OsmPrimitive}s from an OSM server using the so called 29 28 * Multi Fetch API. 30 * 29 * 31 30 * Usage: 32 31 * <pre> … … 42 41 * } 43 42 * </pre> 44 * 43 * 45 44 * 46 45 */ … … 53 52 * which should be safe according to the 54 53 * <a href="http://www.boutell.com/newfaq/misc/urllength.html">WWW FAQ</a>. 55 * 54 * 56 55 */ 57 56 static private int MAX_IDS_PER_REQUEST = 200; … … 79 78 * remembers an {@see OsmPrimitive}'s id and its type. The id will 80 79 * later be fetched as part of a Multi Get request. 81 * 80 * 82 81 * Ignore the id if it id <= 0. 83 * 82 * 84 83 * @param id the id 85 84 * @param type the type … … 100 99 * an {@see OsmPrimitive} with id=<code>id</code>. The id will 101 100 * later we fetched as part of a Multi Get request. 102 * 101 * 103 102 * Ignore the id if it id <= 0. 104 * 103 * 105 104 * @param ds the dataset (must not be null) 106 105 * @param id the id … … 123 122 * appends a list of ids to the list of ids which will be fetched from the server. ds must 124 123 * include an {@see OsmPrimitive} for each id in ids. 125 * 124 * 126 125 * id is ignored if id <= 0. 127 * 126 * 128 127 * @param ds the dataset 129 128 * @param ids the list of ids 130 129 * @return this 131 * 130 * 132 131 */ 133 132 public MultiFetchServerObjectReader append(DataSet ds, long ... ids) { … … 142 141 * appends a collection of ids to the list of ids which will be fetched from the server. ds must 143 142 * include an {@see OsmPrimitive} for each id in ids. 144 * 143 * 145 144 * id is ignored if id <= 0. 146 * 145 * 147 146 * @param ds the dataset 148 147 * @param ids the collection of ids 149 148 * @return this 150 * 149 * 151 150 */ 152 151 public MultiFetchServerObjectReader append(DataSet ds, Collection<Long> ids) { … … 163 162 * @param node the node (ignored, if null) 164 163 * @return this 165 * 164 * 166 165 */ 167 166 public MultiFetchServerObjectReader append(Node node) { … … 177 176 * @param way the way (ignored, if null) 178 177 * @return this 179 * 178 * 180 179 */ 181 180 public MultiFetchServerObjectReader append(Way way) { … … 196 195 * @param relation the relation (ignored, if null) 197 196 * @return this 198 * 197 * 199 198 */ 200 199 public MultiFetchServerObjectReader append(Relation relation) { … … 225 224 * @param primitives the list of primitives (ignored, if null) 226 225 * @return this 227 * 226 * 228 227 * @see #append(Node) 229 228 * @see #append(Way) 230 229 * @see #append(Relation) 231 * 230 * 232 231 */ 233 232 public MultiFetchServerObjectReader append(Collection<OsmPrimitive> primitives) { … … 242 241 * extracts a subset of max {@see #MAX_IDS_PER_REQUEST} ids from <code>ids</code> and 243 242 * replies the subset. The extracted subset is removed from <code>ids</code>. 244 * 243 * 245 244 * @param ids a set of ids 246 245 * @return the subset of ids … … 267 266 * builds the Multi Get request string for a set of ids and a given 268 267 * {@see OsmPrimitiveType}. 269 * 268 * 270 269 * @param type the type 271 270 * @param idPackage the package of ids … … 290 289 * builds the Multi Get request string for a single id and a given 291 290 * {@see OsmPrimitiveType}. 292 * 291 * 293 292 * @param type the type 294 293 * @param id the id … … 306 305 * invokes a Multi Get for a set of ids and a given {@see OsmPrimitiveType}. 307 306 * The retrieved primitives are merged to {@see #outputDataSet}. 308 * 307 * 309 308 * @param type the type 310 309 * @param pkg the package of ids 311 310 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 312 * 313 */ 314 protected void multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg) throws OsmTransferException { 311 * 312 */ 313 protected void multiGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) throws OsmTransferException { 315 314 String request = buildRequestString(type, pkg); 316 final InputStream in = getInputStream(request, Main.pleaseWaitDlg);315 final InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE); 317 316 if (in == null) return; 318 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));317 progressMonitor.subTask(tr("Downloading OSM data...")); 319 318 try { 320 final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);319 final OsmReader osm = OsmReader.parseDataSetOsm(in, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 321 320 merge(osm.getDs()); 322 321 } catch(Exception e) { … … 328 327 * invokes a Multi Get for a single id and a given {@see OsmPrimitiveType}. 329 328 * The retrieved primitive is merged to {@see #outputDataSet}. 330 * 329 * 331 330 * @param type the type 332 331 * @param id the id 333 332 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 334 * 335 */ 336 protected void singleGetId(OsmPrimitiveType type, long id) throws OsmTransferException { 333 * 334 */ 335 protected void singleGetId(OsmPrimitiveType type, long id, ProgressMonitor progressMonitor) throws OsmTransferException { 337 336 String request = buildRequestString(type, id); 338 final InputStream in = getInputStream(request, Main.pleaseWaitDlg);337 final InputStream in = getInputStream(request, NullProgressMonitor.INSTANCE); 339 338 if (in == null) 340 339 return; 341 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));340 progressMonitor.subTask(tr("Downloading OSM data...")); 342 341 try { 343 final OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);342 final OsmReader osm = OsmReader.parseDataSetOsm(in, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 344 343 merge(osm.getDs()); 345 344 } catch(Exception e) { … … 351 350 * invokes a sequence of Multi Gets for individual ids in a set of ids and a given {@see OsmPrimitiveType}. 352 351 * The retrieved primitives are merged to {@see #outputDataSet}. 353 * 352 * 354 353 * This method is used if one of the ids in pkg doesn't exist (the server replies with return code 404). 355 354 * If the set is fetched with this method it is possible to find out which of the ids doesn't exist. 356 355 * Unfortunatelly, the server does not provide an error header or an error body for a 404 reply. 357 * 356 * 358 357 * @param type the type 359 358 * @param pkg the set of ids 360 359 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 361 * 362 */ 363 protected void singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg) throws OsmTransferException { 360 * 361 */ 362 protected void singleGetIdPackage(OsmPrimitiveType type, Set<Long> pkg, ProgressMonitor progressMonitor) throws OsmTransferException { 364 363 for (long id : pkg) { 365 364 try { 366 singleGetId(type, id); 365 singleGetId(type, id, progressMonitor); 367 366 } catch(OsmApiException e) { 368 367 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { … … 378 377 /** 379 378 * merges the dataset <code>from</code> to {@see #outputDataSet}. 380 * 379 * 381 380 * @param from the other dataset 382 * 381 * 383 382 */ 384 383 protected void merge(DataSet from) { … … 389 388 /** 390 389 * fetches a set of ids of a given {@see OsmPrimitiveType} from the server 391 * 390 * 392 391 * @param ids the set of ids 393 392 * @param type the type 394 393 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 395 394 */ 396 protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type) throws OsmTransferException{ 395 protected void fetchPrimitives(Set<Long> ids, OsmPrimitiveType type, ProgressMonitor progressMonitor) throws OsmTransferException{ 397 396 Set<Long> toFetch = new HashSet<Long>(ids); 398 397 toFetch.addAll(ids); … … 400 399 Set<Long> pkg = extractIdPackage(toFetch); 401 400 try { 402 multiGetIdPackage(type, pkg); 401 multiGetIdPackage(type, pkg, progressMonitor); 403 402 } catch(OsmApiException e) { 404 403 if (e.getResponseCode() == HttpURLConnection.HTTP_NOT_FOUND) { 405 404 logger.warning(tr("Server replied with response code 404, retrying with an individual request for each primitive")); 406 singleGetIdPackage(type, pkg); 405 singleGetIdPackage(type, pkg, progressMonitor); 407 406 } else 408 407 throw e; … … 417 416 * the latest version of the primitive (if any), even if the primitive is not visible (i.e. if 418 417 * visible==false). 419 * 418 * 420 419 * Invoke {@see #getMissingPrimitives()} to get a list of primitives which have not been 421 420 * found on the server (the server response code was 404) 422 * 421 * 423 422 * Invoke {@see #getSkippedWay()} to get a list of ways which this reader could not build from 424 423 * the fetched data because the ways refer to nodes which don't exist on the server. 425 * 424 * 426 425 * @return the parsed data 427 426 * @exception OsmTransferException thrown if an error occurs while communicating with the API server 428 427 * @see #getMissingPrimitives() 429 428 * @see #getSkippedWays() 430 * 429 * 431 430 432 431 */ 433 432 @Override 434 public DataSet parseOsm() throws OsmTransferException { 435 missingPrimitives = new HashSet<Long>(); 436 437 fetchPrimitives(nodes,OsmPrimitiveType.NODE); 438 fetchPrimitives(ways,OsmPrimitiveType.WAY); 439 fetchPrimitives(relations,OsmPrimitiveType.RELATION); 440 return outputDataSet; 433 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 434 progressMonitor.beginTask(""); 435 try { 436 missingPrimitives = new HashSet<Long>(); 437 438 fetchPrimitives(nodes,OsmPrimitiveType.NODE, progressMonitor); 439 fetchPrimitives(ways,OsmPrimitiveType.WAY, progressMonitor); 440 fetchPrimitives(relations,OsmPrimitiveType.RELATION, progressMonitor); 441 return outputDataSet; 442 } finally { 443 progressMonitor.finishTask(); 444 } 441 445 } 442 446 … … 445 449 * server was submitted but which are not available from the server (the server 446 450 * replied a return code of 404) 447 * 451 * 448 452 * @return the set of ids of missing primitives 449 453 */ -
trunk/src/org/openstreetmap/josm/io/OsmApi.java
r1750 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.awt.EventQueue;7 6 import java.io.BufferedReader; 8 7 import java.io.BufferedWriter; … … 32 31 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 33 32 import org.openstreetmap.josm.data.osm.visitor.CreateOsmChangeVisitor; 33 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 34 34 import org.xml.sax.Attributes; 35 35 import org.xml.sax.InputSource; … … 279 279 * @throws OsmTransferException signifying a non-200 return code, or connection errors 280 280 */ 281 public void createChangeset(String comment) throws OsmTransferException { 282 changeset = new Changeset(); 283 notifyStatusMessage(tr("Opening changeset...")); 284 Properties sysProp = System.getProperties(); 285 Object ua = sysProp.get("http.agent"); 286 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 287 changeset.put("comment", comment); 288 createPrimitive(changeset); 281 public void createChangeset(String comment, ProgressMonitor progressMonitor) throws OsmTransferException { 282 progressMonitor.beginTask((tr("Opening changeset..."))); 283 try { 284 changeset = new Changeset(); 285 Properties sysProp = System.getProperties(); 286 Object ua = sysProp.get("http.agent"); 287 changeset.put("created_by", (ua == null) ? "JOSM" : ua.toString()); 288 changeset.put("comment", comment); 289 createPrimitive(changeset); 290 } finally { 291 progressMonitor.finishTask(); 292 } 289 293 } 290 294 … … 294 298 * @throws OsmTransferException if something goes wrong. 295 299 */ 296 public void stopChangeset() throws OsmTransferException { 297 initialize(); 298 notifyStatusMessage(tr("Closing changeset...")); 299 sendRequest("PUT", "changeset" + "/" + changeset.id + "/close", null); 300 changeset = null; 300 public void stopChangeset(ProgressMonitor progressMonitor) throws OsmTransferException { 301 progressMonitor.beginTask(tr("Closing changeset...")); 302 try { 303 initialize(); 304 sendRequest("PUT", "changeset" + "/" + changeset.id + "/close", null); 305 changeset = null; 306 } finally { 307 progressMonitor.finishTask(); 308 } 301 309 } 302 310 … … 308 316 * @throws OsmTransferException if something is wrong 309 317 */ 310 public Collection<OsmPrimitive> uploadDiff(final Collection<OsmPrimitive> list) throws OsmTransferException { 311 312 if (changeset == null) 313 throw new OsmTransferException(tr("No changeset present for diff upload")); 314 315 initialize(); 316 final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>(); 317 318 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this); 319 320 notifyStatusMessage(tr("Preparing...")); 321 for (OsmPrimitive osm : list) { 322 osm.visit(duv); 323 notifyRelativeProgress(1); 324 } 325 notifyStatusMessage(tr("Uploading...")); 326 setAutoProgressIndication(true); 327 328 String diff = duv.getDocument(); 318 public Collection<OsmPrimitive> uploadDiff(final Collection<OsmPrimitive> list, ProgressMonitor progressMonitor) throws OsmTransferException { 319 320 progressMonitor.beginTask("", list.size() * 2); 329 321 try { 330 String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff); 331 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), Main.pleaseWaitDlg); 332 } catch(OsmTransferException e) { 333 throw e; 334 } catch(Exception e) { 335 throw new OsmTransferException(e); 322 if (changeset == null) 323 throw new OsmTransferException(tr("No changeset present for diff upload")); 324 325 initialize(); 326 final ArrayList<OsmPrimitive> processed = new ArrayList<OsmPrimitive>(); 327 328 CreateOsmChangeVisitor duv = new CreateOsmChangeVisitor(changeset, OsmApi.this); 329 330 progressMonitor.subTask(tr("Preparing...")); 331 for (OsmPrimitive osm : list) { 332 osm.visit(duv); 333 progressMonitor.worked(1); 334 } 335 progressMonitor.indeterminateSubTask(tr("Uploading...")); 336 337 String diff = duv.getDocument(); 338 try { 339 String diffresult = sendRequest("POST", "changeset/" + changeset.id + "/upload", diff); 340 DiffResultReader.parseDiffResult(diffresult, list, processed, duv.getNewIdMap(), 341 progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 342 } catch(OsmTransferException e) { 343 throw e; 344 } catch(Exception e) { 345 throw new OsmTransferException(e); 346 } 347 348 return processed; 336 349 } finally { 337 setAutoProgressIndication(false); 338 } 339 340 return processed; 350 progressMonitor.finishTask(); 351 } 341 352 } 342 353 … … 468 479 469 480 /** 470 * notifies any listeners about the current state of this API. Currently just471 * displays the message in the global progress dialog, see {@see Main#pleaseWaitDlg}472 *473 * @param message a status message.474 */475 protected void notifyStatusMessage(String message) {476 Main.pleaseWaitDlg.currentAction.setText(message);477 }478 479 /**480 * notifies any listeners about the current about a relative progress. Currently just481 * increments the progress monitor in the in the global progress dialog, see {@see Main#pleaseWaitDlg}482 *483 * @param int the delta484 */485 protected void notifyRelativeProgress(int delta) {486 int current= Main.pleaseWaitDlg.progress.getValue();487 Main.pleaseWaitDlg.progress.setValue(current + delta);488 }489 490 491 protected void setAutoProgressIndication(final boolean enabled) {492 EventQueue.invokeLater(493 new Runnable() {494 public void run() {495 Main.pleaseWaitDlg.setIndeterminate(enabled);496 }497 }498 );499 }500 501 /**502 481 * returns the API capabilities; null, if the API is not initialized yet 503 * 482 * 504 483 * @return the API capabilities 505 484 */ -
trunk/src/org/openstreetmap/josm/io/OsmConnection.java
r1670 r1811 11 11 import java.nio.ByteBuffer; 12 12 import java.nio.CharBuffer; 13 import java.nio.charset.CharacterCodingException; 13 14 import java.nio.charset.Charset; 14 15 import java.nio.charset.CharsetEncoder; 15 import java.nio.charset.CharacterCodingException;16 16 17 17 import javax.swing.JCheckBox; … … 126 126 127 127 public void cancel() { 128 Main.pleaseWaitDlg.currentAction.setText(tr("Aborting...")); 128 //TODO 129 //Main.pleaseWaitDlg.currentAction.setText(tr("Aborting...")); 129 130 cancel = true; 130 131 if (activeConnection != null) { -
trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java
r1670 r1811 18 18 import org.openstreetmap.josm.data.osm.history.HistoryRelation; 19 19 import org.openstreetmap.josm.data.osm.history.HistoryWay; 20 import org.openstreetmap.josm.gui. PleaseWaitDialog;20 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 21 import org.openstreetmap.josm.tools.DateUtils; 22 22 import org.xml.sax.Attributes; … … 32 32 * {@see OsmPrimitive}s. We use objects derived from {@see HistoryOsmPrimitive} instead and we 33 33 * keep the data in a dedicated {@see HistoryDataSet}. 34 * 34 * 35 35 */ 36 36 public class OsmHistoryReader { … … 210 210 } 211 211 212 public HistoryDataSet parse(P leaseWaitDialog dialog) throws SAXException, IOException {212 public HistoryDataSet parse(ProgressMonitor progressMonitor) throws SAXException, IOException { 213 213 InputSource inputSource = new InputSource(new InputStreamReader(in, "UTF-8")); 214 dialog.currentAction.setText("Parsing OSM history data ...");214 progressMonitor.beginTask(tr("Parsing OSM history data ...")); 215 215 try { 216 216 SAXParserFactory.newInstance().newSAXParser().parse(inputSource, new Parser()); … … 218 218 e1.printStackTrace(); // broken SAXException chaining 219 219 throw new SAXException(e1); 220 } finally { 221 progressMonitor.finishTask(); 220 222 } 221 223 return data; -
trunk/src/org/openstreetmap/josm/io/OsmImporter.java
r1790 r1811 11 11 import java.io.InputStream; 12 12 13 import javax.swing.JOptionPane;14 15 13 import org.openstreetmap.josm.Main; 16 14 import org.openstreetmap.josm.actions.ExtensionFileFilter; 17 15 import org.openstreetmap.josm.data.osm.DataSet; 18 16 import org.openstreetmap.josm.gui.layer.OsmDataLayer; 17 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 19 18 import org.xml.sax.SAXException; 20 19 … … 46 45 47 46 protected void importData(InputStream in, File associatedFile) throws SAXException, IOException { 48 OsmReader osm = OsmReader.parseDataSetOsm(in, Main.pleaseWaitDlg);47 OsmReader osm = OsmReader.parseDataSetOsm(in, NullProgressMonitor.INSTANCE); 49 48 DataSet dataSet = osm.getDs(); 50 49 OsmDataLayer layer = new OsmDataLayer(dataSet, associatedFile.getName(), associatedFile); -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r1806 r1811 16 16 import java.util.logging.Logger; 17 17 18 import javax.swing.SwingUtilities;19 18 import javax.xml.parsers.ParserConfigurationException; 20 19 import javax.xml.parsers.SAXParserFactory; … … 31 30 import org.openstreetmap.josm.data.osm.Way; 32 31 import org.openstreetmap.josm.data.osm.visitor.AddVisitor; 33 import org.openstreetmap.josm.gui. PleaseWaitDialog;32 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 34 33 import org.openstreetmap.josm.tools.DateUtils; 35 34 import org.xml.sax.Attributes; … … 70 69 /** 71 70 * constructor (for private use only) 72 * 73 * @see #parseDataSet(InputStream, DataSet, P leaseWaitDialog)74 * @see #parseDataSetOsm(InputStream, DataSet, P leaseWaitDialog)71 * 72 * @see #parseDataSet(InputStream, DataSet, ProgressMonitor) 73 * @see #parseDataSetOsm(InputStream, DataSet, ProgressMonitor) 75 74 */ 76 75 private OsmReader() { … … 454 453 * element found there is returned. 455 454 */ 456 public static DataSet parseDataSet(InputStream source, P leaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {457 return parseDataSetOsm(source, p leaseWaitDlg).ds;458 } 459 460 public static OsmReader parseDataSetOsm(InputStream source, final PleaseWaitDialog pleaseWaitDlg) throws SAXException, IOException {455 public static DataSet parseDataSet(InputStream source, ProgressMonitor progressMonitor) throws SAXException, IOException { 456 return parseDataSetOsm(source, progressMonitor).ds; 457 } 458 459 public static OsmReader parseDataSetOsm(InputStream source, ProgressMonitor progressMonitor) throws SAXException, IOException { 461 460 OsmReader osm = new OsmReader(); 462 461 … … 470 469 } 471 470 472 SwingUtilities.invokeLater( 473 new Runnable() { 474 public void run() { 475 pleaseWaitDlg.currentAction.setText(tr("Prepare OSM data...")); 476 pleaseWaitDlg.setIndeterminate(true); 477 } 471 progressMonitor.beginTask(tr("Prepare OSM data...", 2)); 472 try { 473 for (Node n : osm.nodes.values()) { 474 osm.adder.visit(n); 475 } 476 477 progressMonitor.worked(1); 478 479 try { 480 osm.createWays(); 481 osm.createRelations(); 482 } catch (NumberFormatException e) { 483 e.printStackTrace(); 484 throw new SAXException(tr("Ill-formed node id")); 485 } 486 487 // clear all negative ids (new to this file) 488 for (OsmPrimitive o : osm.ds.allPrimitives()) 489 if (o.id < 0) { 490 o.id = 0; 478 491 } 479 ); 480 481 for (Node n : osm.nodes.values()) { 482 osm.adder.visit(n); 483 } 484 485 try { 486 osm.createWays(); 487 osm.createRelations(); 488 } catch (NumberFormatException e) { 489 e.printStackTrace(); 490 throw new SAXException(tr("Ill-formed node id")); 491 } 492 493 // clear all negative ids (new to this file) 494 for (OsmPrimitive o : osm.ds.allPrimitives()) 495 if (o.id < 0) { 496 o.id = 0; 497 } 498 499 SwingUtilities.invokeLater( 500 new Runnable() { 501 public void run() { 502 pleaseWaitDlg.setIndeterminate(false); 503 pleaseWaitDlg.progress.setValue(0); 504 } 505 } 506 ); 507 508 return osm; 492 493 return osm; 494 } finally { 495 progressMonitor.finishTask(); 496 } 509 497 } 510 498 } -
trunk/src/org/openstreetmap/josm/io/OsmServerBackreferenceReader.java
r1806 r1811 8 8 import java.util.Collection; 9 9 10 import org.openstreetmap.josm.Main;11 10 import org.openstreetmap.josm.data.osm.DataSet; 12 11 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 15 14 import org.openstreetmap.josm.data.osm.Way; 16 15 import org.openstreetmap.josm.data.osm.visitor.MergeVisitor; 16 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 17 17 18 18 /** … … 21 21 * which refer to the node. For a {@see Way} or a {@see Relation}, only relations are 22 22 * read. 23 * 23 * 24 24 * OsmServerBackreferenceReader uses the API calls <code>[node|way|relation]/#id/relations</code> 25 25 * and <code>node/#id/ways</code> to retrieve the referring primitives. The default behaviour 26 26 * of these calls is to reply incomplete primitives only. 27 * 27 * 28 28 * If you set {@see #setReadFull(boolean)} to true this reader uses a {@see MultiFetchServerObjectReader} 29 29 * to complete incomplete primitives. 30 * 30 * 31 31 * 32 32 */ … … 42 42 /** 43 43 * constructor 44 * 44 * 45 45 * @param primitive the primitive to be read. Must not be null. primitive.id > 0 expected 46 * 46 * 47 47 * @exception IllegalArgumentException thrown if primitive is null 48 48 * @exception IllegalArgumentException thrown if primitive.id <= 0 … … 60 60 /** 61 61 * constructor 62 * 62 * 63 63 * @param id the id of the primitive. > 0 expected 64 64 * @param type the type of the primitive. Must not be null. 65 * 65 * 66 66 * @exception IllegalArgumentException thrown if id <= 0 67 67 * @exception IllegalArgumentException thrown if type is null 68 * 68 * 69 69 */ 70 70 public OsmServerBackreferenceReader(long id, OsmPrimitiveType type) throws IllegalArgumentException { … … 80 80 /** 81 81 * constructor 82 * 82 * 83 83 * @param id the id of the primitive. > 0 expected 84 84 * @param type the type of the primitive. Must not be null. 85 85 * @param readFull true, if referers should be read fully (i.e. including their immediate children) 86 * 86 * 87 87 */ 88 88 public OsmServerBackreferenceReader(OsmPrimitive primitive, boolean readFull) { … … 93 93 /** 94 94 * constructor 95 * 95 * 96 96 * @param primitive the primitive whose referers are to be read 97 97 * @param readFull true, if referers should be read fully (i.e. including their immediate children) 98 * 98 * 99 99 * @exception IllegalArgumentException thrown if id <= 0 100 100 * @exception IllegalArgumentException thrown if type is null 101 * 101 * 102 102 */ 103 103 public OsmServerBackreferenceReader(long id, OsmPrimitiveType type, boolean readFull) throws IllegalArgumentException { … … 108 108 /** 109 109 * Replies true if this reader also reads immediate children of referring primitives 110 * 110 * 111 111 * @return true if this reader also reads immediate children of referring primitives 112 112 */ … … 117 117 /** 118 118 * Set true if this reader should reads immediate children of referring primitives too. False, otherweise. 119 * 119 * 120 120 * @param readFull true if this reader should reads immediate children of referring primitives too. False, otherweise. 121 121 */ … … 126 126 /** 127 127 * Reads referring ways from the API server and replies them in a {@see DataSet} 128 * 128 * 129 129 * @return the data set 130 130 * @throws OsmTransferException 131 131 */ 132 protected DataSet getReferringWays() throws OsmTransferException { 132 protected DataSet getReferringWays(ProgressMonitor progressMonitor) throws OsmTransferException { 133 133 InputStream in = null; 134 try {135 Main.pleaseWaitDlg.progress.setValue(0);136 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));134 progressMonitor.beginTask(null, 2); 135 try { 136 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 137 137 StringBuffer sb = new StringBuffer(); 138 138 sb.append(primitiveType.getAPIName()) 139 139 .append("/").append(id).append("/ways"); 140 140 141 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);141 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 142 142 if (in == null) 143 143 return null; 144 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading referring ways ..."));145 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);144 progressMonitor.subTask(tr("Downloading referring ways ...")); 145 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 146 146 } catch(OsmTransferException e) { 147 147 throw e; … … 151 151 throw new OsmTransferException(e); 152 152 } finally { 153 progressMonitor.finishTask(); 153 154 if (in != null) { 154 155 try { … … 162 163 163 164 * Reads referring relations from the API server and replies them in a {@see DataSet} 164 * 165 * 165 166 * @return the data set 166 167 * @throws OsmTransferException 167 168 */ 168 protected DataSet getReferringRelations() throws OsmTransferException { 169 protected DataSet getReferringRelations(ProgressMonitor progressMonitor) throws OsmTransferException { 169 170 InputStream in = null; 170 try {171 Main.pleaseWaitDlg.progress.setValue(0);172 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));171 progressMonitor.beginTask(null, 2); 172 try { 173 progressMonitor.subTask(tr("Contacting OSM Server...")); 173 174 StringBuffer sb = new StringBuffer(); 174 175 sb.append(primitiveType.getAPIName()) 175 176 .append("/").append(id).append("/relations"); 176 177 177 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);178 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 178 179 if (in == null) 179 180 return null; 180 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading referring relations ..."));181 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);181 progressMonitor.subTask(tr("Downloading referring relations ...")); 182 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, true)); 182 183 } catch(OsmTransferException e) { 183 184 throw e; … … 187 188 throw new OsmTransferException(e); 188 189 } finally { 190 progressMonitor.finishTask(); 189 191 if (in != null) { 190 192 try { … … 200 202 * incomplete primitives are read from the server with an individual <tt>/api/0.6/[way,relation]/#id/full</tt> 201 203 * request. 202 * 204 * 203 205 * <ul> 204 206 * <li>if this reader reads referers for an {@see Node}, referring ways are always … … 207 209 * are only read fully if {@see #setReadFull(boolean)} is set to true.</li> 208 210 * </ul> 209 * 211 * 210 212 * The method replies the modified dataset. 211 * 213 * 212 214 * @param ds the original dataset 213 215 * @return the modified dataset 214 216 * @throws OsmTransferException thrown if an exception occurs. 215 217 */ 216 protected DataSet readIncompletePrimitives(DataSet ds) throws OsmTransferException { 217 Collection<Way> waysToCheck = new ArrayList<Way>(ds.ways); 218 if (isReadFull() ||primitiveType.equals(OsmPrimitiveType.NODE)) { 219 for (Way way: waysToCheck) { 220 if (way.id > 0 && way.incomplete) { 221 OsmServerObjectReader reader = new OsmServerObjectReader(way.id, OsmPrimitiveType.from(way), true /* read full */); 222 DataSet wayDs = reader.parseOsm(); 223 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 224 visitor.merge(); 218 protected DataSet readIncompletePrimitives(DataSet ds, ProgressMonitor progressMonitor) throws OsmTransferException { 219 progressMonitor.beginTask(null, 2); 220 try { 221 Collection<Way> waysToCheck = new ArrayList<Way>(ds.ways); 222 if (isReadFull() ||primitiveType.equals(OsmPrimitiveType.NODE)) { 223 for (Way way: waysToCheck) { 224 if (way.id > 0 && way.incomplete) { 225 OsmServerObjectReader reader = new OsmServerObjectReader(way.id, OsmPrimitiveType.from(way), true /* read full */); 226 DataSet wayDs = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 227 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 228 visitor.merge(); 229 } 225 230 } 226 231 } 227 }228 if (isReadFull()) {229 Collection<Relation>relationsToCheck= new ArrayList<Relation>(ds.relations);230 for (Relation relation: relationsToCheck) {231 if(relation.id> 0 &&relation.incomplete) {232 OsmServerObjectReaderreader= new OsmServerObjectReader(relation.id, OsmPrimitiveType.from(relation), true /* read full */);233 DataSet wayDs = reader.parseOsm();234 MergeVisitorvisitor= new MergeVisitor(ds, wayDs);235 visitor.merge();232 if (isReadFull()) { 233 Collection<Relation> relationsToCheck = new ArrayList<Relation>(ds.relations); 234 for (Relation relation: relationsToCheck) { 235 if (relation.id > 0 && relation.incomplete) { 236 OsmServerObjectReader reader = new OsmServerObjectReader(relation.id, OsmPrimitiveType.from(relation), true /* read full */); 237 DataSet wayDs = reader.parseOsm(progressMonitor.createSubTaskMonitor(1, false)); 238 MergeVisitor visitor = new MergeVisitor(ds, wayDs); 239 visitor.merge(); 240 } 236 241 } 237 242 } 238 } 239 return ds; 243 return ds; 244 } finally { 245 progressMonitor.finishTask(); 246 } 240 247 } 241 248 … … 243 250 * Reads the referring primitives from the OSM server, parses them and 244 251 * replies them as {@see DataSet} 245 * 252 * 246 253 * @return the dataset with the referring primitives 247 254 * @exception OsmTransferException thrown if an error occurs while communicating with the server 248 255 */ 249 256 @Override 250 public DataSet parseOsm() throws OsmTransferException { 251 DataSet ret = new DataSet(); 252 if (primitiveType.equals(OsmPrimitiveType.NODE)) { 253 DataSet ds = getReferringWays(); 257 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 258 progressMonitor.beginTask(null, 3); 259 try { 260 DataSet ret = new DataSet(); 261 if (primitiveType.equals(OsmPrimitiveType.NODE)) { 262 DataSet ds = getReferringWays(progressMonitor.createSubTaskMonitor(1, false)); 263 MergeVisitor visitor = new MergeVisitor(ret,ds); 264 visitor.merge(); 265 ret = visitor.getMyDataSet(); 266 } 267 DataSet ds = getReferringRelations(progressMonitor.createSubTaskMonitor(1, false)); 254 268 MergeVisitor visitor = new MergeVisitor(ret,ds); 255 269 visitor.merge(); 256 270 ret = visitor.getMyDataSet(); 257 } 258 DataSet ds = getReferringRelations(); 259 MergeVisitor visitor = new MergeVisitor(ret,ds); 260 visitor.merge(); 261 ret = visitor.getMyDataSet(); 262 readIncompletePrimitives(ret); 263 return ret; 271 readIncompletePrimitives(ret, progressMonitor.createSubTaskMonitor(1, false)); 272 return ret; 273 } finally { 274 progressMonitor.finishTask(); 275 } 264 276 } 265 277 } -
trunk/src/org/openstreetmap/josm/io/OsmServerHistoryReader.java
r1790 r1811 7 7 import java.io.InputStream; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.data.osm.DataSet; 11 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 12 11 import org.openstreetmap.josm.data.osm.history.HistoryDataSet; 12 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 13 13 import org.xml.sax.SAXException; 14 14 … … 17 17 /** 18 18 * Reads the history of an {@see OsmPrimitive} from the OSM API server. 19 * 19 * 20 20 */ 21 21 public class OsmServerHistoryReader extends OsmServerReader { … … 26 26 /** 27 27 * constructor 28 * 28 * 29 29 * @param type the type of the primitive whose history is to be fetched from the server. 30 30 * Must not be null. 31 31 * @param id the id of the primitive 32 * 32 * 33 33 * @exception IllegalArgumentException thrown, if type is null 34 34 */ … … 44 44 /** 45 45 * don't use - not implemented! 46 * 46 * 47 47 * @exception NotImplementedException 48 48 */ 49 49 @Override 50 public DataSet parseOsm() throws OsmTransferException { 50 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 51 51 throw new NotImplementedException(); 52 52 } … … 54 54 /** 55 55 * Fetches the history from the OSM API and parses it 56 * 56 * 57 57 * @return the data set with the parsed history data 58 58 * @throws OsmTransferException thrown, if an exception occurs 59 59 */ 60 public HistoryDataSet parseHistory() throws OsmTransferException { 60 public HistoryDataSet parseHistory(ProgressMonitor progressMonitor) throws OsmTransferException { 61 61 InputStream in = null; 62 progressMonitor.beginTask(""); 62 63 try { 63 Main.pleaseWaitDlg.progress.setValue(0); 64 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 64 progressMonitor.indeterminateSubTask(tr("Contacting OSM Server...")); 65 65 StringBuffer sb = new StringBuffer(); 66 66 sb.append(primitiveType.getAPIName()) 67 67 .append("/").append(id).append("/history"); 68 68 69 in = getInputStream(sb.toString(), Main.pleaseWaitDlg);69 in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 70 70 if (in == null) 71 71 return null; 72 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading history..."));72 progressMonitor.indeterminateSubTask(tr("Downloading history...")); 73 73 final OsmHistoryReader reader = new OsmHistoryReader(in); 74 HistoryDataSet data = reader.parse( Main.pleaseWaitDlg);74 HistoryDataSet data = reader.parse(progressMonitor.createSubTaskMonitor(1, true)); 75 75 return data; 76 76 } catch(OsmTransferException e) { … … 81 81 throw new OsmTransferException(e); 82 82 } finally { 83 progressMonitor.finishTask(); 83 84 if (in != null) { 84 85 try { -
trunk/src/org/openstreetmap/josm/io/OsmServerLocationReader.java
r1790 r1811 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.io.IOException;7 6 import java.io.InputStream; 8 7 9 import org.openstreetmap.josm.Main;10 8 import org.openstreetmap.josm.data.osm.DataSet; 11 import org. xml.sax.SAXException;9 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 10 13 11 public class OsmServerLocationReader extends OsmServerReader { … … 23 21 */ 24 22 @Override 25 public DataSet parseOsm() throws OsmTransferException { 23 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 26 24 InputStream in = null; 25 progressMonitor.beginTask(tr("Contacting Server...", 10)); 27 26 try { 28 Main.pleaseWaitDlg.progress.setValue(0); 29 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting Server...")); 30 31 in = getInputStreamRaw(url, Main.pleaseWaitDlg); 27 in = getInputStreamRaw(url, progressMonitor.createSubTaskMonitor(9, false)); 32 28 if (in == null) 33 29 return null; 34 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));35 return OsmReader.parseDataSet(in, Main.pleaseWaitDlg);30 progressMonitor.subTask(tr("Downloading OSM data...")); 31 return OsmReader.parseDataSet(in, progressMonitor.createSubTaskMonitor(1, false)); 36 32 } catch(OsmTransferException e) { 37 33 throw e; … … 41 37 throw new OsmTransferException(e); 42 38 } finally { 39 progressMonitor.finishTask(); 43 40 try { 44 41 if (in != null) { -
trunk/src/org/openstreetmap/josm/io/OsmServerObjectReader.java
r1790 r1811 7 7 import java.io.InputStream; 8 8 9 import org.openstreetmap.josm.Main;10 9 import org.openstreetmap.josm.data.osm.DataSet; 11 10 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 12 12 import org.xml.sax.SAXException; 13 13 … … 30 30 */ 31 31 @Override 32 public DataSet parseOsm() throws OsmTransferException { 32 public DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException { 33 progressMonitor.beginTask("", 1); 33 34 try { 34 Main.pleaseWaitDlg.progress.setValue(0); 35 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 35 progressMonitor.subTask(tr("Downloading OSM data...")); 36 36 StringBuffer sb = new StringBuffer(); 37 37 sb.append(type.getAPIName()); … … 42 42 } 43 43 44 final InputStream in = getInputStream(sb.toString(), Main.pleaseWaitDlg);44 final InputStream in = getInputStream(sb.toString(), progressMonitor.createSubTaskMonitor(1, true)); 45 45 if (in == null) 46 46 return null; 47 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data...")); 48 final OsmReader osm = OsmReader.parseDataSetOsm(in,Main.pleaseWaitDlg); 47 final OsmReader osm = OsmReader.parseDataSetOsm(in, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false)); 49 48 final DataSet data = osm.getDs(); 50 49 … … 64 63 return null; 65 64 throw new OsmTransferException(e); 65 } finally { 66 progressMonitor.finishTask(); 66 67 } 67 68 } -
trunk/src/org/openstreetmap/josm/io/OsmServerReader.java
r1670 r1811 14 14 import java.util.zip.InflaterInputStream; 15 15 16 import javax.swing.JOptionPane;17 18 16 import org.openstreetmap.josm.Main; 19 17 import org.openstreetmap.josm.data.osm.DataSet; 20 import org.openstreetmap.josm.gui. PleaseWaitDialog;18 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 21 19 22 20 /** … … 40 38 * @return An reader reading the input stream (servers answer) or <code>null</code>. 41 39 */ 42 protected InputStream getInputStream(String urlStr, P leaseWaitDialog pleaseWaitDlg) throws OsmTransferException {40 protected InputStream getInputStream(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 43 41 api.initialize(); 44 42 urlStr = api.getBaseUrl() + urlStr; 45 return getInputStreamRaw(urlStr, p leaseWaitDlg);43 return getInputStreamRaw(urlStr, progressMonitor); 46 44 } 47 45 48 protected InputStream getInputStreamRaw(String urlStr, P leaseWaitDialog pleaseWaitDlg) throws OsmTransferException {46 protected InputStream getInputStreamRaw(String urlStr, ProgressMonitor progressMonitor) throws OsmTransferException { 49 47 URL url = null; 50 48 try { … … 97 95 98 96 String encoding = activeConnection.getContentEncoding(); 99 InputStream inputStream = new ProgressInputStream(activeConnection, p leaseWaitDlg);97 InputStream inputStream = new ProgressInputStream(activeConnection, progressMonitor); 100 98 if (encoding != null && encoding.equalsIgnoreCase("gzip")) { 101 99 inputStream = new GZIPInputStream(inputStream); … … 114 112 } 115 113 116 public abstract DataSet parseOsm() throws OsmTransferException; 114 public abstract DataSet parseOsm(ProgressMonitor progressMonitor) throws OsmTransferException; 117 115 118 116 } -
trunk/src/org/openstreetmap/josm/io/OsmServerWriter.java
r1750 r1811 13 13 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 14 import org.openstreetmap.josm.data.osm.visitor.NameVisitor; 15 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 15 16 16 17 /** … … 81 82 * @param primitives list of objects to send 82 83 */ 83 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives) throws OsmTransferException { 84 public void uploadOsm(String apiVersion, Collection<OsmPrimitive> primitives, ProgressMonitor progressMonitor) throws OsmTransferException { 84 85 processed = new LinkedList<OsmPrimitive>(); 85 86 86 87 api.initialize(); 87 88 88 Main.pleaseWaitDlg.progress.setMaximum(primitives.size()); 89 Main.pleaseWaitDlg.progress.setValue(0); 89 progressMonitor.beginTask(""); 90 90 91 // check whether we can use changeset 92 // 93 boolean canUseChangeset = api.hasChangesetSupport(); 94 boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 95 if (useChangeset && ! canUseChangeset) { 96 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion)); 97 useChangeset = false; 98 } 91 try { 99 92 100 if (useChangeset) { 101 // upload everything in one changeset 93 // check whether we can use changeset 102 94 // 103 try { 104 api.createChangeset(getChangesetComment()); 105 processed.addAll(api.uploadDiff(primitives)); 106 } catch(OsmTransferException e) { 107 throw e; 108 } finally { 95 boolean canUseChangeset = api.hasChangesetSupport(); 96 boolean useChangeset = Main.pref.getBoolean("osm-server.atomic-upload", apiVersion.compareTo("0.6")>=0); 97 if (useChangeset && ! canUseChangeset) { 98 System.out.println(tr("WARNING: preference ''{0}'' or api version ''{1}'' of dataset requires to use changesets, but API is not able to handle them. Ignoring changesets.", "osm-server.atomic-upload", apiVersion)); 99 useChangeset = false; 100 } 101 102 if (useChangeset) { 103 // upload everything in one changeset 104 // 109 105 try { 110 if (canUseChangeset) { 111 api.stopChangeset(); 106 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 107 processed.addAll(api.uploadDiff(primitives, progressMonitor.createSubTaskMonitor(ProgressMonitor.ALL_TICKS, false))); 108 } catch(OsmTransferException e) { 109 throw e; 110 } finally { 111 try { 112 if (canUseChangeset) { 113 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 114 } 115 } catch (Exception ee) { 116 ee.printStackTrace(); 117 // ignore nested exception 112 118 } 113 } catch (Exception ee) {114 ee.printStackTrace();115 // ignore nested exception116 119 } 120 } else { 121 // upload changes individually (90% of code is for the status display...) 122 // 123 progressMonitor.setTicksCount(primitives.size()); 124 api.createChangeset(getChangesetComment(), progressMonitor.createSubTaskMonitor(0, false)); 125 NameVisitor v = new NameVisitor(); 126 uploadStartTime = System.currentTimeMillis(); 127 for (OsmPrimitive osm : primitives) { 128 osm.visit(v); 129 int progress = progressMonitor.getTicks(); 130 String time_left_str = timeLeft(progress, primitives.size()); 131 progressMonitor.subTask( 132 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 133 Math.round(100.0*progress/primitives.size()), progress, 134 primitives.size(), time_left_str, tr(v.className), v.name, osm.id)); 135 makeApiRequest(osm); 136 processed.add(osm); 137 progressMonitor.worked(1); 138 } 139 api.stopChangeset(progressMonitor.createSubTaskMonitor(0, false)); 117 140 } 118 } else { 119 // upload changes individually (90% of code is for the status display...) 120 // 121 api.createChangeset(getChangesetComment()); 122 NameVisitor v = new NameVisitor(); 123 uploadStartTime = System.currentTimeMillis(); 124 for (OsmPrimitive osm : primitives) { 125 osm.visit(v); 126 int progress = Main.pleaseWaitDlg.progress.getValue(); 127 String time_left_str = timeLeft(progress, primitives.size()); 128 Main.pleaseWaitDlg.currentAction.setText( 129 tr("{0}% ({1}/{2}), {3} left. Uploading {4}: {5} (id: {6})", 130 Math.round(100.0*progress/primitives.size()), progress, 131 primitives.size(), time_left_str, tr(v.className), v.name, osm.id)); 132 makeApiRequest(osm); 133 processed.add(osm); 134 Main.pleaseWaitDlg.progress.setValue(progress+1); 135 } 136 api.stopChangeset(); 141 } finally { 142 progressMonitor.finishTask(); 137 143 } 138 144 } -
trunk/src/org/openstreetmap/josm/io/ProgressInputStream.java
r1670 r1811 8 8 import java.net.URLConnection; 9 9 10 import org.openstreetmap.josm.gui.PleaseWaitDialog; 10 import org.openstreetmap.josm.gui.progress.NullProgressMonitor; 11 import org.openstreetmap.josm.gui.progress.ProgressMonitor; 11 12 12 13 /** … … 19 20 private int readSoFar = 0; 20 21 private int lastDialogUpdate = 0; 22 private boolean sizeKnown; 21 23 private final URLConnection connection; 22 private PleaseWaitDialog pleaseWaitDlg;24 private final ProgressMonitor progressMonitor; 23 25 24 public ProgressInputStream(URLConnection con, P leaseWaitDialog pleaseWaitDlg) throws OsmTransferException {26 public ProgressInputStream(URLConnection con, ProgressMonitor progressMonitor) throws OsmTransferException { 25 27 this.connection = con; 28 if (progressMonitor == null) { 29 progressMonitor = NullProgressMonitor.INSTANCE; 30 } 31 this.progressMonitor = progressMonitor; 32 progressMonitor.beginTask(tr("Contacting OSM Server..."), 1); 33 progressMonitor.indeterminateSubTask(null); 26 34 27 35 try { … … 33 41 } 34 42 35 int contentLength = con.getContentLength(); 36 this.pleaseWaitDlg = pleaseWaitDlg; 37 if (pleaseWaitDlg == null) 38 return; 39 if (contentLength > 0) { 40 pleaseWaitDlg.progress.setMaximum(contentLength); 41 } else { 42 pleaseWaitDlg.progress.setMaximum(0); 43 updateSize(); 44 if (!sizeKnown) { 45 progressMonitor.indeterminateSubTask(tr("Downloading OSM data...")); 43 46 } 44 pleaseWaitDlg.progress.setValue(0);45 47 } 46 48 47 49 @Override public void close() throws IOException { 48 50 in.close(); 51 progressMonitor.finishTask(); 49 52 } 50 53 … … 53 56 if (read != -1) { 54 57 advanceTicker(read); 58 } else { 59 progressMonitor.finishTask(); 55 60 } 56 61 return read; … … 61 66 if (read != -1) { 62 67 advanceTicker(1); 68 } else { 69 progressMonitor.finishTask(); 63 70 } 64 71 return read; … … 70 77 */ 71 78 private void advanceTicker(int amount) { 72 if (pleaseWaitDlg == null)73 return;74 75 if (pleaseWaitDlg.progress.getMaximum() == 0 && connection.getContentLength() != -1) {76 pleaseWaitDlg.progress.setMaximum(connection.getContentLength());77 }78 79 79 readSoFar += amount; 80 updateSize(); 80 81 81 82 if (readSoFar / 1024 != lastDialogUpdate) { 82 83 lastDialogUpdate++; 83 String progStr = " "+readSoFar/1024+"/"; 84 progStr += (pleaseWaitDlg.progress.getMaximum()==0) ? "??? KB" : (pleaseWaitDlg.progress.getMaximum()/1024)+" KB"; 85 pleaseWaitDlg.progress.setValue(readSoFar); 84 if (sizeKnown) { 85 progressMonitor.setExtraText(readSoFar/1024 + " KB"); 86 progressMonitor.setTicks(readSoFar); 87 } else { 88 progressMonitor.setExtraText("??? KB"); 89 } 90 } 91 } 86 92 87 String cur = pleaseWaitDlg.currentAction.getText(); 88 int i = cur.indexOf(' '); 89 if (i != -1) { 90 cur = cur.substring(0, i) + progStr; 91 } else { 92 cur += progStr; 93 } 94 pleaseWaitDlg.currentAction.setText(cur); 93 private void updateSize() { 94 if (!sizeKnown && connection.getContentLength() > 0) { 95 sizeKnown = true; 96 progressMonitor.subTask(tr("Downloading OSM data...")); 97 progressMonitor.setTicksCount(connection.getContentLength()); 95 98 } 96 99 }
Note:
See TracChangeset
for help on using the changeset viewer.