Changeset 806 in josm for trunk/src


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

Remember last download settings. Patch by Rainer Rothkegel.

Location:
trunk/src/org/openstreetmap/josm
Files:
2 edited

Legend:

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

    r627 r806  
    2424/**
    2525 * Main download dialog.
    26  * 
     26 *
    2727 * Can be extended by plugins in two ways:
    2828 * (1) by adding download tasks that are then called with the selected bounding box
    2929 * (2) by adding "DownloadSelection" objects that implement different ways of selecting a bounding box
    30  * 
     30 *
    3131 * @author Frederik Ramm <frederik@remote.org>
    3232 *
    3333 */
    3434public class DownloadDialog extends JPanel {
    35        
     35
    3636        // the JOptionPane that contains this dialog. required for the closeDialog() method.
    3737        private JOptionPane optionPane;
    38        
     38
    3939        public interface DownloadTask {
    4040                /**
     
    6363        public final JTabbedPane tabpane = new JTabbedPane();
    6464        public final JCheckBox newLayer;
    65        
     65
    6666        public double minlon;
    6767        public double minlat;
    6868        public double maxlon;
    6969        public double maxlat;
    70        
    71        
     70
     71
    7272        public DownloadDialog() {
    7373                setLayout(new GridBagLayout());
    74                
     74
    7575                downloadTasks.add(new DownloadOsmTask());
    7676                downloadTasks.add(new DownloadGpsTask());
    77                
     77
    7878                // adding the download tasks
    7979                add(new JLabel(tr("Data Sources and Types")), GBC.eol().insets(0,5,0,0));
     
    8585                        }
    8686                }
    87                
     87
    8888                // predefined download selections
    8989                downloadSelections.add(new BoundingBoxSelection());
    90                 downloadSelections.add(new BookmarkSelection());       
     90                downloadSelections.add(new BookmarkSelection());
    9191                downloadSelections.add(new WorldChooser());
    92                
     92
    9393                // add selections from plugins
    9494                for (PluginProxy p : Main.plugins) {
    9595                        p.addDownloadSelection(downloadSelections);
    9696                }
    97                
     97
    9898                // now everybody may add their tab to the tabbed pane
    9999                // (not done right away to allow plugins to remove one of
     
    102102                        s.addGui(this);
    103103                }
    104                
     104
    105105                if (Main.map != null) {
    106106                        MapView mv = Main.map.mapView;
     
    111111                        boundingBoxChanged(null);
    112112                }
     113                else if (Main.pref.hasKey("osm-download.bounds")) {
     114                        // read the bounding box from the preferences
     115                        try {
     116                                String bounds[] = Main.pref.get("osm-download.bounds").split(";");
     117                                minlat = Double.parseDouble(bounds[0]);
     118                                minlon = Double.parseDouble(bounds[1]);
     119                                maxlat = Double.parseDouble(bounds[2]);
     120                                maxlon = Double.parseDouble(bounds[3]);
     121                                boundingBoxChanged(null);
     122                        }
     123                        catch (Exception e) {
     124                                e.printStackTrace();
     125                        }
     126                }
    113127
    114128                newLayer = new JCheckBox(tr("Download as new layer"), Main.pref.getBoolean("download.newlayer", false));
     
    117131                add(new JLabel(tr("Download Area")), GBC.eol().insets(0,5,0,0));
    118132                add(tabpane, GBC.eol().fill());
    119                
     133
    120134                try {
    121135                        tabpane.setSelectedIndex(Integer.parseInt(Main.pref.get("download.tab", "0")));
     
    124138                }
    125139        }
    126        
     140
    127141        /**
    128          * Distributes a "bounding box changed" from one DownloadSelection 
    129          * object to the others, so they may update or clear their input 
     142         * Distributes a "bounding box changed" from one DownloadSelection
     143         * object to the others, so they may update or clear their input
    130144         * fields.
    131          * 
     145         *
    132146         * @param eventSource - the DownloadSelection object that fired this notification.
    133147         */
     
    135149                for (DownloadSelection s : downloadSelections) {
    136150                        if (s != eventSource) s.boundingBoxChanged(this);
    137                 }       
     151                }
    138152        }
    139153
     
    144158                return tabpane.getSelectedIndex();
    145159        }
    146        
     160
    147161        /**
    148162         * Closes the download dialog. This is intended to be called by one of
    149163         * the various download area selection "plugins".
    150          * 
     164         *
    151165         * @param download true to download selected data, false to cancel download
    152166         */
     
    160174         */
    161175        public void setOptionPane(JOptionPane optionPane) {
    162         this.optionPane = optionPane;
    163     }
     176                this.optionPane = optionPane;
     177        }
    164178}
  • 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.