Changeset 2717 in josm
- Timestamp:
- 2009-12-31T00:49:20+01:00 (15 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/data/Bounds.java
r2686 r2717 5 5 6 6 import java.awt.geom.Rectangle2D; 7 import java.text.DecimalFormat; 7 8 8 9 import org.openstreetmap.josm.data.coor.LatLon; … … 126 127 } 127 128 129 public String toShortString(DecimalFormat format) { 130 return 131 format.format(min.lat()) + " " 132 + format.format(min.lon()) + " / " 133 + format.format(max.lat()) + " " 134 + format.format(max.lon()); 135 } 136 128 137 /** 129 138 * @return Center of the bounding box. -
trunk/src/org/openstreetmap/josm/gui/download/PlaceSelection.java
r2676 r2717 2 2 3 3 import static org.openstreetmap.josm.tools.I18n.tr; 4 import static org.openstreetmap.josm.tools.I18n.trc; 4 5 5 6 import java.awt.BorderLayout; 6 7 import java.awt.Component; 7 8 import java.awt.Dimension; 8 import java.awt.GridBagConstraints;9 9 import java.awt.GridBagLayout; 10 import java.awt.GridLayout; 10 11 import java.awt.Insets; 11 12 import java.awt.event.ActionEvent; … … 17 18 import java.net.HttpURLConnection; 18 19 import java.net.URL; 20 import java.text.DecimalFormat; 19 21 import java.util.ArrayList; 20 22 import java.util.Collections; … … 27 29 import javax.swing.DefaultListSelectionModel; 28 30 import javax.swing.JButton; 31 import javax.swing.JComboBox; 29 32 import javax.swing.JLabel; 30 33 import javax.swing.JPanel; … … 51 54 import org.openstreetmap.josm.gui.widgets.HistoryComboBox; 52 55 import org.openstreetmap.josm.io.OsmTransferException; 56 import org.openstreetmap.josm.tools.GBC; 53 57 import org.openstreetmap.josm.tools.ImageProvider; 58 import org.openstreetmap.josm.tools.OsmUrlToBounds; 54 59 import org.xml.sax.Attributes; 55 60 import org.xml.sax.InputSource; … … 63 68 private JButton btnSearch; 64 69 private NamedResultTableModel model; 70 private NamedResultTableColumnModel columnmodel; 65 71 private JTable tblSearchResults; 66 72 private DownloadDialog parent; 73 private final static Server[] servers = new Server[]{ 74 new Server("Nominatim","http://nominatim.openstreetmap.org/search?format=xml&q=",tr("Class Type"),tr("Bounds")), 75 new Server("Gazetter","http://gazetteer.openstreetmap.org/namefinder/search.xml?find=",tr("Near"),trc("placeselection", "Zoom")) 76 }; 77 private final JComboBox server = new JComboBox(servers); 78 79 private static class Server { 80 public String name; 81 public String url; 82 public String thirdcol; 83 public String fourthcol; 84 public String toString() { 85 return name; 86 } 87 public Server(String n, String u, String t, String f) { 88 name = n; 89 url = u; 90 thirdcol = t; 91 fourthcol = f; 92 } 93 } 67 94 68 95 protected JPanel buildSearchPanel() { 96 JPanel lpanel = new JPanel(); 97 lpanel.setLayout(new GridLayout(2,2)); 69 98 JPanel panel = new JPanel(); 70 99 panel.setLayout(new GridBagLayout()); 71 GridBagConstraints gc = new GridBagConstraints(); 72 73 // the label for the search field 74 // 75 gc.gridwidth = 2; 76 gc.fill = GridBagConstraints.HORIZONTAL; 77 gc.weightx =1.0; 78 gc.insets = new Insets(5, 5, 0, 5); 79 panel.add(new JLabel(tr("Enter a place name to search for:")), gc); 80 81 // the search expression field 82 // 100 101 lpanel.add(new JLabel(tr("Choose the server for searching:"))); 102 lpanel.add(server); 103 String s = Main.pref.get("namefinder.server", servers[0].name); 104 for(int i = 0; i < servers.length; ++i) { 105 if(servers[i].name.equals(s)) 106 server.setSelectedIndex(i); 107 } 108 lpanel.add(new JLabel(tr("Enter a place name to search for:"))); 109 83 110 cbSearchExpression = new HistoryComboBox(); 84 111 cbSearchExpression.setToolTipText(tr("Enter a place name to search for")); … … 86 113 Collections.reverse(cmtHistory); 87 114 cbSearchExpression.setPossibleItems(cmtHistory); 88 gc.gridx = 0; 89 gc.gridy = 1; 90 gc.gridwidth = 1; 91 panel.add(cbSearchExpression, gc); 92 93 // the search button 94 // 115 lpanel.add(cbSearchExpression); 116 117 panel.add(lpanel, GBC.std().fill(GBC.HORIZONTAL).insets(5, 5, 0, 5)); 95 118 SearchAction searchAction = new SearchAction(); 96 119 btnSearch = new JButton(searchAction); … … 98 121 ((JTextField)cbSearchExpression.getEditor().getEditorComponent()).addActionListener(searchAction); 99 122 100 gc.gridx = 1; 101 gc.gridy = 1; 102 gc.fill = GridBagConstraints.HORIZONTAL; 103 gc.weightx = 0.0; 104 panel.add(btnSearch, gc); 123 panel.add(btnSearch, GBC.eol().insets(5, 5, 0, 5)); 105 124 106 125 return panel; … … 119 138 DefaultListSelectionModel selectionModel = new DefaultListSelectionModel(); 120 139 model = new NamedResultTableModel(selectionModel); 121 tblSearchResults = new JTable(model, new NamedResultTableColumnModel()); 140 columnmodel = new NamedResultTableColumnModel(); 141 tblSearchResults = new JTable(model, columnmodel); 122 142 tblSearchResults.setSelectionModel(selectionModel); 123 143 JScrollPane scrollPane = new JScrollPane(tblSearchResults); … … 156 176 public double lat; 157 177 public double lon; 158 public int zoom; 178 public int zoom = 0; 179 public Bounds bounds = null; 159 180 160 181 public Bounds getDownloadArea() { 161 double size = 180.0 / Math.pow(2, zoom); 162 Bounds b = new Bounds( 163 new LatLon(lat - size / 2, lon - size), 164 new LatLon(lat + size / 2, lon+ size) 165 ); 166 return b; 182 return bounds != null ? bounds : OsmUrlToBounds.positionToBounds(lat, lon, zoom); 167 183 } 168 184 } … … 194 210 currentResult.name = atts.getValue("name"); 195 211 currentResult.info = atts.getValue("info"); 212 if(currentResult.info != null) 213 currentResult.info = tr(currentResult.info); 196 214 currentResult.lat = Double.parseDouble(atts.getValue("lat")); 197 215 currentResult.lon = Double.parseDouble(atts.getValue("lon")); 198 216 currentResult.zoom = Integer.parseInt(atts.getValue("zoom")); 199 //currentResult.osmId = Integer.parseInt(atts.getValue("id"));200 //currentResult.type = OsmPrimitiveType.from(atts.getValue("type"));201 217 data.add(currentResult); 202 218 } else if (qName.equals("description") && (depth == 3)) { … … 208 224 currentResult.nearestPlace = atts.getValue("name"); 209 225 } 226 } else if (qName.equals("place")) { 227 currentResult = new PlaceSelection.SearchResult(); 228 currentResult.name = atts.getValue("display_name"); 229 currentResult.description = currentResult.name; 230 currentResult.info = tr(atts.getValue("class")); 231 currentResult.nearestPlace = tr(atts.getValue("type")); 232 currentResult.lat = Double.parseDouble(atts.getValue("lat")); 233 currentResult.lon = Double.parseDouble(atts.getValue("lon")); 234 String[] bbox = atts.getValue("boundingbox").split(","); 235 currentResult.bounds = new Bounds( 236 new LatLon(Double.parseDouble(bbox[0]), Double.parseDouble(bbox[2])), 237 new LatLon(Double.parseDouble(bbox[1]), Double.parseDouble(bbox[3]))); 238 data.add(currentResult); 210 239 } 211 240 } catch (NumberFormatException x) { … … 288 317 private List<SearchResult> data; 289 318 private boolean canceled = false; 319 private Server useserver; 290 320 private Exception lastException; 291 321 … … 293 323 super(tr("Querying name server"),false /* don't ignore exceptions */); 294 324 this.searchExpression = searchExpression; 325 useserver = (Server)server.getSelectedItem(); 326 Main.pref.put("namefinder.server", useserver.name); 295 327 } 296 328 … … 313 345 return; 314 346 } 347 columnmodel.setHeadlines(useserver.thirdcol, useserver.fourthcol); 315 348 model.setData(this.data); 316 349 } … … 320 353 try { 321 354 getProgressMonitor().indeterminateSubTask(tr("Querying name server ...")); 322 URL url = new URL("http://gazetteer.openstreetmap.org/namefinder/search.xml?find=" 323 +java.net.URLEncoder.encode(searchExpression, "UTF-8")); 355 URL url = new URL(useserver.url+java.net.URLEncoder.encode(searchExpression, "UTF-8")); 324 356 synchronized(this) { 325 357 connection = (HttpURLConnection)url.openConnection(); … … 381 413 382 414 static class NamedResultTableColumnModel extends DefaultTableColumnModel { 415 TableColumn col3 = null; 416 TableColumn col4 = null; 383 417 protected void createColumns() { 384 418 TableColumn col = null; … … 402 436 403 437 // column 2 - Near 404 col = new TableColumn(2);405 col .setHeaderValue(tr("Near"));406 col .setResizable(true);407 col .setPreferredWidth(100);408 col .setCellRenderer(renderer);409 addColumn(col );438 col3 = new TableColumn(2); 439 col3.setHeaderValue(servers[0].thirdcol); 440 col3.setResizable(true); 441 col3.setPreferredWidth(100); 442 col3.setCellRenderer(renderer); 443 addColumn(col3); 410 444 411 445 // column 3 - Zoom 412 col = new TableColumn(3); 413 col.setHeaderValue(tr("Zoom")); 414 col.setResizable(true); 415 col.setPreferredWidth(50); 416 col.setCellRenderer(renderer); 417 addColumn(col); 446 col4 = new TableColumn(3); 447 col4.setHeaderValue(servers[0].fourthcol); 448 col4.setResizable(true); 449 col4.setPreferredWidth(50); 450 col4.setCellRenderer(renderer); 451 addColumn(col4); 452 } 453 public void setHeadlines(String third, String fourth) { 454 col3.setHeaderValue(third); 455 col4.setHeaderValue(fourth); 456 fireColumnMarginChanged(); 418 457 } 419 458 … … 499 538 break; 500 539 case 3: 501 setText(Integer.toString(sr.zoom)); 540 if(sr.bounds != null) 541 setText(sr.bounds.toShortString(new DecimalFormat("0.000"))); 542 else 543 setText(sr.zoom != 0 ? Integer.toString(sr.zoom) : tr("unknown")); 502 544 break; 503 545 } … … 506 548 } 507 549 } 508 509 550 } -
trunk/src/org/openstreetmap/josm/tools/OsmUrlToBounds.java
r2626 r2717 129 129 } 130 130 131 p rivatestatic Bounds positionToBounds(final double lat, final double lon, final int zoom) {131 public static Bounds positionToBounds(final double lat, final double lon, final int zoom) { 132 132 final double size = 180.0 / Math.pow(2, zoom); 133 133 return new Bounds(
Note:
See TracChangeset
for help on using the changeset viewer.