Changeset 5346 in josm


Ignore:
Timestamp:
Jul 17, 2012 9:34:34 AM (10 months ago)
Author:
Don-vip
Message:

fix #7867, see #7505, see #7847 - Handle deleted nodes without coordinates in history

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

Legend:

Unmodified
Added
Removed
  • trunk/src/org/openstreetmap/josm/data/osm/history/HistoryNode.java

    r4602 r5346  
    1515 */ 
    1616public class HistoryNode extends HistoryOsmPrimitive { 
    17     /** the coordinates */ 
     17    /** the coordinates. May be null for deleted nodes */ 
    1818 
    1919    private LatLon coords; 
  • trunk/src/org/openstreetmap/josm/gui/DefaultNameFormatter.java

    r5328 r5346  
    1919import org.openstreetmap.josm.Main; 
    2020import org.openstreetmap.josm.data.coor.CoordinateFormat; 
     21import org.openstreetmap.josm.data.coor.LatLon; 
    2122import org.openstreetmap.josm.data.osm.Changeset; 
    2223import org.openstreetmap.josm.data.osm.IPrimitive; 
     
    556557            sb.append(name); 
    557558        } 
    558         sb.append(" (") 
    559         .append(node.getCoords().latToString(CoordinateFormat.getDefaultFormat())) 
    560         .append(", ") 
    561         .append(node.getCoords().lonToString(CoordinateFormat.getDefaultFormat())) 
    562         .append(")"); 
     559        LatLon coord = node.getCoords(); 
     560        if (coord != null) { 
     561            sb.append(" (") 
     562            .append(coord.latToString(CoordinateFormat.getDefaultFormat())) 
     563            .append(", ") 
     564            .append(coord.lonToString(CoordinateFormat.getDefaultFormat())) 
     565            .append(")"); 
     566        } 
    563567        decorateNameWithId(sb, node); 
    564568        return sb.toString(); 
  • trunk/src/org/openstreetmap/josm/gui/history/CoordinateInfoViewer.java

    r5266 r5346  
    1515 
    1616import org.openstreetmap.josm.data.coor.CoordinateFormat; 
     17import org.openstreetmap.josm.data.coor.LatLon; 
    1718import org.openstreetmap.josm.data.osm.history.HistoryNode; 
    1819import org.openstreetmap.josm.data.osm.history.HistoryOsmPrimitive; 
     
    256257            HistoryNode oppositeNode = (HistoryNode) opposite; 
    257258 
     259            LatLon coord = node.getCoords(); 
     260            LatLon oppositeCoord = oppositeNode.getCoords(); 
     261             
    258262            // display the coordinates 
    259263            // 
    260             lblLat.setText(node.getCoords().latToString(CoordinateFormat.DECIMAL_DEGREES)); 
    261             lblLon.setText(node.getCoords().lonToString(CoordinateFormat.DECIMAL_DEGREES)); 
     264            lblLat.setText(coord != null ? coord.latToString(CoordinateFormat.DECIMAL_DEGREES) : tr("Deleted")); 
     265            lblLon.setText(coord != null ? coord.lonToString(CoordinateFormat.DECIMAL_DEGREES) : tr("Deleted")); 
    262266 
    263267            // update background color to reflect differences in the coordinates 
    264268            // 
    265             if (node.getCoords().lat() == oppositeNode.getCoords().lat()) { 
     269            if (coord == oppositeCoord ||  
     270                    (coord != null && oppositeCoord != null && coord.lat() == oppositeCoord.lat())) { 
    266271                lblLat.setBackground(Color.WHITE); 
    267272            } else { 
    268273                lblLat.setBackground(BGCOLOR_DIFFERENCE); 
    269274            } 
    270             if (node.getCoords().lon() == oppositeNode.getCoords().lon()) { 
     275            if (coord == oppositeCoord ||  
     276                    (coord != null && oppositeCoord != null && coord.lon() == oppositeCoord.lon())) { 
    271277                lblLon.setBackground(Color.WHITE); 
    272278            } else { 
    273279                lblLon.setBackground(BGCOLOR_DIFFERENCE); 
    274280            } 
    275  
    276281        } 
    277282 
     
    322327            HistoryNode oppositeNode = (HistoryNode) opposite; 
    323328 
     329            LatLon coord = node.getCoords(); 
     330            LatLon oppositeCoord = oppositeNode.getCoords(); 
     331             
    324332            // update distance 
    325333            // 
    326             double distance = node.getCoords().greatCircleDistance(oppositeNode.getCoords()); 
    327             if (distance > 0) { 
    328                 lblDistance.setBackground(BGCOLOR_DIFFERENCE); 
     334            if (coord != null && oppositeCoord != null) { 
     335                double distance = coord.greatCircleDistance(oppositeCoord); 
     336                if (distance > 0) { 
     337                    lblDistance.setBackground(BGCOLOR_DIFFERENCE); 
     338                } else { 
     339                    lblDistance.setBackground(Color.WHITE); 
     340                } 
     341                lblDistance.setText(NavigatableComponent.getDistText(distance)); 
    329342            } else { 
    330                 lblDistance.setBackground(Color.WHITE); 
     343                lblDistance.setBackground(coord != oppositeCoord ? BGCOLOR_DIFFERENCE : Color.WHITE); 
     344                lblDistance.setText(tr("Deleted")); 
    331345            } 
    332             lblDistance.setText(NavigatableComponent.getDistText(distance)); 
    333346        } 
    334347    } 
  • trunk/src/org/openstreetmap/josm/io/OsmChangesetContentParser.java

    r5266 r5346  
    4444    private ChangesetDataSet data; 
    4545 
     46    // FIXME: this class has many similarities with OsmHistoryReader.Parser and should be merged  
    4647    private class Parser extends DefaultHandler { 
    4748 
     
    103104        } 
    104105 
    105         protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{ 
     106        protected Double getAttributeDouble(Attributes attr, String name) throws SAXException{ 
    106107            String v = attr.getValue(name); 
    107108            if (v == null) { 
    108                 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 
     109                return null; 
    109110            } 
    110111            double d = 0.0; 
     
    112113                d = Double.parseDouble(v); 
    113114            } catch(NumberFormatException e) { 
    114                 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 
     115                throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 
    115116            } 
    116117            return d; 
     
    160161            HistoryOsmPrimitive primitive = null; 
    161162            if (type.equals(OsmPrimitiveType.NODE)) { 
    162                 double lat = getMandatoryAttributeDouble(atts, "lat"); 
    163                 double lon = getMandatoryAttributeDouble(atts, "lon"); 
     163                Double lat = getAttributeDouble(atts, "lat"); 
     164                Double lon = getAttributeDouble(atts, "lon"); 
     165                LatLon coor = (lat != null && lon != null) ? new LatLon(lat,lon) : null; 
    164166                primitive = new HistoryNode( 
    165                         id,version,visible,user,changesetId,timestamp, new LatLon(lat,lon) 
     167                        id,version,visible,user,changesetId,timestamp,coor 
    166168                ); 
    167169 
  • trunk/src/org/openstreetmap/josm/io/OsmHistoryReader.java

    r5266 r5346  
    4242    private final HistoryDataSet data; 
    4343 
     44    // FIXME: this class has many similarities with OsmChangesetContentParser.Parser and should be merged  
    4445    private class Parser extends DefaultHandler { 
    4546 
     
    99100        } 
    100101 
    101         protected Double getMandatoryAttributeDouble(Attributes attr, String name) throws SAXException{ 
    102             String v = attr.getValue(name); 
    103             if (v == null) { 
    104                 throwException(tr("Missing mandatory attribute ''{0}''.", name)); 
     102        protected Double getAttributeDouble(Attributes attr, String name) throws SAXException{ 
     103            String v = attr.getValue(name); 
     104            if (v == null) { 
     105                return null; 
    105106            } 
    106107            double d = 0.0; 
     
    108109                d = Double.parseDouble(v); 
    109110            } catch(NumberFormatException e) { 
    110                 throwException(tr("Illegal value for mandatory attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 
     111                throwException(tr("Illegal value for attribute ''{0}'' of type double. Got ''{1}''.", name, v)); 
    111112            } 
    112113            return d; 
     
    154155            HistoryOsmPrimitive primitive = null; 
    155156            if (type.equals(OsmPrimitiveType.NODE)) { 
    156                 double lat = getMandatoryAttributeDouble(atts, "lat"); 
    157                 double lon = getMandatoryAttributeDouble(atts, "lon"); 
     157                Double lat = getAttributeDouble(atts, "lat"); 
     158                Double lon = getAttributeDouble(atts, "lon"); 
     159                LatLon coord = (lat != null && lon != null) ? new LatLon(lat,lon) : null; 
    158160                primitive = new HistoryNode( 
    159                         id,version,visible,user,changesetId,timestamp, new LatLon(lat,lon) 
     161                        id,version,visible,user,changesetId,timestamp,coord 
    160162                ); 
    161163 
Note: See TracChangeset for help on using the changeset viewer.