- Timestamp:
- 2017-04-23T19:14:12+02:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 7 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r11925 r11986 18 18 import java.util.Arrays; 19 19 import java.util.Collection; 20 import java.util.Collections; 20 21 import java.util.EnumSet; 21 22 import java.util.HashMap; … … 826 827 } 827 828 829 /** 830 * Handle command line instructions after GUI has been initialized. 831 * @param args program arguments 832 */ 828 833 protected static void postConstructorProcessCmdLine(ProgramArguments args) { 834 List<Future<?>> tasks = new ArrayList<>(); 829 835 List<File> fileList = new ArrayList<>(); 830 836 for (String s : args.get(Option.DOWNLOAD)) { 831 DownloadParamType.paramType(s).download(s, fileList);837 tasks.addAll(DownloadParamType.paramType(s).download(s, fileList)); 832 838 } 833 839 if (!fileList.isEmpty()) { 834 OpenFileAction.openFiles(fileList, true);840 tasks.add(OpenFileAction.openFiles(fileList, true)); 835 841 } 836 842 for (String s : args.get(Option.DOWNLOADGPS)) { 837 DownloadParamType.paramType(s).downloadGps(s); 843 tasks.addAll(DownloadParamType.paramType(s).downloadGps(s)); 844 } 845 // Make sure all download tasks complete before handling selection arguments 846 for (Future<?> task : tasks) { 847 try { 848 task.get(); 849 } catch (InterruptedException | ExecutionException e) { 850 error(e); 851 } 838 852 } 839 853 for (String s : args.get(Option.SELECTION)) { … … 868 882 } 869 883 884 /** 885 * Shutdown JOSM. 886 */ 870 887 protected void shutdown() { 871 888 if (!GraphicsEnvironment.isHeadless()) { … … 897 914 httpUrl { 898 915 @Override 899 voiddownload(String s, Collection<File> fileList) {900 new OpenLocationAction().openUrl(false, s);916 List<Future<?>> download(String s, Collection<File> fileList) { 917 return new OpenLocationAction().openUrl(false, s); 901 918 } 902 919 903 920 @Override 904 voiddownloadGps(String s) {921 List<Future<?>> downloadGps(String s) { 905 922 final Bounds b = OsmUrlToBounds.parse(s); 906 923 if (b == null) { … … 911 928 JOptionPane.WARNING_MESSAGE 912 929 ); 913 return ;930 return Collections.emptyList(); 914 931 } 915 downloadFromParamBounds(true, b);932 return downloadFromParamBounds(true, b); 916 933 } 917 934 }, fileUrl { 918 935 @Override 919 voiddownload(String s, Collection<File> fileList) {936 List<Future<?>> download(String s, Collection<File> fileList) { 920 937 File f = null; 921 938 try { … … 933 950 fileList.add(f); 934 951 } 952 return Collections.emptyList(); 935 953 } 936 954 }, bounds { … … 940 958 * @param rawGps Flag to download raw GPS tracks 941 959 * @param s The bounds parameter 960 * @return the complete download task (including post-download handler), or {@code null} 942 961 */ 943 private voiddownloadFromParamBounds(final boolean rawGps, String s) {962 private List<Future<?>> downloadFromParamBounds(final boolean rawGps, String s) { 944 963 final StringTokenizer st = new StringTokenizer(s, ","); 945 964 if (st.countTokens() == 4) { 946 Bounds b =new Bounds(965 return Main.downloadFromParamBounds(rawGps, new Bounds( 947 966 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())), 948 967 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())) 949 ); 950 Main.downloadFromParamBounds(rawGps, b); 968 )); 951 969 } 970 return Collections.emptyList(); 952 971 } 953 972 954 973 @Override 955 voiddownload(String param, Collection<File> fileList) {956 downloadFromParamBounds(false, param);974 List<Future<?>> download(String param, Collection<File> fileList) { 975 return downloadFromParamBounds(false, param); 957 976 } 958 977 959 978 @Override 960 voiddownloadGps(String param) {961 downloadFromParamBounds(true, param);979 List<Future<?>> downloadGps(String param) { 980 return downloadFromParamBounds(true, param); 962 981 } 963 982 }, fileName { 964 983 @Override 965 voiddownload(String s, Collection<File> fileList) {984 List<Future<?>> download(String s, Collection<File> fileList) { 966 985 fileList.add(new File(s)); 986 return Collections.emptyList(); 967 987 } 968 988 }; … … 972 992 * @param param represents the object to be downloaded 973 993 * @param fileList files which shall be opened, should be added to this collection 994 * @return the download task, or {@code null} 974 995 */ 975 abstract voiddownload(String param, Collection<File> fileList);996 abstract List<Future<?>> download(String param, Collection<File> fileList); 976 997 977 998 /** 978 999 * Performs the GPS download 979 1000 * @param param represents the object to be downloaded 1001 * @return the download task, or {@code null} 980 1002 */ 981 voiddownloadGps(String param) {1003 List<Future<?>> downloadGps(String param) { 982 1004 JOptionPane.showMessageDialog( 983 1005 Main.parent, … … 986 1008 JOptionPane.WARNING_MESSAGE 987 1009 ); 1010 return Collections.emptyList(); 988 1011 } 989 1012 … … 1008 1031 * @param rawGps Flag to download raw GPS tracks 1009 1032 * @param b The bounds value 1010 */ 1011 private static void downloadFromParamBounds(final boolean rawGps, Bounds b) { 1033 * @return the complete download task (including post-download handler) 1034 */ 1035 private static List<Future<?>> downloadFromParamBounds(final boolean rawGps, Bounds b) { 1012 1036 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 1013 1037 // asynchronously launch the download task ... 1014 1038 Future<?> future = task.download(true, b, null); 1015 1039 // ... and the continuation when the download is finished (this will wait for the download to finish) 1016 Main.worker.execute(new PostDownloadHandler(task, future));1040 return Collections.singletonList(Main.worker.submit(new PostDownloadHandler(task, future))); 1017 1041 } 1018 1042 -
trunk/src/org/openstreetmap/josm/actions/OpenFileAction.java
r11848 r11986 22 22 import java.util.List; 23 23 import java.util.Set; 24 import java.util.concurrent.Future; 24 25 import java.util.regex.Matcher; 25 26 import java.util.regex.Pattern; … … 84 85 * Filenames will not be saved in history. 85 86 * @param fileList A list of files 86 */ 87 public static void openFiles(List<File> fileList) { 88 openFiles(fileList, false); 87 * @return the future task 88 * @since 11986 (return task) 89 */ 90 public static Future<?> openFiles(List<File> fileList) { 91 return openFiles(fileList, false); 89 92 } 90 93 … … 93 96 * @param fileList A list of files 94 97 * @param recordHistory {@code true} to save filename in history (default: false) 95 */ 96 public static void openFiles(List<File> fileList, boolean recordHistory) { 98 * @return the future task 99 * @since 11986 (return task) 100 */ 101 public static Future<?> openFiles(List<File> fileList, boolean recordHistory) { 97 102 OpenFileTask task = new OpenFileTask(fileList, null); 98 103 task.setRecordHistory(recordHistory); 99 Main.worker.submit(task);104 return Main.worker.submit(task); 100 105 } 101 106 -
trunk/src/org/openstreetmap/josm/actions/OpenLocationAction.java
r11531 r11986 57 57 */ 58 58 private static final BooleanProperty USE_NEW_LAYER = new BooleanProperty("download.newlayer", false); 59 /** 60 * the list of download tasks 61 */ 59 62 protected final transient List<Class<? extends DownloadTask>> downloadTasks; 60 63 … … 200 203 * @param newLayer true if the URL needs to be opened in a new layer, false otherwise 201 204 * @param url The URL to open 202 */ 203 public void openUrl(boolean newLayer, String url) { 204 realOpenUrl(newLayer, url); 205 * @return the list of tasks that have been started successfully (can be empty). 206 * @since 11986 (return type) 207 */ 208 public List<Future<?>> openUrl(boolean newLayer, String url) { 209 return realOpenUrl(newLayer, url); 205 210 } 206 211 … … 208 213 * Open the given URL. This class checks the {@link #USE_NEW_LAYER} preference to check if a new layer should be used. 209 214 * @param url The URL to open 210 * @return <code>true</code> if at least one task was started successfully.211 * @since 11 279212 */ 213 public booleanopenUrl(String url) {215 * @return the list of tasks that have been started successfully (can be empty). 216 * @since 11986 (return type) 217 */ 218 public List<Future<?>> openUrl(String url) { 214 219 return realOpenUrl(USE_NEW_LAYER.get(), url); 215 220 } 216 221 217 private booleanrealOpenUrl(boolean newLayer, String url) {222 private List<Future<?>> realOpenUrl(boolean newLayer, String url) { 218 223 Collection<DownloadTask> tasks = findDownloadTasks(url, false); 219 224 … … 222 227 } else if (tasks.isEmpty()) { 223 228 warnNoSuitableTasks(url); 224 return false;229 return Collections.emptyList(); 225 230 } 226 231 227 232 PleaseWaitProgressMonitor monitor = new PleaseWaitProgressMonitor(tr("Download Data")); 228 233 229 boolean hadAnySuccess = false;234 List<Future<?>> result = new ArrayList<>(); 230 235 for (final DownloadTask task : tasks) { 231 236 try { 232 Future<?> future = task.loadUrl(newLayer, url, monitor); 233 Main.worker.submit(new PostDownloadHandler(task, future)); 234 hadAnySuccess = true; 237 result.add(Main.worker.submit(new PostDownloadHandler(task, task.loadUrl(newLayer, url, monitor)))); 235 238 } catch (IllegalArgumentException e) { 236 239 Main.error(e); 237 240 } 238 241 } 239 return hadAnySuccess;242 return result; 240 243 } 241 244 -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r11849 r11986 267 267 // 268 268 final OsmDataLayer layer = createNewLayer(newLayerName); 269 if (Main.main != null) 270 Main.getLayerManager().addLayer(layer, zoomAfterDownload); 269 Main.getLayerManager().addLayer(layer, zoomAfterDownload); 271 270 return layer; 272 271 } -
trunk/src/org/openstreetmap/josm/actions/search/SearchAction.java
r11978 r11986 10 10 import java.awt.Dimension; 11 11 import java.awt.FlowLayout; 12 import java.awt.GraphicsEnvironment; 12 13 import java.awt.GridBagLayout; 13 14 import java.awt.event.ActionEvent; … … 596 597 msg = null; 597 598 } 598 Main.map.statusLine.setHelpText(msg); 599 JOptionPane.showMessageDialog( 600 Main.parent, 601 msg, 602 tr("Warning"), 603 JOptionPane.WARNING_MESSAGE 604 ); 605 } else { 599 if (Main.map != null) { 600 Main.map.statusLine.setHelpText(msg); 601 } 602 if (!GraphicsEnvironment.isHeadless()) { 603 JOptionPane.showMessageDialog( 604 Main.parent, 605 msg, 606 tr("Warning"), 607 JOptionPane.WARNING_MESSAGE 608 ); 609 } 610 } else if (Main.map != null) { 606 611 Main.map.statusLine.setHelpText(tr("Found {0} matches", foundMatches)); 607 612 } -
trunk/src/org/openstreetmap/josm/gui/ProgramArguments.java
r11747 r11986 136 136 addOption(opt, g.getOptarg()); 137 137 } else 138 throw new IllegalArgumentException("Invalid option: "+ c);138 throw new IllegalArgumentException("Invalid option: "+ (char) c); 139 139 } 140 140 // positional arguments are a shortcut for the --download ... option -
trunk/src/org/openstreetmap/josm/gui/datatransfer/importers/OsmLinkPaster.java
r11713 r11986 51 51 52 52 String transferData = (String) support.getTransferable().getTransferData(df); 53 if ( new NoWarnOpenLocationAction().openUrl(transferData)) {53 if (!new NoWarnOpenLocationAction().openUrl(transferData).isEmpty()) { 54 54 return true; 55 55 }
Note:
See TracChangeset
for help on using the changeset viewer.