Ignore:
Timestamp:
2008-08-18T12:12:40+02:00 (17 years ago)
Author:
stoecker
Message:

Remember last download settings. Patch by Rainer Rothkegel.

File:
1 edited

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java

    r769 r806  
    1919
    2020        /**
    21     * The boundings of the desired map data.
    22     */
    23     private final double lat1;
     21        * The boundings of the desired map data.
     22        */
     23        private final double lat1;
    2424        private final double lon1;
    2525        private final double lat2;
     
    3131                this.lat2 = lat2;
    3232                this.lon2 = lon2;
    33     }
     33                // store the bounding box in the preferences so it can be
     34                // re-used across invocations of josm
     35                Main.pref.put("osm-download.bounds", lat1+";"+lon1+";"+lat2+";"+lon2);
     36        }
    3437
    3538        /**
    36     * Retrieve raw gps waypoints from the server API.
    37     * @return A list of all primitives retrieved. Currently, the list of lists
    38      *          contain only one list, since the server cannot distinguish between
    39      *          ways.
    40     */
     39        * Retrieve raw gps waypoints from the server API.
     40        * @return A list of all primitives retrieved. Currently, the list of lists
     41         *      contain only one list, since the server cannot distinguish between
     42         *      ways.
     43        */
    4144        public GpxData parseRawGps() throws IOException, SAXException {
    4245                Main.pleaseWaitDlg.progress.setValue(0);
    4346                Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
    44         try {
    45                 String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";
     47                try {
     48                        String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=";
    4649
    4750                        boolean done = false;
    4851                        GpxData result = null;
    4952                        for (int i = 0;!done;++i) {
    50                         Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));
    51                         InputStream in = getInputStream(url+i, Main.pleaseWaitDlg);
    52                         if (in == null)
    53                                 break;
     53                                Main.pleaseWaitDlg.currentAction.setText(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000)));
     54                                InputStream in = getInputStream(url+i, Main.pleaseWaitDlg);
     55                                if (in == null)
     56                                        break;
    5457                                GpxData currentGpx = new GpxReader(in, null).data;
    5558                                if (result == null) {
     
    5962                                } else{
    6063                                        done = true;
    61                         }
    62                         in.close();
    63                         activeConnection = null;
    64                 }
     64                                }
     65                                in.close();
     66                                activeConnection = null;
     67                        }
    6568                        result.fromServer = true;
    6669                        return result;
    67         } catch (IllegalArgumentException e) {
    68                 // caused by HttpUrlConnection in case of illegal stuff in the response
    69                 if (cancel)
    70                         return null;
    71                 throw new SAXException("Illegal characters within the HTTP-header response", e);
    72         } catch (IOException e) {
    73                 if (cancel)
    74                         return null;
    75                 throw e;
    76         } catch (SAXException e) {
    77                 throw e;
    78         } catch (Exception e) {
    79                 if (cancel)
    80                         return null;
    81                 if (e instanceof RuntimeException)
    82                         throw (RuntimeException)e;
    83                 throw new RuntimeException(e);
    84         }
    85     }
     70                } catch (IllegalArgumentException e) {
     71                        // caused by HttpUrlConnection in case of illegal stuff in the response
     72                        if (cancel)
     73                                return null;
     74                        throw new SAXException("Illegal characters within the HTTP-header response", e);
     75                } catch (IOException e) {
     76                        if (cancel)
     77                                return null;
     78                        throw e;
     79                } catch (SAXException e) {
     80                        throw e;
     81                } catch (Exception e) {
     82                        if (cancel)
     83                                return null;
     84                        if (e instanceof RuntimeException)
     85                                throw (RuntimeException)e;
     86                        throw new RuntimeException(e);
     87                }
     88        }
    8689
    8790        /**
    88     * Read the data from the osm server address.
    89     * @return A data set containing all data retrieved from that url
    90     */
    91     public DataSet parseOsm() throws SAXException, IOException {
    92         try {
     91        * Read the data from the osm server address.
     92        * @return A data set containing all data retrieved from that url
     93        */
     94        public DataSet parseOsm() throws SAXException, IOException {
     95                try {
    9396                        Main.pleaseWaitDlg.progress.setValue(0);
    94                 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
    95                 final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg);
    96                 if (in == null)
    97                         return null;
    98                 Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
    99                 final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg);
    100             /*
    101              * We're not doing this here anymore as the API now properly sets a bounds element
    102              * which will get parsed.
    103                 String origin = Main.pref.get("osm-server.url")+"/"+Main.pref.get("osm-server.version", "0.5");
    104                 Bounds bounds = new Bounds(new LatLon(lat1, lon1), new LatLon(lat2, lon2));
    105                         DataSource src = new DataSource(bounds, origin);
    106                 data.dataSources.add(src);
    107              */
    108                 in.close();
    109                 activeConnection = null;
    110                 return data;
    111         } catch (IOException e) {
    112                 if (cancel)
    113                         return null;
    114                 throw e;
    115         } catch (SAXException e) {
    116                 throw e;
    117         } catch (Exception e) {
    118                 if (cancel)
    119                         return null;
    120                 if (e instanceof RuntimeException)
    121                         throw (RuntimeException)e;
    122                 throw new RuntimeException(e);
    123         }
    124     }
     97                        Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server..."));
     98                        final InputStream in = getInputStream("map?bbox="+lon1+","+lat1+","+lon2+","+lat2, Main.pleaseWaitDlg);
     99                        if (in == null)
     100                                return null;
     101                        Main.pleaseWaitDlg.currentAction.setText(tr("Downloading OSM data..."));
     102                        final DataSet data = OsmReader.parseDataSet(in, null, Main.pleaseWaitDlg);
     103                        in.close();
     104                        activeConnection = null;
     105                        return data;
     106                } catch (IOException e) {
     107                        if (cancel)
     108                                return null;
     109                        throw e;
     110                } catch (SAXException e) {
     111                        throw e;
     112                } catch (Exception e) {
     113                        if (cancel)
     114                                return null;
     115                        if (e instanceof RuntimeException)
     116                                throw (RuntimeException)e;
     117                        throw new RuntimeException(e);
     118                }
     119        }
    125120}
Note: See TracChangeset for help on using the changeset viewer.