Changeset 72 in josm


Ignore:
Timestamp:
2006-03-27T08:24:41+02:00 (18 years ago)
Author:
imi
Message:

fixed incomplete line segment saving

Location:
src/org/openstreetmap/josm
Files:
1 added
4 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/data/coor/EastNorth.java

    r71 r72  
    2121                return y;
    2222        }
     23       
     24        @Override
     25        public String toString() {
     26                return "(EastNorth e="+x+", n="+y+")";
     27        }
    2328}
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r71 r72  
    7575                                center.east() + (x - getWidth()/2.0)*scale,
    7676                                center.north() - (y - getHeight()/2.0)*scale);
    77                 return Main.pref.getProjection().eastNorth2latlon(eastNorth);
     77                return getProjection().eastNorth2latlon(eastNorth);
    7878        }
    7979
  • src/org/openstreetmap/josm/io/OsmReader.java

    r71 r72  
    113113       
    114114        @Override
    115         public void endElement(String namespaceURI, String localName, String qName) throws SAXException {
     115        public void endElement(String namespaceURI, String localName, String qName) {
    116116                if (qName.equals("node") || qName.equals("segment") || qName.equals("way") || qName.equals("area")) {
    117117                        current.visit(adder);
  • src/org/openstreetmap/josm/io/OsmWriter.java

    r71 r72  
    1212import org.openstreetmap.josm.data.osm.Way;
    1313import org.openstreetmap.josm.data.osm.visitor.Visitor;
    14 import org.xml.sax.SAXException;
     14import org.openstreetmap.josm.tools.XmlWriter;
    1515
    1616/**
     
    2020 */
    2121public class OsmWriter implements Visitor {
    22 
    23         private class RuntimeEncodingException extends RuntimeException {
    24                 public RuntimeEncodingException(Throwable t) {
    25                         super(t);
    26                 }
    27                 public RuntimeEncodingException() {
    28                 }
    29         }
    3022
    3123        /**
     
    4638        private final boolean osmConform;
    4739
    48         private final static HashMap<Character, String> encoding = new HashMap<Character, String>();
    49         static {
    50                 encoding.put('<', "&lt;");
    51                 encoding.put('>', "&gt;");
    52                 encoding.put('"', "&quot;");
    53                 encoding.put('\'', "&apos;");
    54                 encoding.put('&', "&amp;");
    55                 encoding.put('\n', "&#xA;");
    56                 encoding.put('\r', "&#xD;");
    57                 encoding.put('\t', "&#x9;");
    58         }
    59        
    6040        /**
    6141         * Output the data to the stream
     
    7757        }
    7858
    79         public static void outputSingle(Writer out, OsmPrimitive osm, boolean osmConform) throws SAXException {
    80                 try {
    81                         OsmWriter writer = new OsmWriter(out, osmConform);
    82                         writer.out.println("<?xml version='1.0' encoding='UTF-8'?>");
    83                         writer.out.println("<osm version='0.3' generator='JOSM'>");
    84                         osm.visit(writer);
    85                         writer.out.println("</osm>");
    86                 } catch (RuntimeEncodingException e) {
    87                         throw new SAXException("Your Java installation does not support the required UTF-8 encoding", (Exception)e.getCause());
    88                 }               
     59        public static void outputSingle(Writer out, OsmPrimitive osm, boolean osmConform) {
     60                OsmWriter writer = new OsmWriter(out, osmConform);
     61                writer.out.println(XmlWriter.header());
     62                writer.out.println("<osm version='0.3' generator='JOSM'>");
     63                osm.visit(writer);
     64                writer.out.println("</osm>");
    8965        }
    9066
     
    10581        public void visit(LineSegment ls) {
    10682                if (ls.incomplete)
    107                         throw new IllegalArgumentException("Cannot write an incomplete LineSegment.");
     83                        return; // Do not write an incomplete line segment
    10884                addCommon(ls, "segment");
    10985                out.print(" from='"+getUsedId(ls.from)+"' to='"+getUsedId(ls.to)+"'");
     
    137113                                out.println(">");
    138114                        for (Entry<String, String> e : osm.keys.entrySet())
    139                                 out.println("    <tag k='"+ encode(e.getKey()) +
    140                                                 "' v='"+encode(e.getValue())+ "' />");
     115                                out.println("    <tag k='"+ XmlWriter.encode(e.getKey()) +
     116                                                "' v='"+XmlWriter.encode(e.getValue())+ "' />");
    141117                        out.println("  </" + tagname + ">");
    142118                } else if (tagOpen)
     
    145121                        out.println("  </" + tagname + ">");
    146122        }
    147 
    148         /**
    149          * Encode the given string in XML1.0 format.
    150          * Optimized to fast pass strings that don't need encoding (normal case).
    151          */
    152         public String encode(String unencoded) {
    153                 StringBuilder buffer = null;
    154                 for (int i = 0; i < unencoded.length(); ++i) {
    155                         String encS = encoding.get(unencoded.charAt(i));
    156                         if (encS != null) {
    157                                 if (buffer == null)
    158                                         buffer = new StringBuilder(unencoded.substring(0,i));
    159                                 buffer.append(encS);
    160                         } else if (buffer != null)
    161                                 buffer.append(unencoded.charAt(i));
    162                 }
    163                 return (buffer == null) ? unencoded : buffer.toString();
    164         }
    165 
    166123
    167124        /**
Note: See TracChangeset for help on using the changeset viewer.