- Timestamp:
- 2005-10-04T00:09:32+02:00 (19 years ago)
- Location:
- src/org/openstreetmap/josm
- Files:
-
- 2 added
- 11 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/OpenGpxAction.java
r7 r9 13 13 import javax.swing.filechooser.FileFilter; 14 14 15 import org.jdom.JDOMException;16 15 import org.openstreetmap.josm.data.osm.DataSet; 17 16 import org.openstreetmap.josm.gui.Main; 18 17 import org.openstreetmap.josm.gui.MapFrame; 19 18 import org.openstreetmap.josm.io.GpxReader; 19 import org.openstreetmap.josm.io.DataReader.ConnectionException; 20 import org.openstreetmap.josm.io.DataReader.ParseException; 20 21 21 22 /** … … 53 54 54 55 try { 55 DataSet dataSet = new GpxReader( ).parse(new FileReader(gpxFile));56 DataSet dataSet = new GpxReader(new FileReader(gpxFile)).parse(); 56 57 MapFrame map = new MapFrame(dataSet); 57 58 Main.main.setMapFrame(gpxFile.getName(), map); 58 } catch ( JDOMException x) {59 } catch (ParseException x) { 59 60 x.printStackTrace(); 60 JOptionPane.showMessageDialog(Main.main, "Illegal GPX document:\n"+x.getMessage());61 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 61 62 } catch (IOException x) { 62 63 x.printStackTrace(); 63 JOptionPane.showMessageDialog(Main.main, "Could not read '"+gpxFile.getName()+"':\n"+x.getMessage()); 64 JOptionPane.showMessageDialog(Main.main, "Could not read '"+gpxFile.getName()+"'\n"+x.getMessage()); 65 } catch (ConnectionException x) { 66 x.printStackTrace(); 67 JOptionPane.showMessageDialog(Main.main, x.getMessage()); 64 68 } 65 69 } -
src/org/openstreetmap/josm/data/GeoPoint.java
r7 r9 48 48 49 49 /** 50 * GeoPoints are equal, if their lat/lon are equal or, if lat or lon are NaN,51 * if their x/y are equal.52 */53 @Override54 public boolean equals(Object obj) {55 if (!(obj instanceof GeoPoint))56 return false;57 GeoPoint gp = (GeoPoint)obj;58 59 if (Double.isNaN(lat) || Double.isNaN(lon))60 return x == gp.x && y == gp.y;61 return lat == gp.lat && lon == gp.lon;62 }63 64 @Override65 public int hashCode() {66 return super.hashCode();67 }68 69 /**70 50 * Return the squared distance of the northing/easting values between 71 51 * this and the argument. -
src/org/openstreetmap/josm/data/osm/Key.java
r8 r9 57 57 } 58 58 59 /**60 * Keys are equal, when their name is equal, regardless of their other keys.61 */62 @Override63 public boolean equals(Object obj) {64 if (!(obj instanceof Key))65 return false;66 return name.equals(((Key)obj).name);67 }68 69 @Override70 public int hashCode() {71 return name.hashCode();72 }73 74 59 @Override 75 60 public void visit(Visitor visitor) { -
src/org/openstreetmap/josm/data/osm/LineSegment.java
r8 r9 85 85 } 86 86 87 /**88 * Line segments are equal, if their starting and ending node and their89 * keys are equal.90 */91 @Override92 public boolean equals(Object obj) {93 if (!(obj instanceof LineSegment))94 return false;95 return super.equals(obj) &&96 getStart().equals(((LineSegment)obj).getStart()) &&97 getEnd().equals(((LineSegment)obj).getEnd());98 }99 100 @Override101 public int hashCode() {102 return super.hashCode() + getStart().hashCode() + getEnd().hashCode();103 }104 105 87 @Override 106 88 public void visit(Visitor visitor) { -
src/org/openstreetmap/josm/data/osm/Node.java
r8 r9 35 35 36 36 /** 37 * Nodes are equal when their coordinates are equal.38 */39 @Override40 public boolean equals(Object obj) {41 if (!(obj instanceof Node))42 return false;43 Node n = (Node)obj;44 if (coor == null)45 return n.coor == null;46 return coor.equals(n.coor) && super.equals(obj);47 }48 49 /**50 * Compute the hashcode from the OsmPrimitive's hash and the coor's hash.51 */52 @Override53 public int hashCode() {54 return (coor == null ? 0 : coor.hashCode()) + super.hashCode();55 }56 57 /**58 37 * Return a list only this added. 59 38 */ -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r8 r9 68 68 69 69 /** 70 * Osm primitives are equal, when their keys are equal.71 */72 @Override73 public boolean equals(Object obj) {74 if (obj == null)75 return false;76 if (!(obj instanceof OsmPrimitive))77 return false;78 OsmPrimitive osm = (OsmPrimitive)obj;79 if (keys == null)80 return osm.keys == null;81 return keys.equals(osm.keys);82 }83 84 /**85 * Compute the hashCode from the keys.86 */87 @Override88 public int hashCode() {89 return keys == null ? 0 : keys.hashCode();90 }91 92 /**93 70 * Mark the primitive as selected or not selected and fires a selection 94 71 * changed later, if the value actualy changed. -
src/org/openstreetmap/josm/data/osm/Track.java
r8 r9 90 90 91 91 /** 92 * Tracks are equal, when all segments and the keys are equal93 */94 @Override95 public boolean equals(Object obj) {96 if (!(obj instanceof Track))97 return false;98 if (!super.equals(obj))99 return false;100 Track t = (Track)obj;101 int size = segments.size();102 if (size != t.segments.size())103 return false;104 for (int i = 0; i < size; ++i)105 if (!segments.get(i).equals(t.segments.get(i)))106 return false;107 return true;108 }109 110 @Override111 public int hashCode() {112 int hash = super.hashCode();113 for (LineSegment ls : segments)114 hash += ls.hashCode();115 return hash;116 }117 118 /**119 92 * Return the last node in the track. This is the node, which no line segment 120 93 * has as start, but at least one has it as end. If there are not exact one -
src/org/openstreetmap/josm/gui/Main.java
r7 r9 142 142 panel.removeAll(); 143 143 panel.add(mapFrame, BorderLayout.CENTER); 144 panel.add(mapFrame.getToolBarActions(), BorderLayout.WEST); 144 panel.add(mapFrame.toolBarActions, BorderLayout.WEST); 145 panel.add(mapFrame.statusLine, BorderLayout.SOUTH); 145 146 panel.setVisible(true); 146 147 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r8 r9 47 47 * The toolbar with the action icons 48 48 */ 49 private JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL); 49 public JToolBar toolBarActions = new JToolBar(JToolBar.VERTICAL); 50 /** 51 * The status line below the map 52 */ 53 public MapStatus statusLine; 50 54 51 55 /** … … 77 81 toolGroup.setSelected(((AbstractButton)toolBarActions.getComponent(0)).getModel(), true); 78 82 selectMapMode((MapMode)((AbstractButton)toolBarActions.getComponent(0)).getAction()); 79 83 80 84 // autoScale 81 85 toolBarActions.addSeparator(); … … 93 97 // properties 94 98 toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this))); 95 99 96 100 // selection dialog 97 101 SelectionListDialog selectionList = new SelectionListDialog(dataSet); … … 104 108 }); 105 109 toolBarActions.add(buttonSelection); 110 111 // status line below the map 112 statusLine = new MapStatus(mapView); 106 113 } 107 114 … … 117 124 mapMode.registerListener(); 118 125 } 119 120 /**121 * @return Returns the toolBarActions.122 */123 public JToolBar getToolBarActions() {124 return toolBarActions;125 }126 126 } -
src/org/openstreetmap/josm/gui/MapView.java
r8 r9 84 84 85 85 /** 86 * Construct a MapView and attach it to a frame.86 * Construct a MapView. 87 87 */ 88 88 public MapView(DataSet dataSet) { 89 89 this.dataSet = dataSet; 90 90 addComponentListener(this); 91 91 92 92 // initialize the movement listener 93 93 new MapMover(this); 94 94 95 95 // initialize the projection 96 96 setProjection(Main.pref.projection.clone()); 97 98 // initialize the engine97 98 // initialize the drawing engine 99 99 engine = new SimpleEngine(this); 100 100 } … … 222 222 } 223 223 224 224 225 /** 225 226 * Zoom to the given coordinate. … … 247 248 248 249 /** 250 * Draw the component. 251 */ 252 @Override 253 public void paint(Graphics g) { 254 engine.init(g); 255 engine.drawBackground(getPoint(0,0,true), getPoint(getWidth(), getHeight(), true)); 256 257 for (Track t : dataSet.tracks()) 258 engine.drawTrack(t); 259 for (LineSegment ls : dataSet.pendingLineSegments()) 260 engine.drawPendingLineSegment(ls); 261 for (Node n : dataSet.nodes) 262 engine.drawNode(n); 263 } 264 265 /** 266 * Notify from the projection, that something has changed. 267 * @param e 268 */ 269 public void stateChanged(ChangeEvent e) { 270 projection.init(dataSet); 271 recalculateCenterScale(); 272 } 273 274 /** 275 * Set a new projection method. This call is not cheap, as it will 276 * transform the whole underlying dataSet and repaint itself. 277 * 278 * @param projection The new projection method to set. 279 */ 280 public void setProjection(Projection projection) { 281 if (projection == this.projection) 282 return; 283 284 Projection oldProjection = this.projection; 285 286 if (this.projection != null) 287 this.projection.removeChangeListener(this); 288 this.projection = projection; 289 projection.addChangeListener(this); 290 291 stateChanged(new ChangeEvent(this)); 292 firePropertyChange("projection", oldProjection, projection); 293 } 294 295 /** 296 * Return the projection method for this map view. 297 * @return The projection method. 298 */ 299 public Projection getProjection() { 300 return projection; 301 } 302 303 /** 249 304 * Return the current scale value. 250 305 * @return The scale value currently used in display … … 254 309 } 255 310 311 /** 312 * @return Returns the autoScale. 313 */ 314 public boolean isAutoScale() { 315 return autoScale; 316 } 317 318 /** 319 * @param autoScale The autoScale to set. 320 */ 321 public void setAutoScale(boolean autoScale) { 322 if (this.autoScale != autoScale) { 323 this.autoScale = autoScale; 324 firePropertyChange("autoScale", !autoScale, autoScale); 325 } 326 } 327 /** 328 * @return Returns the center point. A copy is returned, so users cannot 329 * change the center by accessing the return value. Use zoomTo instead. 330 */ 331 public GeoPoint getCenter() { 332 return center.clone(); 333 } 334 335 336 256 337 /** 257 338 * Set the new dimension to the projection class. Also adjust the components … … 285 366 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 286 367 } 287 368 288 369 firePropertyChange("center", oldCenter, center); 289 370 if (oldAutoScale != autoScale) … … 303 384 304 385 /** 305 * Draw the component.306 */307 @Override308 public void paint(Graphics g) {309 engine.init(g);310 engine.drawBackground(getPoint(0,0,true), getPoint(getWidth(), getHeight(), true));311 312 for (Track t : dataSet.tracks())313 engine.drawTrack(t);314 for (LineSegment ls : dataSet.pendingLineSegments())315 engine.drawPendingLineSegment(ls);316 for (Node n : dataSet.nodes)317 engine.drawNode(n);318 }319 320 /**321 * Notify from the projection, that something has changed.322 * @param e323 */324 public void stateChanged(ChangeEvent e) {325 projection.init(dataSet);326 recalculateCenterScale();327 }328 329 /**330 * Set a new projection method. This call is not cheap, as it will331 * transform the whole underlying dataSet and repaint itself.332 *333 * @param projection The new projection method to set.334 */335 public void setProjection(Projection projection) {336 if (projection == this.projection)337 return;338 339 Projection oldProjection = this.projection;340 341 if (this.projection != null)342 this.projection.removeChangeListener(this);343 this.projection = projection;344 projection.addChangeListener(this);345 346 stateChanged(new ChangeEvent(this));347 firePropertyChange("projection", oldProjection, projection);348 }349 350 /**351 * Return the projection method for this map view.352 * @return The projection method.353 */354 public Projection getProjection() {355 return projection;356 }357 358 /**359 * @return Returns the autoScale.360 */361 public boolean isAutoScale() {362 return autoScale;363 }364 365 /**366 * @param autoScale The autoScale to set.367 */368 public void setAutoScale(boolean autoScale) {369 if (this.autoScale != autoScale) {370 this.autoScale = autoScale;371 firePropertyChange("autoScale", !autoScale, autoScale);372 }373 }374 /**375 * @return Returns the center point. A copy is returned, so users cannot376 * change the center by accessing the return value. Use zoomTo instead.377 */378 public GeoPoint getCenter() {379 return center.clone();380 }381 382 /**383 386 * Does nothing. Just to satisfy ComponentListener. 384 387 */ -
src/org/openstreetmap/josm/io/GpxReader.java
r8 r9 3 3 import java.io.IOException; 4 4 import java.io.Reader; 5 import java.util.HashMap; 5 6 6 7 import org.jdom.Element; … … 10 11 import org.openstreetmap.josm.data.GeoPoint; 11 12 import org.openstreetmap.josm.data.osm.DataSet; 13 import org.openstreetmap.josm.data.osm.Key; 12 14 import org.openstreetmap.josm.data.osm.LineSegment; 13 15 import org.openstreetmap.josm.data.osm.Node; 16 import org.openstreetmap.josm.data.osm.OsmPrimitive; 14 17 import org.openstreetmap.josm.data.osm.Track; 15 18 import org.openstreetmap.josm.gui.Main; 16 19 17 20 /** 18 * Reads an gpx stream and construct a DataSet out of it. Some information may not be 19 * imported, since JOSM does not fully support GPX. 21 * Reads an gpx stream and construct a DataSet out of it. 22 * Some information may not be imported, but GpxReader tries its best to load 23 * all data possible in the key/value structure. 20 24 * 21 25 * @author imi 22 26 */ 23 public class GpxReader { 24 25 public static final Namespace XSD = Namespace.getNamespace("http://www.w3.org/2001/XMLSchema"); 26 public static final Namespace GPX = Namespace.getNamespace("http://www.topografix.com/GPX/1/0"); 27 public class GpxReader implements DataReader { 28 29 /** 30 * The GPX namespace used. 31 */ 32 private static final Namespace GPX = Namespace.getNamespace("http://www.topografix.com/GPX/1/0"); 33 /** 34 * The OSM namespace used (for extensions). 35 */ 36 private static final Namespace OSM = Namespace.getNamespace("osm"); 37 38 /** 39 * The data source from this reader. 40 */ 41 public Reader source; 27 42 28 43 /** 44 * Construct a parser from a specific data source. 45 * @param source The data source, as example a FileReader to read from a file. 46 */ 47 public GpxReader(Reader source) { 48 this.source = source; 49 } 50 51 /** 29 52 * Read the input stream and return a DataSet from the stream. 30 * 31 * @param in 32 * @throws IOException An error with the provided stream occoured. 33 * @throws JDOMException An parse error occoured. 34 */ 35 public DataSet parse(Reader in) throws JDOMException, IOException { 53 */ 54 public DataSet parse() throws ParseException, ConnectionException { 36 55 try { 37 56 final SAXBuilder builder = new SAXBuilder(); 38 Element root = builder.build( in).getRootElement();57 Element root = builder.build(source).getRootElement(); 39 58 return parseDataSet(root); 40 59 } catch (NullPointerException npe) { 41 throw new JDOMException("NullPointerException. Probably a tag name mismatch.", npe);60 throw new ParseException("NullPointerException. Probably a tag name mismatch.", npe); 42 61 } catch (ClassCastException cce) { 43 throw new JDOMException("ClassCastException. Probably a tag does not contain the correct type.", cce); 62 throw new ParseException("ClassCastException. Probably a tag does not contain the correct type.", cce); 63 } catch (JDOMException e) { 64 throw new ParseException("The data could not be parsed. Reason: "+e.getMessage(), e); 65 } catch (IOException e) { 66 throw new ConnectionException("The data could not be retrieved. Reason: "+e.getMessage(), e); 44 67 } 45 68 } … … 56 79 Float.parseFloat(e.getAttributeValue("lat")), 57 80 Float.parseFloat(e.getAttributeValue("lon"))); 81 for (Object o : e.getChildren()) { 82 Element child = (Element)o; 83 if (child.getName().equals("extensions")) 84 parseKeyValueExtensions(data, child); 85 else if (child.getName().equals("link")) 86 parseKeyValueLink(data, child); 87 else 88 parseKeyValueTag(data, child); 89 } 58 90 return data; 91 } 92 93 /** 94 * Parse the extensions tag and add all properties found as key/value. 95 * <code>osm.keys</code> may be <code>null</code>, in which case it is 96 * created first. If <code>e</code> is <code>null</code>, nothing 97 * happens. 98 * 99 * @param osm The primitive to store the properties. 100 * @param e The extensions element to read the properties from. 101 */ 102 private void parseKeyValueExtensions(OsmPrimitive osm, Element e) { 103 if (e != null) { 104 if (osm.keys == null) 105 osm.keys = new HashMap<Key, String>(); 106 for (Object o : e.getChildren("property", OSM)) { 107 Element child = (Element)o; 108 Key key = Key.get(child.getAttributeValue("name")); 109 osm.keys.put(key, child.getAttributeValue("value")); 110 } 111 } 112 } 113 114 /** 115 * If the element is not <code>null</code>, read the data from it and put 116 * it as the key with the name of the elements name in the given object. 117 * 118 * The <code>keys</code> - field of the element could be <code>null</code>, 119 * in which case it is created first. 120 * 121 * @param osm The osm primitive to put the key into. 122 * @param e The element to look for data. 123 */ 124 private void parseKeyValueTag(OsmPrimitive osm, Element e) { 125 if (e != null) { 126 if (osm.keys == null) 127 osm.keys = new HashMap<Key, String>(); 128 osm.keys.put(Key.get(e.getName()), e.getValue()); 129 } 130 } 131 132 /** 133 * Parse the GPX linkType data information and store it as value in the 134 * primitives <i>link</i> key. <code>osm.keys</code> may be 135 * <code>null</code>, in which case it is created first. If 136 * <code>e</code> is <code>null</code>, nothing happens. 137 * 138 * The format stored is: mimetype;url 139 * Example: text/html;http://www.openstreetmap.org 140 * @param osm The osm primitive to store the data in. 141 * @param e The element in gpx:linkType - format. 142 */ 143 private void parseKeyValueLink(Node osm, Element e) { 144 if (e != null) { 145 if (osm.keys == null) 146 osm.keys = new HashMap<Key, String>(); 147 String link = e.getChildText("type") + ";" + e.getChildText("text"); 148 osm.keys.put(Key.get("link"), link); 149 } 59 150 } 60 151 … … 105 196 if (Main.pref.mergeNodes) 106 197 for (Node n : data.nodes) 107 if (node. equals(n))198 if (node.coor.lat == n.coor.lat && node.coor.lon == n.coor.lon) 108 199 return n; 109 200 data.nodes.add(node);
Note:
See TracChangeset
for help on using the changeset viewer.