Ticket #4288: patch-4288.diff
File patch-4288.diff, 12.7 KB (added by , 14 years ago) |
---|
-
src/org/openstreetmap/josm/Main.java
diff --git a/src/org/openstreetmap/josm/Main.java b/src/org/openstreetmap/josm/Main.java index e862354..ad0ecb0 100644
a b import java.awt.Rectangle; 9 9 import java.awt.Toolkit; 10 10 import java.awt.event.KeyEvent; 11 11 import java.io.File; 12 import java.io.IOException;13 12 import java.net.URI; 14 13 import java.net.URISyntaxException; 15 14 import java.util.ArrayList; … … import org.openstreetmap.josm.gui.MainMenu; 49 48 import org.openstreetmap.josm.gui.MapFrame; 50 49 import org.openstreetmap.josm.gui.SplashScreen; 51 50 import org.openstreetmap.josm.gui.dialogs.LayerListDialog; 52 import org.openstreetmap.josm.gui.help.HelpBrowser;53 51 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 54 52 import org.openstreetmap.josm.gui.layer.Layer; 55 53 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … import org.openstreetmap.josm.gui.preferences.MapPaintPreference; 58 56 import org.openstreetmap.josm.gui.preferences.ProjectionPreference; 59 57 import org.openstreetmap.josm.gui.preferences.TaggingPresetPreference; 60 58 import org.openstreetmap.josm.gui.preferences.ToolbarPreferences; 61 import org.openstreetmap.josm.io.IllegalDataException;62 59 import org.openstreetmap.josm.plugins.PluginHandler; 63 60 import org.openstreetmap.josm.tools.ImageProvider; 64 61 import org.openstreetmap.josm.tools.OsmUrlToBounds; … … abstract public class Main { 377 374 378 375 public void postConstructorProcessCmdLine(Map<String, Collection<String>> args) { 379 376 if (args.containsKey("download")) { 377 List<File> fileList = new ArrayList<File>(); 380 378 for (String s : args.get("download")) { 381 downloadFromParamString(false, s); 379 File f = null; 380 switch(paramType(s)) { 381 case httpUrl: 382 downloadFromParamHttp(false, s); 383 break; 384 case bounds: 385 downloadFromParamBounds(false, s); 386 break; 387 case fileUrl: 388 try { 389 f = new File(new URI(s)); 390 } catch (URISyntaxException e) { 391 JOptionPane.showMessageDialog( 392 Main.parent, 393 tr("Ignoring malformed file URL: \"{0}\"", s), 394 tr("Warning"), 395 JOptionPane.WARNING_MESSAGE 396 ); 397 } 398 if (f!=null) { 399 fileList.add(f); 400 } 401 break; 402 case fileName: 403 f = new File(s); 404 fileList.add(f); 405 break; 406 } 407 } 408 if(!fileList.isEmpty()) 409 { 410 OpenFileAction.openFiles(fileList); 382 411 } 383 412 } 384 413 if (args.containsKey("downloadgps")) { 385 414 for (String s : args.get("downloadgps")) { 386 downloadFromParamString(true, s); 415 switch(paramType(s)) { 416 case httpUrl: 417 downloadFromParamHttp(true, s); 418 break; 419 case bounds: 420 downloadFromParamBounds(true, s); 421 break; 422 case fileUrl: 423 case fileName: 424 JOptionPane.showMessageDialog( 425 Main.parent, 426 tr("Parameter \"downloadgps\" does not accept file names or file URLs"), 427 tr("Warning"), 428 JOptionPane.WARNING_MESSAGE 429 ); 430 } 387 431 } 388 432 } 389 433 if (args.containsKey("selection")) { … … abstract public class Main { 416 460 return true; 417 461 } 418 462 419 private static void downloadFromParamString(final boolean rawGps, String s) {420 if (s.startsWith("http:")) {421 final Bounds b = OsmUrlToBounds.parse(s);422 if (b == null) {423 JOptionPane.showMessageDialog(424 Main.parent,425 tr("Ignoring malformed URL: \"{0}\"", s),426 tr("Warning"),427 JOptionPane.WARNING_MESSAGE428 );429 } else {430 //DownloadTask osmTask = main.menu.download.downloadTasks.get(0);431 DownloadTask osmTask = new DownloadOsmTask();432 Future<?> future = osmTask.download(true, b, null);433 Main.worker.submit(new PostDownloadHandler(osmTask, future));434 }435 return;436 }437 463 438 if (s.startsWith("file:")) { 439 File f = null; 440 try { 441 f = new File(new URI(s)); 442 } catch (URISyntaxException e) { 443 JOptionPane.showMessageDialog( 444 Main.parent, 445 tr("Ignoring malformed file URL: \"{0}\"", s), 446 tr("Warning"), 447 JOptionPane.WARNING_MESSAGE 448 ); 449 } 450 try { 451 if (f!=null) { 452 OpenFileAction.openFile(f); 453 } 454 } catch(IllegalDataException e) { 455 e.printStackTrace(); 456 JOptionPane.showMessageDialog( 457 Main.parent, 458 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 459 tr("Error"), 460 JOptionPane.ERROR_MESSAGE 461 ); 462 }catch(IOException e) { 463 e.printStackTrace(); 464 JOptionPane.showMessageDialog( 465 Main.parent, 466 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 467 tr("Error"), 468 JOptionPane.ERROR_MESSAGE 469 ); 470 } 471 return; 464 /** 465 * The type of a command line parameter, to be used in switch statements. 466 * @see paramType 467 */ 468 private enum DownloadParamType { httpUrl, fileUrl, bounds, fileName } 469 470 /** 471 * Guess the type of a parameter string specified on the command line with --download= or --downloadgps. 472 * @param s A parameter string 473 * @return The guessed parameter type 474 */ 475 private DownloadParamType paramType(String s) { 476 if(s.startsWith("http:")) return DownloadParamType.httpUrl; 477 if(s.startsWith("file:")) return DownloadParamType.fileUrl; 478 final StringTokenizer st = new StringTokenizer(s, ","); 479 // we assume a string with exactly 3 commas is a bounds parameter 480 if (st.countTokens() == 4) return DownloadParamType.bounds; 481 // everything else must be a file name 482 return DownloadParamType.fileName; 483 } 484 485 /** 486 * Download area specified on the command line as OSM URL. 487 * @param rawGps Flag to download raw GPS tracks 488 * @param s The URL parameter 489 */ 490 private static void downloadFromParamHttp(final boolean rawGps, String s) { 491 final Bounds b = OsmUrlToBounds.parse(s); 492 if (b == null) { 493 JOptionPane.showMessageDialog( 494 Main.parent, 495 tr("Ignoring malformed URL: \"{0}\"", s), 496 tr("Warning"), 497 JOptionPane.WARNING_MESSAGE 498 ); 499 } else { 500 downloadFromParamBounds(rawGps, b); 472 501 } 502 } 473 503 504 /** 505 * Download area specified on the command line as bounds string. 506 * @param rawGps Flag to download raw GPS tracks 507 * @param s The bounds parameter 508 */ 509 private static void downloadFromParamBounds(final boolean rawGps, String s) { 474 510 final StringTokenizer st = new StringTokenizer(s, ","); 475 511 if (st.countTokens() == 4) { 476 512 Bounds b = new Bounds( 477 513 new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())), 478 514 new LatLon(Double.parseDouble(st.nextToken()),Double.parseDouble(st.nextToken())) 479 515 ); 480 try { 481 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 482 // asynchronously launch the download task ... 483 Future<?> future = task.download(true, b, null); 484 // ... and the continuation when the download is finished (this will wait for the download to finish) 485 Main.worker.execute(new PostDownloadHandler(task, future)); 486 return; 487 } catch (final NumberFormatException e) { 488 } 489 } 490 File f = new File(s); 491 try { 492 OpenFileAction.openFile(f); 493 }catch(IllegalDataException e) { 494 e.printStackTrace(); 495 JOptionPane.showMessageDialog( 496 Main.parent, 497 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 498 tr("Error"), 499 JOptionPane.ERROR_MESSAGE 500 ); 501 }catch(IOException e) { 502 e.printStackTrace(); 503 JOptionPane.showMessageDialog( 504 Main.parent, 505 tr("<html>Could not read file ''{0}\''.<br> Error is: <br>{1}</html>", f.getName(), e.getMessage()), 506 tr("Error"), 507 JOptionPane.ERROR_MESSAGE 508 ); 516 downloadFromParamBounds(rawGps, b); 509 517 } 510 518 } 511 519 520 /** 521 * Download area specified as Bounds value. 522 * @param rawGps Flag to download raw GPS tracks 523 * @param b The bounds value 524 * @see downloadFromParamBounds(final boolean rawGps, String s) 525 * @see downloadFromParamHttp 526 */ 527 private static void downloadFromParamBounds(final boolean rawGps, Bounds b) { 528 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 529 // asynchronously launch the download task ... 530 Future<?> future = task.download(true, b, null); 531 // ... and the continuation when the download is finished (this will wait for the download to finish) 532 Main.worker.execute(new PostDownloadHandler(task, future)); 533 } 534 535 512 536 public static void determinePlatformHook() { 513 537 String os = System.getProperty("os.name"); 514 538 if (os == null) { -
src/org/openstreetmap/josm/actions/OpenFileAction.java
diff --git a/src/org/openstreetmap/josm/actions/OpenFileAction.java b/src/org/openstreetmap/josm/actions/OpenFileAction.java index a4f588f..33c9ab4 100644
a b public class OpenFileAction extends DiskAccessAction { 59 59 setEnabled(! Main.applet); 60 60 } 61 61 62 63 @Deprecated 62 64 static public void openFile(File f) throws IOException, IllegalDataException { 63 65 for (FileImporter importer : ExtensionFileFilter.importers) 64 if ( importer.acceptFile(f)) {66 if (!importer.isBatchImporter() && importer.acceptFile(f)) { 65 67 importer.importData(f); 66 68 } 67 69 } 68 70 71 /** 72 * Open a list of files. The complete list will be passed to batch importers. 73 * @param fileList A list of files 74 */ 75 static public void openFiles(List<File> fileList) { 76 OpenFileTask task = new OpenFileTask(fileList, null); 77 Main.worker.submit(task); 78 } 79 69 80 static public class OpenFileTask extends PleaseWaitRunnable { 70 81 private List<File> files; 71 82 private FileFilter fileFilter; -
src/org/openstreetmap/josm/gui/MainApplication.java
diff --git a/src/org/openstreetmap/josm/gui/MainApplication.java b/src/org/openstreetmap/josm/gui/MainApplication.java index e232296..4c303d9 100644
a b public class MainApplication extends Main { 77 77 "\t[--download=]<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z)")+"\n"+ 78 78 "\t[--download=]<filename> "+tr("Open a file (any file type that can be opened with File/Open)")+"\n"+ 79 79 "\t--downloadgps=minlat,minlon,maxlat,maxlon "+tr("Download the bounding box as raw gps")+"\n"+ 80 "\t--downloadgps=<url> "+tr("Download the location at the url (with lat=x&lon=y&zoom=z) as raw gps")+"\n"+ 80 81 "\t--selection=<searchstring> "+tr("Select with the given search")+"\n"+ 81 82 "\t--[no-]maximize "+tr("Launch in maximized mode")+"\n"+ 82 83 "\t--reset-preferences "+tr("Reset the preferences to default")+"\n\n"+