Changeset 12633 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-08-24T12:09:39+02:00 (7 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/Main.java
r12631 r12633 6 6 import java.awt.Component; 7 7 import java.awt.GraphicsEnvironment; 8 import java.io.File;9 8 import java.io.IOException; 10 9 import java.lang.ref.WeakReference; 11 import java.net.URI;12 import java.net.URISyntaxException;13 10 import java.net.URL; 14 11 import java.text.MessageFormat; … … 25 22 import java.util.Objects; 26 23 import java.util.Set; 27 import java.util.StringTokenizer;28 24 import java.util.concurrent.Callable; 29 25 import java.util.concurrent.ExecutionException; … … 35 31 import javax.swing.InputMap; 36 32 import javax.swing.JComponent; 37 import javax.swing.JOptionPane;38 33 import javax.swing.KeyStroke; 39 34 import javax.swing.LookAndFeel; … … 42 37 43 38 import org.openstreetmap.josm.actions.JosmAction; 44 import org.openstreetmap.josm.actions.OpenFileAction;45 import org.openstreetmap.josm.actions.OpenLocationAction;46 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;47 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;48 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;49 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;50 39 import org.openstreetmap.josm.actions.mapmode.DrawAction; 51 import org.openstreetmap.josm.actions.search.SearchAction;52 40 import org.openstreetmap.josm.data.Bounds; 53 41 import org.openstreetmap.josm.data.Preferences; … … 55 43 import org.openstreetmap.josm.data.cache.JCSCacheManager; 56 44 import org.openstreetmap.josm.data.coor.CoordinateFormat; 57 import org.openstreetmap.josm.data.coor.LatLon;58 45 import org.openstreetmap.josm.data.osm.DataSet; 59 46 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 65 52 import org.openstreetmap.josm.gui.MapFrame; 66 53 import org.openstreetmap.josm.gui.MapFrameListener; 67 import org.openstreetmap.josm.gui.ProgramArguments;68 import org.openstreetmap.josm.gui.ProgramArguments.Option;69 54 import org.openstreetmap.josm.gui.io.SaveLayersDialog; 70 55 import org.openstreetmap.josm.gui.layer.MainLayerManager; … … 86 71 import org.openstreetmap.josm.tools.JosmRuntimeException; 87 72 import org.openstreetmap.josm.tools.Logging; 88 import org.openstreetmap.josm.tools.OsmUrlToBounds;89 73 import org.openstreetmap.josm.tools.PlatformHook; 90 74 import org.openstreetmap.josm.tools.PlatformHookOsx; … … 841 825 842 826 /** 843 * Handle command line instructions after GUI has been initialized.844 * @param args program arguments845 * @return the list of submitted tasks846 */847 protected static List<Future<?>> postConstructorProcessCmdLine(ProgramArguments args) {848 List<Future<?>> tasks = new ArrayList<>();849 List<File> fileList = new ArrayList<>();850 for (String s : args.get(Option.DOWNLOAD)) {851 tasks.addAll(DownloadParamType.paramType(s).download(s, fileList));852 }853 if (!fileList.isEmpty()) {854 tasks.add(OpenFileAction.openFiles(fileList, true));855 }856 for (String s : args.get(Option.DOWNLOADGPS)) {857 tasks.addAll(DownloadParamType.paramType(s).downloadGps(s));858 }859 final Collection<String> selectionArguments = args.get(Option.SELECTION);860 if (!selectionArguments.isEmpty()) {861 tasks.add(Main.worker.submit(() -> {862 for (String s : selectionArguments) {863 SearchAction.search(s, SearchAction.SearchMode.add);864 }865 }));866 }867 return tasks;868 }869 870 /**871 827 * Closes JOSM and optionally terminates the Java Virtual Machine (JVM). 872 828 * If there are some unsaved data layers, asks first for user confirmation. … … 914 870 ImageProvider.shutdown(true); 915 871 } 916 }917 918 /**919 * The type of a command line parameter, to be used in switch statements.920 * @see #paramType921 */922 enum DownloadParamType {923 httpUrl {924 @Override925 List<Future<?>> download(String s, Collection<File> fileList) {926 return new OpenLocationAction().openUrl(false, s);927 }928 929 @Override930 List<Future<?>> downloadGps(String s) {931 final Bounds b = OsmUrlToBounds.parse(s);932 if (b == null) {933 JOptionPane.showMessageDialog(934 Main.parent,935 tr("Ignoring malformed URL: \"{0}\"", s),936 tr("Warning"),937 JOptionPane.WARNING_MESSAGE938 );939 return Collections.emptyList();940 }941 return downloadFromParamBounds(true, b);942 }943 }, fileUrl {944 @Override945 List<Future<?>> download(String s, Collection<File> fileList) {946 File f = null;947 try {948 f = new File(new URI(s));949 } catch (URISyntaxException e) {950 Logging.warn(e);951 JOptionPane.showMessageDialog(952 Main.parent,953 tr("Ignoring malformed file URL: \"{0}\"", s),954 tr("Warning"),955 JOptionPane.WARNING_MESSAGE956 );957 }958 if (f != null) {959 fileList.add(f);960 }961 return Collections.emptyList();962 }963 }, bounds {964 965 /**966 * Download area specified on the command line as bounds string.967 * @param rawGps Flag to download raw GPS tracks968 * @param s The bounds parameter969 * @return the complete download task (including post-download handler), or {@code null}970 */971 private List<Future<?>> downloadFromParamBounds(final boolean rawGps, String s) {972 final StringTokenizer st = new StringTokenizer(s, ",");973 if (st.countTokens() == 4) {974 return Main.downloadFromParamBounds(rawGps, new Bounds(975 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken())),976 new LatLon(Double.parseDouble(st.nextToken()), Double.parseDouble(st.nextToken()))977 ));978 }979 return Collections.emptyList();980 }981 982 @Override983 List<Future<?>> download(String param, Collection<File> fileList) {984 return downloadFromParamBounds(false, param);985 }986 987 @Override988 List<Future<?>> downloadGps(String param) {989 return downloadFromParamBounds(true, param);990 }991 }, fileName {992 @Override993 List<Future<?>> download(String s, Collection<File> fileList) {994 fileList.add(new File(s));995 return Collections.emptyList();996 }997 };998 999 /**1000 * Performs the download1001 * @param param represents the object to be downloaded1002 * @param fileList files which shall be opened, should be added to this collection1003 * @return the download task, or {@code null}1004 */1005 abstract List<Future<?>> download(String param, Collection<File> fileList);1006 1007 /**1008 * Performs the GPS download1009 * @param param represents the object to be downloaded1010 * @return the download task, or {@code null}1011 */1012 List<Future<?>> downloadGps(String param) {1013 if (!GraphicsEnvironment.isHeadless()) {1014 JOptionPane.showMessageDialog(1015 Main.parent,1016 tr("Parameter \"downloadgps\" does not accept file names or file URLs"),1017 tr("Warning"),1018 JOptionPane.WARNING_MESSAGE1019 );1020 }1021 return Collections.emptyList();1022 }1023 1024 /**1025 * Guess the type of a parameter string specified on the command line with --download= or --downloadgps.1026 *1027 * @param s A parameter string1028 * @return The guessed parameter type1029 */1030 static DownloadParamType paramType(String s) {1031 if (s.startsWith("http:") || s.startsWith("https:")) return DownloadParamType.httpUrl;1032 if (s.startsWith("file:")) return DownloadParamType.fileUrl;1033 String coorPattern = "\\s*[+-]?[0-9]+(\\.[0-9]+)?\\s*";1034 if (s.matches(coorPattern + "(," + coorPattern + "){3}")) return DownloadParamType.bounds;1035 // everything else must be a file name1036 return DownloadParamType.fileName;1037 }1038 }1039 1040 /**1041 * Download area specified as Bounds value.1042 * @param rawGps Flag to download raw GPS tracks1043 * @param b The bounds value1044 * @return the complete download task (including post-download handler)1045 */1046 private static List<Future<?>> downloadFromParamBounds(final boolean rawGps, Bounds b) {1047 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask();1048 // asynchronously launch the download task ...1049 Future<?> future = task.download(true, b, null);1050 // ... and the continuation when the download is finished (this will wait for the download to finish)1051 return Collections.singletonList(Main.worker.submit(new PostDownloadHandler(task, future)));1052 872 } 1053 873 -
trunk/src/org/openstreetmap/josm/gui/MainApplication.java
r12631 r12633 36 36 import java.util.TreeSet; 37 37 import java.util.concurrent.Callable; 38 import java.util.concurrent.Future; 38 39 import java.util.logging.Level; 39 40 import java.util.stream.Collectors; … … 49 50 import org.openstreetmap.gui.jmapviewer.FeatureAdapter; 50 51 import org.openstreetmap.josm.Main; 52 import org.openstreetmap.josm.actions.OpenFileAction; 51 53 import org.openstreetmap.josm.actions.PreferencesAction; 52 54 import org.openstreetmap.josm.actions.RestartAction; 55 import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask; 56 import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask; 57 import org.openstreetmap.josm.actions.downloadtasks.DownloadTask; 58 import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler; 53 59 import org.openstreetmap.josm.actions.mapmode.DrawAction; 60 import org.openstreetmap.josm.actions.search.SearchAction; 54 61 import org.openstreetmap.josm.data.AutosaveTask; 55 62 import org.openstreetmap.josm.data.Bounds; … … 653 660 } 654 661 662 /** 663 * Download area specified as Bounds value. 664 * @param rawGps Flag to download raw GPS tracks 665 * @param b The bounds value 666 * @return the complete download task (including post-download handler) 667 */ 668 static List<Future<?>> downloadFromParamBounds(final boolean rawGps, Bounds b) { 669 DownloadTask task = rawGps ? new DownloadGpsTask() : new DownloadOsmTask(); 670 // asynchronously launch the download task ... 671 Future<?> future = task.download(true, b, null); 672 // ... and the continuation when the download is finished (this will wait for the download to finish) 673 return Collections.singletonList(Main.worker.submit(new PostDownloadHandler(task, future))); 674 } 675 676 /** 677 * Handle command line instructions after GUI has been initialized. 678 * @param args program arguments 679 * @return the list of submitted tasks 680 */ 681 static List<Future<?>> postConstructorProcessCmdLine(ProgramArguments args) { 682 List<Future<?>> tasks = new ArrayList<>(); 683 List<File> fileList = new ArrayList<>(); 684 for (String s : args.get(Option.DOWNLOAD)) { 685 tasks.addAll(DownloadParamType.paramType(s).download(s, fileList)); 686 } 687 if (!fileList.isEmpty()) { 688 tasks.add(OpenFileAction.openFiles(fileList, true)); 689 } 690 for (String s : args.get(Option.DOWNLOADGPS)) { 691 tasks.addAll(DownloadParamType.paramType(s).downloadGps(s)); 692 } 693 final Collection<String> selectionArguments = args.get(Option.SELECTION); 694 if (!selectionArguments.isEmpty()) { 695 tasks.add(Main.worker.submit(() -> { 696 for (String s : selectionArguments) { 697 SearchAction.search(s, SearchAction.SearchMode.add); 698 } 699 })); 700 } 701 return tasks; 702 } 703 655 704 private static class GuiFinalizationWorker implements Runnable { 656 705 -
trunk/src/org/openstreetmap/josm/gui/ProgramArguments.java
r11986 r12633 20 20 21 21 /** 22 * This class holds the arguments passed on to Main.22 * This class holds the arguments passed on to {@link MainApplication#main}. 23 23 * @author Michael Zangl 24 24 * @since 10899
Note:
See TracChangeset
for help on using the changeset viewer.