- Timestamp:
- 2014-09-21T23:00:38+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm
- Files:
-
- 1 added
- 13 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/actions/UpdateDataAction.java
r7434 r7575 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.actions.downloadtasks.DownloadTaskList; 16 import org.openstreetmap.josm.data. osm.DataSource;16 import org.openstreetmap.josm.data.DataSource; 17 17 import org.openstreetmap.josm.gui.progress.PleaseWaitProgressMonitor; 18 18 import org.openstreetmap.josm.io.OnlineResource; -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadGpsTask.java
r6990 r7575 106 106 } 107 107 108 @Override public void realRun() throws IOException, SAXException, OsmTransferException { 108 @Override 109 public void realRun() throws IOException, SAXException, OsmTransferException { 109 110 try { 110 111 if (isCanceled()) … … 123 124 } 124 125 125 @Override protected void finish() { 126 @Override 127 protected void finish() { 126 128 if (isCanceled() || isFailed()) 127 129 return; -
trunk/src/org/openstreetmap/josm/actions/downloadtasks/DownloadOsmTask.java
r7149 r7575 14 14 import org.openstreetmap.josm.Main; 15 15 import org.openstreetmap.josm.data.Bounds; 16 import org.openstreetmap.josm.data.DataSource; 16 17 import org.openstreetmap.josm.data.coor.LatLon; 17 18 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.DataSource;19 19 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; 20 20 import org.openstreetmap.josm.gui.PleaseWaitRunnable; -
trunk/src/org/openstreetmap/josm/data/DataSource.java
r7573 r7575 1 1 // License: GPL. For details, see LICENSE file. 2 package org.openstreetmap.josm.data .osm;2 package org.openstreetmap.josm.data; 3 3 4 import org.openstreetmap.josm.data.Bounds; 4 import java.awt.geom.Area; 5 import java.util.ArrayList; 6 import java.util.Collection; 7 import java.util.List; 8 5 9 import org.openstreetmap.josm.tools.CheckParameterUtil; 6 10 7 11 /** 8 12 * A data source, defined by bounds and textual description for the origin. 9 * @since 247 13 * @since 247 (creation) 14 * @since 7575 (moved package) 10 15 */ 11 16 public class DataSource { 17 12 18 /** 13 19 * The bounds of this data source 14 20 */ 15 21 public final Bounds bounds; 22 16 23 /** 17 24 * The textual description of the origin (example: "OpenStreetMap Server") … … 30 37 this.origin = origin; 31 38 } 39 40 @Override 41 public int hashCode() { 42 final int prime = 31; 43 int result = 1; 44 result = prime * result + ((bounds == null) ? 0 : bounds.hashCode()); 45 result = prime * result + ((origin == null) ? 0 : origin.hashCode()); 46 return result; 47 } 48 49 @Override 50 public boolean equals(Object obj) { 51 if (this == obj) 52 return true; 53 if (obj == null) 54 return false; 55 if (getClass() != obj.getClass()) 56 return false; 57 DataSource other = (DataSource) obj; 58 if (bounds == null) { 59 if (other.bounds != null) 60 return false; 61 } else if (!bounds.equals(other.bounds)) 62 return false; 63 if (origin == null) { 64 if (other.origin != null) 65 return false; 66 } else if (!origin.equals(other.origin)) 67 return false; 68 return true; 69 } 70 71 @Override 72 public String toString() { 73 return "DataSource [bounds=" + bounds + ", origin=" + origin + "]"; 74 } 75 76 /** 77 * Returns the total area of downloaded data (the "yellow rectangles"). 78 * @param dataSources list of data sources 79 * @return Area object encompassing downloaded data. 80 * @see Data#getDataSourceArea() 81 */ 82 public static Area getDataSourceArea(Collection<DataSource> dataSources) { 83 if (dataSources == null || dataSources.isEmpty()) { 84 return null; 85 } 86 Area a = new Area(); 87 for (DataSource source : dataSources) { 88 // create area from data bounds 89 a.add(new Area(source.bounds.asRect())); 90 } 91 return a; 92 } 93 94 /** 95 * <p>Replies the list of data source bounds.</p> 96 * 97 * <p>Dataset maintains a list of data sources which have been merged into the 98 * data set. Each of these sources can optionally declare a bounding box of the 99 * data it supplied to the dataset.</p> 100 * 101 * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p> 102 * @param dataSources list of data sources 103 * 104 * @return the list of data source bounds. An empty list, if no non-null data source 105 * bounds are defined. 106 * @see Data#getDataSourceBounds() 107 */ 108 public static List<Bounds> getDataSourceBounds(Collection<DataSource> dataSources) { 109 if (dataSources == null) { 110 return null; 111 } 112 List<Bounds> ret = new ArrayList<>(dataSources.size()); 113 for (DataSource ds : dataSources) { 114 if (ds.bounds != null) { 115 ret.add(ds.bounds); 116 } 117 } 118 return ret; 119 } 32 120 } -
trunk/src/org/openstreetmap/josm/data/gpx/GpxConstants.java
r7518 r7575 39 39 public static final String META_NAME = META_PREFIX + "name"; 40 40 public static final String META_TIME = META_PREFIX + "time"; 41 public static final String META_BOUNDS = META_PREFIX + "bounds"; 41 42 public static final String META_EXTENSIONS = META_PREFIX + "extensions"; 42 43 -
trunk/src/org/openstreetmap/josm/data/gpx/GpxData.java
r7518 r7575 2 2 package org.openstreetmap.josm.data.gpx; 3 3 4 import java.awt.geom.Area; 4 5 import java.io.File; 5 6 import java.util.Collection; 6 7 import java.util.Date; 8 import java.util.HashSet; 7 9 import java.util.Iterator; 8 10 import java.util.LinkedList; 11 import java.util.List; 9 12 import java.util.Map; 13 import java.util.Set; 10 14 11 15 import org.openstreetmap.josm.Main; 12 16 import org.openstreetmap.josm.data.Bounds; 17 import org.openstreetmap.josm.data.Data; 18 import org.openstreetmap.josm.data.DataSource; 13 19 import org.openstreetmap.josm.data.coor.EastNorth; 14 20 … … 20 26 * @author Raphael Mack <ramack@raphael-mack.de> 21 27 */ 22 public class GpxData extends WithAttributes {28 public class GpxData extends WithAttributes implements Data { 23 29 24 30 public File storageFile; … … 30 36 public final Collection<GpxRoute> routes = new LinkedList<>(); 31 37 public final Collection<WayPoint> waypoints = new LinkedList<>(); 38 39 /** 40 * All data sources (bounds of downloaded bounds) of this GpxData.<br> 41 * Not part of GPX standard but rather a JOSM extension, needed by the fact that 42 * OSM API does not provide {@code <bounds>} element in its GPX reply. 43 * @since 7575 44 */ 45 public final Set<DataSource> dataSources = new HashSet<>(); 32 46 33 47 public void mergeFrom(GpxData other) { … … 52 66 routes.addAll(other.routes); 53 67 waypoints.addAll(other.waypoints); 54 } 55 68 dataSources.addAll(other.dataSources); 69 } 70 71 /** 72 * Determines if this GPX data has one or more track points 73 * @return {@code true} if this GPX data has track points, {@code false} otherwise 74 */ 56 75 public boolean hasTrackPoints() { 57 76 for (GpxTrack trk : tracks) { … … 64 83 } 65 84 85 /** 86 * Determines if this GPX data has one or more route points 87 * @return {@code true} if this GPX data has route points, {@code false} otherwise 88 */ 66 89 public boolean hasRoutePoints() { 67 90 for (GpxRoute rte : routes) { … … 72 95 } 73 96 97 /** 98 * Determines if this GPX data is empty (i.e. does not contain any point) 99 * @return {@code true} if this GPX data is empty, {@code false} otherwise 100 */ 74 101 public boolean isEmpty() { 75 102 return !hasRoutePoints() && !hasTrackPoints() && waypoints.isEmpty(); … … 77 104 78 105 /** 79 * calculates the bounding box of available data and returns it. 106 * Returns the bounds defining the extend of this data, as read in metadata, if any. 107 * If no bounds is defined in metadata, {@code null} is returned. There is no guarantee 108 * that data entirely fit in this bounds, as it is not recalculated. To get recalculated bounds, 109 * see {@link #recalculateBounds()}. To get downloaded areas, see {@link #dataSources}. 110 * @return the bounds defining the extend of this data, or {@code null}. 111 * @see #recalculateBounds() 112 * @see #dataSources 113 * @since 7575 114 */ 115 public Bounds getMetaBounds() { 116 Object value = get(META_BOUNDS); 117 if (value instanceof Bounds) { 118 return (Bounds) value; 119 } 120 return null; 121 } 122 123 /** 124 * Calculates the bounding box of available data and returns it. 80 125 * The bounds are not stored internally, but recalculated every time 81 * this function is called. 126 * this function is called.<br> 127 * To get bounds as read from metadata, see {@link #getMetaBounds()}.<br> 128 * To get downloaded areas, see {@link #dataSources}.<br> 82 129 * 83 130 * FIXME might perhaps use visitor pattern? 84 131 * @return the bounds 132 * @see #getMetaBounds() 133 * @see #dataSources 85 134 */ 86 135 public Bounds recalculateBounds() { … … 119 168 * @return the length in meters 120 169 */ 121 public double length() {170 public double length() { 122 171 double result = 0.0; // in meters 123 172 … … 402 451 } 403 452 453 @Override 454 public Collection<DataSource> getDataSources() { 455 return dataSources; 456 } 457 458 @Override 459 public Area getDataSourceArea() { 460 return DataSource.getDataSourceArea(dataSources); 461 } 462 463 @Override 464 public List<Bounds> getDataSourceBounds() { 465 return DataSource.getDataSourceBounds(dataSources); 466 } 404 467 } -
trunk/src/org/openstreetmap/josm/data/osm/DataSet.java
r7501 r7575 24 24 import org.openstreetmap.josm.Main; 25 25 import org.openstreetmap.josm.data.Bounds; 26 import org.openstreetmap.josm.data.Data; 27 import org.openstreetmap.josm.data.DataSource; 26 28 import org.openstreetmap.josm.data.SelectionChangedListener; 27 29 import org.openstreetmap.josm.data.coor.EastNorth; … … 90 92 * @author imi 91 93 */ 92 public final class DataSet implements Cloneable, ProjectionChangeListener {94 public final class DataSet implements Data, Cloneable, ProjectionChangeListener { 93 95 94 96 /** … … 916 918 } 917 919 918 /** 919 * Returns the total area of downloaded data (the "yellow rectangles"). 920 * @return Area object encompassing downloaded data. 921 */ 920 @Override 921 public Collection<DataSource> getDataSources() { 922 return dataSources; 923 } 924 925 @Override 922 926 public Area getDataSourceArea() { 923 if (dataSources.isEmpty()) return null; 924 Area a = new Area(); 925 for (DataSource source : dataSources) { 926 // create area from data bounds 927 a.add(new Area(source.bounds.asRect())); 928 } 929 return a; 927 return DataSource.getDataSourceArea(dataSources); 930 928 } 931 929 … … 1317 1315 } 1318 1316 1319 /** 1320 * <p>Replies the list of data source bounds.</p> 1321 * 1322 * <p>Dataset maintains a list of data sources which have been merged into the 1323 * data set. Each of these sources can optionally declare a bounding box of the 1324 * data it supplied to the dataset.</p> 1325 * 1326 * <p>This method replies the list of defined (non {@code null}) bounding boxes.</p> 1327 * 1328 * @return the list of data source bounds. An empty list, if no non-null data source 1329 * bounds are defined. 1330 */ 1317 @Override 1331 1318 public List<Bounds> getDataSourceBounds() { 1332 List<Bounds> ret = new ArrayList<>(dataSources.size()); 1333 for (DataSource ds : dataSources) { 1334 if (ds.bounds != null) { 1335 ret.add(ds.bounds); 1336 } 1337 } 1338 return ret; 1319 return DataSource.getDataSourceBounds(dataSources); 1339 1320 } 1340 1321 -
trunk/src/org/openstreetmap/josm/gui/MapView.java
r7534 r7575 42 42 import org.openstreetmap.josm.data.Preferences.PreferenceChangeEvent; 43 43 import org.openstreetmap.josm.data.Preferences.PreferenceChangedListener; 44 import org.openstreetmap.josm.data.DataSource; 44 45 import org.openstreetmap.josm.data.SelectionChangedListener; 45 46 import org.openstreetmap.josm.data.ViewportData; … … 48 49 import org.openstreetmap.josm.data.imagery.ImageryInfo; 49 50 import org.openstreetmap.josm.data.osm.DataSet; 50 import org.openstreetmap.josm.data.osm.DataSource;51 51 import org.openstreetmap.josm.data.osm.OsmPrimitive; 52 52 import org.openstreetmap.josm.data.osm.visitor.BoundingXYVisitor; -
trunk/src/org/openstreetmap/josm/gui/dialogs/relation/ParentRelationLoadingTask.java
r7005 r7575 12 12 13 13 import org.openstreetmap.josm.Main; 14 import org.openstreetmap.josm.data.DataSource; 14 15 import org.openstreetmap.josm.data.osm.DataSet; 15 16 import org.openstreetmap.josm.data.osm.DataSetMerger; 16 import org.openstreetmap.josm.data.osm.DataSource;17 17 import org.openstreetmap.josm.data.osm.Relation; 18 18 import org.openstreetmap.josm.gui.PleaseWaitRunnable; -
trunk/src/org/openstreetmap/josm/gui/layer/OsmDataLayer.java
r7518 r7575 47 47 import org.openstreetmap.josm.data.APIDataSet; 48 48 import org.openstreetmap.josm.data.Bounds; 49 import org.openstreetmap.josm.data.DataSource; 49 50 import org.openstreetmap.josm.data.SelectionChangedListener; 50 51 import org.openstreetmap.josm.data.conflict.Conflict; … … 59 60 import org.openstreetmap.josm.data.osm.DataSet; 60 61 import org.openstreetmap.josm.data.osm.DataSetMerger; 61 import org.openstreetmap.josm.data.osm.DataSource;62 62 import org.openstreetmap.josm.data.osm.DatasetConsistencyTest; 63 63 import org.openstreetmap.josm.data.osm.IPrimitive; -
trunk/src/org/openstreetmap/josm/io/BoundingBoxDownloader.java
r7531 r7575 10 10 import org.openstreetmap.josm.Main; 11 11 import org.openstreetmap.josm.data.Bounds; 12 import org.openstreetmap.josm.data.DataSource; 12 13 import org.openstreetmap.josm.data.gpx.GpxData; 13 14 import org.openstreetmap.josm.data.notes.Note; … … 45 46 } 46 47 47 private GpxData downloadRawGps( String url, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException {48 private GpxData downloadRawGps(Bounds b, ProgressMonitor progressMonitor) throws IOException, OsmTransferException, SAXException { 48 49 boolean done = false; 49 50 GpxData result = null; 51 String url = "trackpoints?bbox="+b.getMinLon()+","+b.getMinLat()+","+b.getMaxLon()+","+b.getMaxLat()+"&page="; 50 52 for (int i = 0;!done;++i) { 51 53 progressMonitor.subTask(tr("Downloading points {0} to {1}...", i * 5000, ((i + 1) * 5000))); … … 70 72 if (result != null) { 71 73 result.fromServer = true; 74 result.dataSources.add(new DataSource(b, "OpenStreetMap server")); 72 75 } 73 76 return result; … … 81 84 if (crosses180th) { 82 85 // API 0.6 does not support requests crossing the 180th meridian, so make two requests 83 GpxData result = downloadRawGps( "trackpoints?bbox="+lon1+","+lat1+",180.0,"+lat2+"&page=", progressMonitor);84 result.mergeFrom(downloadRawGps( "trackpoints?bbox=-180.0,"+lat1+","+lon2+","+lat2+"&page=", progressMonitor));86 GpxData result = downloadRawGps(new Bounds(lat1, lon1, lat2, 180.0), progressMonitor); 87 result.mergeFrom(downloadRawGps(new Bounds(lat1, -180.0, lat2, lon2), progressMonitor)); 85 88 return result; 86 89 } else { 87 90 // Simple request 88 return downloadRawGps( "trackpoints?bbox="+lon1+","+lat1+","+lon2+","+lat2+"&page=", progressMonitor);91 return downloadRawGps(new Bounds(lat1, lon1, lat2, lon2), progressMonitor); 89 92 } 90 93 } catch (IllegalArgumentException e) { -
trunk/src/org/openstreetmap/josm/io/GpxReader.java
r7518 r7575 21 21 22 22 import org.openstreetmap.josm.Main; 23 import org.openstreetmap.josm.data.Bounds; 23 24 import org.openstreetmap.josm.data.coor.LatLon; 24 25 import org.openstreetmap.josm.data.gpx.Extensions; … … 38 39 * Read a gpx file. 39 40 * 40 * Bounds are not read, as we caluclate them. @see GpxData.recalculateBounds()41 * Bounds are read, even if we calculate them, see {@link GpxData#recalculateBounds}.<br> 41 42 * Both GPX version 1.0 and 1.1 are supported. 42 43 * … … 73 74 private boolean nokiaSportsTrackerBug = false; 74 75 75 @Override public void startDocument() { 76 @Override 77 public void startDocument() { 76 78 accumulator = new StringBuffer(); 77 79 states = new Stack<>(); … … 162 164 currentState = State.link; 163 165 currentLink = new GpxLink(atts.getValue("href")); 166 break; 167 case "bounds": 168 data.put(META_BOUNDS, new Bounds( 169 parseCoord(atts.getValue("minlat")), 170 parseCoord(atts.getValue("minlon")), 171 parseCoord(atts.getValue("maxlat")), 172 parseCoord(atts.getValue("maxlon")))); 164 173 } 165 174 break; … … 312 321 break; 313 322 } 323 case "bounds": 324 // do nothing, has been parsed on startElement 325 break; 314 326 default: 315 //TODO: parse bounds,extensions327 //TODO: parse extensions 316 328 } 317 329 break; -
trunk/src/org/openstreetmap/josm/io/OsmReader.java
r7299 r7575 21 21 import org.openstreetmap.josm.Main; 22 22 import org.openstreetmap.josm.data.Bounds; 23 import org.openstreetmap.josm.data.DataSource; 23 24 import org.openstreetmap.josm.data.coor.LatLon; 24 25 import org.openstreetmap.josm.data.osm.Changeset; 25 26 import org.openstreetmap.josm.data.osm.DataSet; 26 import org.openstreetmap.josm.data.osm.DataSource;27 27 import org.openstreetmap.josm.data.osm.Node; 28 28 import org.openstreetmap.josm.data.osm.NodeData; -
trunk/src/org/openstreetmap/josm/io/OsmWriter.java
r7299 r7575 12 12 import java.util.Map.Entry; 13 13 14 import org.openstreetmap.josm.data.DataSource; 14 15 import org.openstreetmap.josm.data.coor.CoordinateFormat; 15 16 import org.openstreetmap.josm.data.coor.LatLon; 16 17 import org.openstreetmap.josm.data.osm.Changeset; 17 18 import org.openstreetmap.josm.data.osm.DataSet; 18 import org.openstreetmap.josm.data.osm.DataSource;19 19 import org.openstreetmap.josm.data.osm.INode; 20 20 import org.openstreetmap.josm.data.osm.IPrimitive;
Note:
See TracChangeset
for help on using the changeset viewer.