Ignore:
Timestamp:
2017-08-24T12:09:39+02:00 (4 years ago)
Author:
Don-vip
Message:

see #15182 - move GUI program arguments management from Main to gui.MainApplication

Location:
trunk/src/org/openstreetmap/josm/gui
Files:
1 added
2 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/gui/MainApplication.java

    r12631 r12633  
    3636import java.util.TreeSet;
    3737import java.util.concurrent.Callable;
     38import java.util.concurrent.Future;
    3839import java.util.logging.Level;
    3940import java.util.stream.Collectors;
     
    4950import org.openstreetmap.gui.jmapviewer.FeatureAdapter;
    5051import org.openstreetmap.josm.Main;
     52import org.openstreetmap.josm.actions.OpenFileAction;
    5153import org.openstreetmap.josm.actions.PreferencesAction;
    5254import org.openstreetmap.josm.actions.RestartAction;
     55import org.openstreetmap.josm.actions.downloadtasks.DownloadGpsTask;
     56import org.openstreetmap.josm.actions.downloadtasks.DownloadOsmTask;
     57import org.openstreetmap.josm.actions.downloadtasks.DownloadTask;
     58import org.openstreetmap.josm.actions.downloadtasks.PostDownloadHandler;
    5359import org.openstreetmap.josm.actions.mapmode.DrawAction;
     60import org.openstreetmap.josm.actions.search.SearchAction;
    5461import org.openstreetmap.josm.data.AutosaveTask;
    5562import org.openstreetmap.josm.data.Bounds;
     
    653660    }
    654661
     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
    655704    private static class GuiFinalizationWorker implements Runnable {
    656705
  • trunk/src/org/openstreetmap/josm/gui/ProgramArguments.java

    r11986 r12633  
    2020
    2121/**
    22  * This class holds the arguments passed on to Main.
     22 * This class holds the arguments passed on to {@link MainApplication#main}.
    2323 * @author Michael Zangl
    2424 * @since 10899
Note: See TracChangeset for help on using the changeset viewer.