Changeset 806 in josm
- Timestamp:
- 2008-08-18T12:12:40+02:00 (16 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 2 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/download/DownloadDialog.java
r627 r806 24 24 /** 25 25 * Main download dialog. 26 * 26 * 27 27 * Can be extended by plugins in two ways: 28 28 * (1) by adding download tasks that are then called with the selected bounding box 29 29 * (2) by adding "DownloadSelection" objects that implement different ways of selecting a bounding box 30 * 30 * 31 31 * @author Frederik Ramm <frederik@remote.org> 32 32 * 33 33 */ 34 34 public class DownloadDialog extends JPanel { 35 35 36 36 // the JOptionPane that contains this dialog. required for the closeDialog() method. 37 37 private JOptionPane optionPane; 38 38 39 39 public interface DownloadTask { 40 40 /** … … 63 63 public final JTabbedPane tabpane = new JTabbedPane(); 64 64 public final JCheckBox newLayer; 65 65 66 66 public double minlon; 67 67 public double minlat; 68 68 public double maxlon; 69 69 public double maxlat; 70 71 70 71 72 72 public DownloadDialog() { 73 73 setLayout(new GridBagLayout()); 74 74 75 75 downloadTasks.add(new DownloadOsmTask()); 76 76 downloadTasks.add(new DownloadGpsTask()); 77 77 78 78 // adding the download tasks 79 79 add(new JLabel(tr("Data Sources and Types")), GBC.eol().insets(0,5,0,0)); … … 85 85 } 86 86 } 87 87 88 88 // predefined download selections 89 89 downloadSelections.add(new BoundingBoxSelection()); 90 downloadSelections.add(new BookmarkSelection()); 90 downloadSelections.add(new BookmarkSelection()); 91 91 downloadSelections.add(new WorldChooser()); 92 92 93 93 // add selections from plugins 94 94 for (PluginProxy p : Main.plugins) { 95 95 p.addDownloadSelection(downloadSelections); 96 96 } 97 97 98 98 // now everybody may add their tab to the tabbed pane 99 99 // (not done right away to allow plugins to remove one of … … 102 102 s.addGui(this); 103 103 } 104 104 105 105 if (Main.map != null) { 106 106 MapView mv = Main.map.mapView; … … 111 111 boundingBoxChanged(null); 112 112 } 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 } 113 127 114 128 newLayer = new JCheckBox(tr("Download as new layer"), Main.pref.getBoolean("download.newlayer", false)); … … 117 131 add(new JLabel(tr("Download Area")), GBC.eol().insets(0,5,0,0)); 118 132 add(tabpane, GBC.eol().fill()); 119 133 120 134 try { 121 135 tabpane.setSelectedIndex(Integer.parseInt(Main.pref.get("download.tab", "0"))); … … 124 138 } 125 139 } 126 140 127 141 /** 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 130 144 * fields. 131 * 145 * 132 146 * @param eventSource - the DownloadSelection object that fired this notification. 133 147 */ … … 135 149 for (DownloadSelection s : downloadSelections) { 136 150 if (s != eventSource) s.boundingBoxChanged(this); 137 } 151 } 138 152 } 139 153 … … 144 158 return tabpane.getSelectedIndex(); 145 159 } 146 160 147 161 /** 148 162 * Closes the download dialog. This is intended to be called by one of 149 163 * the various download area selection "plugins". 150 * 164 * 151 165 * @param download true to download selected data, false to cancel download 152 166 */ … … 160 174 */ 161 175 public void setOptionPane(JOptionPane optionPane) { 162 163 176 this.optionPane = optionPane; 177 } 164 178 } -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r769 r806 19 19 20 20 /** 21 22 23 21 * The boundings of the desired map data. 22 */ 23 private final double lat1; 24 24 private final double lon1; 25 25 private final double lat2; … … 31 31 this.lat2 = lat2; 32 32 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 } 34 37 35 38 /** 36 37 38 *contain only one list, since the server cannot distinguish between39 *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 */ 41 44 public GpxData parseRawGps() throws IOException, SAXException { 42 45 Main.pleaseWaitDlg.progress.setValue(0); 43 46 Main.pleaseWaitDlg.currentAction.setText(tr("Contacting OSM Server...")); 44 45 47 try { 48 String url = "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page="; 46 49 47 50 boolean done = false; 48 51 GpxData result = null; 49 52 for (int i = 0;!done;++i) { 50 51 52 53 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; 54 57 GpxData currentGpx = new GpxReader(in, null).data; 55 58 if (result == null) { … … 59 62 } else{ 60 63 done = true; 61 62 63 64 64 } 65 in.close(); 66 activeConnection = null; 67 } 65 68 result.fromServer = true; 66 69 return result; 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 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 } 86 89 87 90 /** 88 89 90 91 92 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 { 93 96 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 } 125 120 }
Note:
See TracChangeset
for help on using the changeset viewer.