Ignore:
Timestamp:
2011-10-16T23:59:38+02:00 (13 years ago)
Author:
Don-vip
Message:

fix #6960 - Download GPX traces with Ctrl+L

Location:
trunk/src/org/openstreetmap/josm/actions/downloadtasks
Files:
3 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java

    r4334 r4521  
    99import org.openstreetmap.josm.Main;
    1010import org.openstreetmap.josm.data.Bounds;
     11import org.openstreetmap.josm.data.Bounds.ParseMethod;
    1112import org.openstreetmap.josm.data.gpx.GpxData;
    1213import org.openstreetmap.josm.gui.PleaseWaitRunnable;
     
    1516import org.openstreetmap.josm.gui.progress.ProgressMonitor;
    1617import org.openstreetmap.josm.io.BoundingBoxDownloader;
     18import org.openstreetmap.josm.io.OsmServerLocationReader;
     19import org.openstreetmap.josm.io.OsmServerReader;
    1720import org.openstreetmap.josm.io.OsmTransferException;
    1821import org.xml.sax.SAXException;
     
    2124
    2225    private DownloadTask downloadTask;
     26   
     27    private static final String PATTERN_TRACE_ID = "http://.*openstreetmap.org/trace/\\p{Digit}+/data";
     28   
     29    private static final String PATTERN_TRACKPOINTS_BBOX = "http://.*/api/0.6/trackpoints\\?bbox=.*,.*,.*,.*";
    2330
    2431    public Future<?> download(boolean newLayer, Bounds downloadArea, ProgressMonitor progressMonitor) {
     
    3037    }
    3138
    32     public Future<?> loadUrl(boolean a,java.lang.String b,  ProgressMonitor progressMonitor) {
     39    public Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor) {
     40        if (url != null && url.matches(PATTERN_TRACE_ID)) {
     41            downloadTask = new DownloadTask(newLayer,
     42                    new OsmServerLocationReader(url), progressMonitor);
     43            // We need submit instead of execute so we can wait for it to finish and get the error
     44            // message if necessary. If no one calls getErrorMessage() it just behaves like execute.
     45            return Main.worker.submit(downloadTask);
     46           
     47        } else if (url != null && url.matches(PATTERN_TRACKPOINTS_BBOX)) {
     48            String[] table = url.split("\\?|=|&");
     49            for (int i = 0; i<table.length; i++) {
     50                if (table[i].equals("bbox") && i<table.length-1 ) {
     51                    return download(newLayer, new Bounds(table[i+1], ",", ParseMethod.LEFT_BOTTOM_RIGHT_TOP), progressMonitor);
     52                }
     53            }
     54        }
    3355        return null;
    34         // FIXME this is not currently used
     56    }
     57
     58    /* (non-Javadoc)
     59     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String)
     60     */
     61    @Override
     62    public boolean acceptsUrl(String url) {
     63        return url != null && (url.matches(PATTERN_TRACE_ID) || url.matches(PATTERN_TRACKPOINTS_BBOX));
    3564    }
    3665
     
    4271
    4372    class DownloadTask extends PleaseWaitRunnable {
    44         private BoundingBoxDownloader reader;
     73        private OsmServerReader reader;
    4574        private GpxData rawData;
    4675        private final boolean newLayer;
    4776
    48         public DownloadTask(boolean newLayer, BoundingBoxDownloader reader, ProgressMonitor progressMonitor) {
     77        public DownloadTask(boolean newLayer, OsmServerReader reader, ProgressMonitor progressMonitor) {
    4978            super(tr("Downloading GPS data"));
    5079            this.reader = reader;
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java

    r4310 r4521  
    6464        return Main.worker.submit(downloadTask);
    6565    }
     66   
     67    /* (non-Javadoc)
     68     * @see org.openstreetmap.josm.actions.downloadtasks.DownloadTask#acceptsUrl(java.lang.String)
     69     */
     70    @Override
     71    public boolean acceptsUrl(String url) {
     72        return url != null && url.matches("http://.*/api/0.6/(map|nodes?|ways?|relations?).*");
     73    }
    6674
    6775    public void cancel() {
  • trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadTask.java

    r3083 r4521  
    6565     */
    6666    Future<?> loadUrl(boolean newLayer, String url, ProgressMonitor progressMonitor);
     67   
     68    /**
     69     * Returns true if the task is able to open the given URL, false otherwise.
     70     * @param url the url to download from
     71     * @return True if the task is able to open the given URL, false otherwise.
     72     */
     73    boolean acceptsUrl(String url);
    6774
    6875    /**
Note: See TracChangeset for help on using the changeset viewer.