Changeset 66 in josm


Ignore:
Timestamp:
2006-03-22T19:13:05+01:00 (18 years ago)
Author:
imi
Message:

fixed "segment completly out of map" - problem

Files:
1 deleted
30 edited

Legend:

Unmodified
Added
Removed
  • src/org/openstreetmap/josm/actions/DownloadAction.java

    r61 r66  
    207207                                }
    208208                                b.name = JOptionPane.showInputDialog(Main.main, "Please enter a name for the location.");
    209                                 if (!b.name.equals("")) {
     209                                if (b.name != null && !b.name.equals("")) {
    210210                                        ((DefaultListModel)bookmarks.getModel()).addElement(b);
    211211                                        bookmarks.save();
     
    245245
    246246        /**
    247          * Read the values from the edit fields and start the download.
     247         * Read the values from the edit fields and from the download.
    248248         */
    249249        private DownloadStatus startDownload() {
  • src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java

    r39 r66  
    7272
    7373        /**
    74          * If user clicked on a node, start the dragging with that node.
     74         * If user clicked on a node, from the dragging with that node.
    7575         */
    7676        @Override
     
    138138                        // try to find a line segment
    139139                        for (LineSegment ls : Main.main.ds.lineSegments)
    140                                 if ((start == ls.start && end == ls.end) || (end == ls.start && start == ls.end))
     140                                if ((start == ls.from && end == ls.to) || (end == ls.from && start == ls.to))
    141141                                        return; // already a line segment here - be happy, do nothing.
    142142
  • src/org/openstreetmap/josm/actions/mapmode/AddNodeAction.java

    r40 r66  
    5050        public void mouseClicked(MouseEvent e) {
    5151                if (e.getButton() == MouseEvent.BUTTON1) {
    52                         Node node = new Node();
    53                         node.coor = mv.getPoint(e.getX(), e.getY(), true);
     52                        Node node = new Node(mv.getPoint(e.getX(), e.getY(), true));
    5453                        if (node.coor.isOutSideWorld()) {
    5554                                JOptionPane.showMessageDialog(Main.main, "Can not add a node outside of the world.");
  • src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java

    r64 r66  
    8888                // 0  if no elements in list, quit
    8989                // 1  taking the first ls as pivot, remove it from list
    90                 // 2  searching for a connection at start or end of pivot
     90                // 2  searching for a connection at from or to of pivot
    9191                // 3  if found, attach it, remove it from list, goto 2
    9292                // 4  if not found, save the pivot-string and goto 0
     
    100100                                for (Iterator<LineSegment> it = lineSegments.iterator(); it.hasNext();) {
    101101                                        LineSegment ls = it.next();
    102                                         if (ls.start == pivotList.getLast().end) {
     102                                        if (ls.incomplete)
     103                                                continue; // incomplete segments are never added to a new way
     104                                        if (ls.from == pivotList.getLast().to) {
    103105                                                pivotList.addLast(ls);
    104106                                                it.remove();
    105107                                                found = true;
    106                                         } else if (ls.end == pivotList.getFirst().start) {
     108                                        } else if (ls.to == pivotList.getFirst().from) {
    107109                                                pivotList.addFirst(ls);
    108110                                                it.remove();
     
    115117               
    116118                Way t = new Way();
    117                 for (LineSegment ls : sortedLineSegments)
    118                         t.segments.add(ls);
     119                t.segments.addAll(sortedLineSegments);
    119120                mv.editLayer().add(new AddCommand(Main.main.ds, t));
    120121                Main.main.ds.clearSelection();
  • src/org/openstreetmap/josm/command/ChangeKeyValueCommand.java

    r64 r66  
    5959
    6060                if (value == null) {
    61                         for (OsmPrimitive osm : objects) {
    62                                 if (osm.keys != null) {
    63                                         osm.keys.remove(key);
    64                                         if (osm.keys.isEmpty())
    65                                                 osm.keys = null;
    66                                 }
    67                         }
     61                        for (OsmPrimitive osm : objects)
     62                                osm.remove(key);
    6863                } else {
    69                         for (OsmPrimitive osm : objects) {
    70                                 if (osm.keys == null)
    71                                         osm.keys = new HashMap<String, String>();
    72                                 osm.keys.put(key, value);
    73                         }
     64                        for (OsmPrimitive osm : objects)
     65                                osm.put(key, value);
    7466                }
    7567        }
  • src/org/openstreetmap/josm/data/osm/LineSegment.java

    r64 r66  
    66
    77/**
    8  * One way line segment consisting of a pair of nodes (start/end)
     8 * One way line segment consisting of a pair of nodes (from/to)
    99 *
    1010 * @author imi
     
    1515         * The starting node of the line segment
    1616         */
    17         public Node start;
     17        public Node from;
    1818       
    1919        /**
    2020         * The ending node of the line segment
    2121         */
    22         public Node end;
     22        public Node to;
     23
     24        /**
     25         * If set to true, this object is incomplete, which means only the id
     26         * and type is known (type is the objects instance class)
     27         */
     28        public boolean incomplete;
    2329
    2430        /**
    2531         * Create an line segment from the given starting and ending node
    26          * @param start Starting node of the line segment.
    27          * @param end   Ending node of the line segment.
     32         * @param from  Starting node of the line segment.
     33         * @param to    Ending node of the line segment.
    2834         */
    29         public LineSegment(Node start, Node end) {
    30                 this.start = start;
    31                 this.end = end;
     35        public LineSegment(Node from, Node to) {
     36                this.from = from;
     37                this.to = to;
     38                incomplete = false;
     39        }
     40
     41        public LineSegment(long id) {
     42                this.id = id;
     43                incomplete = true;
    3244        }
    3345
     
    4456                if (equals(ls))
    4557                        return true;
    46                 GeoPoint s1 = start.coor;
    47                 GeoPoint s2 = ls.start.coor;
    48                 GeoPoint e1 = end.coor;
    49                 GeoPoint e2 = ls.end.coor;
     58                if (incomplete || ls.incomplete)
     59                        return false;
     60                GeoPoint s1 = from.coor;
     61                GeoPoint s2 = ls.from.coor;
     62                GeoPoint e1 = to.coor;
     63                GeoPoint e2 = ls.to.coor;
    5064                return ((s1.equalsLatLon(s2) && e1.equalsLatLon(e2)) ||
    5165                                (s1.equalsLatLon(e2) && e1.equalsLatLon(s2)));
    5266        }
     67
     68        @Override
     69        public String toString() {
     70                String s = "{LineSegment id="+id;
     71                if (incomplete)
     72                        return s+",incomplete}";
     73                return s+",from="+from+",to="+to+"}";
     74        }
     75
     76        @Override
     77        public void cloneFrom(OsmPrimitive osm) {
     78                super.cloneFrom(osm);
     79                LineSegment ls = ((LineSegment)osm);
     80                from = ls.from;
     81                to = ls.to;
     82                incomplete = ls.incomplete;
     83        }
    5384}       
  • src/org/openstreetmap/josm/data/osm/Node.java

    r23 r66  
    1717        public GeoPoint coor;
    1818
     19        public Node(GeoPoint coor) {
     20                this.coor = coor;
     21        }
     22
    1923        @Override
    2024        public void visit(Visitor visitor) {
    2125                visitor.visit(this);
    2226        }
     27       
     28        @Override
     29        public String toString() {
     30                return "{Node id="+id+",lat="+coor.lat+",lon="+coor.lon+"}";
     31        }
     32
     33        @Override
     34        public void cloneFrom(OsmPrimitive osm) {
     35                super.cloneFrom(osm);
     36                GeoPoint g = ((Node)osm).coor;
     37                coor = new GeoPoint(g.lat, g.lon, g.x, g.y); //TODO: Make GeoPoint immutable!
     38        }
    2339}
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r64 r66  
    11package org.openstreetmap.josm.data.osm;
    22
     3import java.util.Collection;
     4import java.util.Collections;
    35import java.util.HashMap;
    46import java.util.Map;
     7import java.util.Map.Entry;
    58
    69import org.openstreetmap.josm.Main;
     
    6467         */
    6568        abstract public void visit(Visitor visitor);
    66        
     69
    6770        /**
    6871         * Return <code>true</code>, if either <code>this.keys</code> and
     
    119122         * Equal, if the id (and class) is equal. If both ids are 0, use the super classes
    120123         * equal instead.
     124         *
     125         * An primitive is equal to its incomplete counter part.
    121126         */
    122127        @Override
     
    129134        /**
    130135         * Return the id as hashcode or supers hashcode if 0.
     136         *
     137         * An primitive has the same hashcode as its incomplete counter part.
    131138         */
    132139        @Override
     
    145152                keys.put(key, value);
    146153        }
     154        /**
     155         * Remove the given key from the list.
     156         */
     157        public void remove(String key) {
     158                if (keys != null) {
     159                        keys.remove(key);
     160                        if (keys.isEmpty())
     161                                keys = null;
     162                }
     163        }
     164
     165        public String get(String key) {
     166                return keys == null ? null : keys.get(key);
     167        }
    147168       
    148         public String get(String key) {
    149                 return (keys == null) ? null : keys.get(key);
     169        public Collection<Entry<String, String>> entrySet() {
     170                if (keys == null)
     171                        return Collections.emptyList();
     172                return keys.entrySet();
     173        }
     174
     175        public Collection<String> keySet() {
     176                if (keys == null)
     177                        return Collections.emptyList();
     178                return keys.keySet();
     179        }
     180
     181        /**
     182         * Get and write all attributes from the parameter. Does not fire any listener, so
     183         * use this only in the data initializing phase
     184         */
     185        public void cloneFrom(OsmPrimitive osm) {
     186                keys = osm.keys;
     187                id = osm.id;
     188                modified = osm.modified;
     189                modifiedProperties = osm.modifiedProperties;
     190                deleted = osm.deleted;
     191                selected = osm.selected;
    150192        }
    151193}
  • src/org/openstreetmap/josm/data/osm/Way.java

    r64 r66  
    1818        public final List<LineSegment> segments = new ArrayList<LineSegment>();
    1919
    20        
    21         /**
    22          * Return the last node in the way. This is the node, which no line segment
    23          * has as start, but at least one has it as end. If there are not exact one
    24          * such nodes found, <code>null</code> is returned.
    25          *
    26          * TODO Currently does return just the end node in the list.
    27          *
    28          * @return The ending node, if there is one.
    29          */
    30         public Node getEndingNode() {
    31                 if (segments.isEmpty())
    32                         return null;
    33                 return segments.get(segments.size()-1).end;
    34         }
    35        
    36         /**
    37          * Return the last segment.
    38          * @see #getEndingNode()
    39          */
    40         public LineSegment getEndingSegment() {
    41                 if (segments.isEmpty())
    42                         return null;
    43                 return segments.get(segments.size()-1);
    44         }
    45 
    46         /**
    47          * Return the first node in the way. This is the node, which no line segment
    48          * has as end, but at least one as starting node. If there are not exact one
    49          * such nodes found, <code>null</code> is returned.
    50          *
    51          * TODO Currently does return just the first node in the list.
    52          *
    53          * @return The starting node, if there is one.
    54          */
    55         public Node getStartingNode() {
    56                 if (segments.isEmpty())
    57                         return null;
    58                 return segments.get(0).start;
    59         }
    60        
    61         /**
    62          * Return the first segment.
    63          * @see #getStartingNode()
    64          */
    65         public LineSegment getStartingSegment() {
    66                 if (segments.isEmpty())
    67                         return null;
    68                 return segments.get(0);
    69         }
    70 
    7120        @Override
    7221        public void visit(Visitor visitor) {
    7322                visitor.visit(this);
    7423        }
     24
     25        @Override
     26        public void cloneFrom(OsmPrimitive osm) {
     27                super.cloneFrom(osm);
     28                segments.clear();
     29                segments.addAll(((Way)osm).segments);
     30        }
    7531}
  • src/org/openstreetmap/josm/data/osm/visitor/AllNodesVisitor.java

    r64 r66  
    2929
    3030        /**
    31          * Line segments have exactly two nodes: start and end.
     31         * Line segments have exactly two nodes: from and to.
    3232         */
    3333        public void visit(LineSegment ls) {
    34                 nodes.add(ls.start);
    35                 nodes.add(ls.end);
     34                if (!ls.incomplete) {
     35                        visit(ls.from);
     36                        visit(ls.to);
     37                }
    3638        }
    3739
     
    4042         */
    4143        public void visit(Way t) {
    42                 for (LineSegment ls : t.segments) {
    43                         nodes.add(ls.start);
    44                         nodes.add(ls.end);
    45                 }
     44                for (LineSegment ls : t.segments)
     45                        visit(ls);
    4646        }
    4747
  • src/org/openstreetmap/josm/data/osm/visitor/BoundingVisitor.java

    r64 r66  
    4848
    4949        public void visit(LineSegment ls) {
    50                 visit(ls.start);
    51                 visit(ls.end);
     50                if (!ls.incomplete) {
     51                        visit(ls.from);
     52                        visit(ls.to);
     53                }
    5254        }
    5355
  • src/org/openstreetmap/josm/data/osm/visitor/CollectBackReferencesVisitor.java

    r64 r66  
    4141                                continue;
    4242                        for (LineSegment ls : t.segments) {
    43                                 if (ls.start == n || ls.end == n) {
     43                                if (ls.incomplete)
     44                                        continue;
     45                                if (ls.from == n || ls.to == n) {
    4446                                        data.add(t);
    4547                                        break;
     
    4850                }
    4951                for (LineSegment ls : ds.lineSegments) {
    50                         if (ls.isDeleted())
     52                        if (ls.isDeleted() || ls.incomplete)
    5153                                continue;
    52                         if (ls.start == n || ls.end == n)
     54                        if (ls.from == n || ls.to == n)
    5355                                data.add(ls);
    5456                }
  • src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java

    r64 r66  
    7979                if (myLs == null)
    8080                        ds.lineSegments.add(otherLs);
    81                 else {
     81                else if (myLs.incomplete && !otherLs.incomplete) {
     82                        mergedLineSegments.put(otherLs, myLs);
     83                        myLs.cloneFrom(otherLs);
     84                } else if (!otherLs.incomplete) {
    8285                        mergedLineSegments.put(otherLs, myLs);
    8386                        mergeCommon(myLs, otherLs);
    8487                        if (myLs.modified && !otherLs.modified)
    8588                                return;
    86                         if (!match(myLs.start, otherLs.start)) {
    87                                 myLs.start = otherLs.start;
     89                        if (!match(myLs.from, otherLs.from)) {
     90                                myLs.from = otherLs.from;
    8891                                myLs.modified = otherLs.modified;
    8992                        }
    90                         if (!match(myLs.end, otherLs.end)) {
    91                                 myLs.end = otherLs.end;
     93                        if (!match(myLs.to, otherLs.to)) {
     94                                myLs.to = otherLs.to;
    9295                                myLs.modified = otherLs.modified;
    9396                        }
     
    133136        public void fixReferences() {
    134137                for (LineSegment ls : ds.lineSegments) {
    135                         if (mergedNodes.containsKey(ls.start))
    136                                 ls.start = mergedNodes.get(ls.start);
    137                         if (mergedNodes.containsKey(ls.end))
    138                                 ls.end = mergedNodes.get(ls.end);
     138                        if (mergedNodes.containsKey(ls.from))
     139                                ls.from = mergedNodes.get(ls.from);
     140                        if (mergedNodes.containsKey(ls.to))
     141                                ls.to = mergedNodes.get(ls.to);
    139142                }
    140143                for (Way t : ds.waies) {
     
    152155                        }
    153156                        for (LineSegment ls : t.segments) {
    154                                 if (mergedNodes.containsKey(ls.start))
    155                                         ls.start = mergedNodes.get(ls.start);
    156                                 if (mergedNodes.containsKey(ls.end))
    157                                         ls.end = mergedNodes.get(ls.end);
     157                                if (mergedNodes.containsKey(ls.from))
     158                                        ls.from = mergedNodes.get(ls.from);
     159                                if (mergedNodes.containsKey(ls.to))
     160                                        ls.to = mergedNodes.get(ls.to);
    158161                        }
    159162                }
     
    173176         */
    174177        private boolean match(LineSegment ls1, LineSegment ls2) {
    175                 if (ls1.id == 0 || ls2.id == 0)
    176                         return match(ls1.start, ls2.start) && match(ls1.end, ls2.end);
    177                 return ls1.id == ls2.id;
     178                if (ls1.id == ls2.id)
     179                        return true;
     180                if (ls1.incomplete || ls2.incomplete)
     181                        return false;
     182                return match(ls1.from, ls2.from) && match(ls1.to, ls2.to);
    178183        }
    179184
  • src/org/openstreetmap/josm/data/osm/visitor/SelectionComponentVisitor.java

    r64 r66  
    33
    44import java.util.HashSet;
    5 import java.util.Map;
    65import java.util.Set;
    76
     
    3635         */
    3736        public void visit(LineSegment ls) {
    38                 String name = getName(ls.keys);
     37                name = ls.get("name");
     38                if (name == null && ls.incomplete)
     39                        name = ""+ls.id;
    3940                if (name == null)
    40                         name = "("+ls.start.coor.lat+","+ls.start.coor.lon+") -> ("+ls.end.coor.lat+","+ls.end.coor.lon+")";
    41                        
    42                 this.name = name;
     41                        name = "("+ls.from.coor.lat+","+ls.from.coor.lon+") -> ("+ls.to.coor.lat+","+ls.to.coor.lon+")";
    4342                icon = ImageProvider.get("data", "linesegment");
    4443        }
     
    4948         */
    5049        public void visit(Node n) {
    51                 String name = getName(n.keys);
     50                name = n.get("name");
    5251                if (name == null)
    5352                        name = "("+n.coor.lat+","+n.coor.lon+")";
    54                
    55                 this.name = name;
    5653                icon = ImageProvider.get("data", "node");
    5754        }
     
    6158         * is displayed with x beeing the number of nodes in the way.
    6259         */
    63         public void visit(Way t) {
    64                 String name = getName(t.keys);
     60        public void visit(Way w) {
     61                name = w.get("name");
    6562                if (name == null) {
    6663                        Set<Node> nodes = new HashSet<Node>();
    67                         for (LineSegment ls : t.segments) {
    68                                 nodes.add(ls.start);
    69                                 nodes.add(ls.end);
     64                        for (LineSegment ls : w.segments) {
     65                                if (!ls.incomplete) {
     66                                        nodes.add(ls.from);
     67                                        nodes.add(ls.to);
     68                                }
    7069                        }
    7170                        name = "("+nodes.size()+" nodes)";
    7271                }
    73                
    74                 this.name = name;
    7572                icon = ImageProvider.get("data", "way");
    7673        }
    77 
    78        
    79         /**
    80          * Try to read a name from the given properties.
    81          * @param keys The properties to search for a name. Can be <code>null</code>.
    82          * @return If a name could be found, return it here.
    83          */
    84         public String getName(Map<String, String> keys) {
    85                 String name = null;
    86                 if (keys != null) {
    87                         name = keys.get("name");
    88                         if (name == null)
    89                                 name = keys.get("id");
    90                 }
    91                 return name;
    92         }
    93        
    9474}
  • src/org/openstreetmap/josm/data/osm/visitor/SimplePaintVisitor.java

    r64 r66  
    1818public class SimplePaintVisitor implements Visitor {
    1919
     20        private final static Color darkerblue = new Color(0,0,96);
    2021        private final static Color darkblue = new Color(0,0,128);
    2122        private final static Color darkgreen = new Color(0,128,0);
     
    6465        public void visit(Way t) {
    6566                // only to overwrite with blue
     67                Color wayColor = darkblue;
     68                for (LineSegment ls : t.segments) {
     69                        if (ls.incomplete) {
     70                                wayColor = darkerblue;
     71                                break;
     72                        }
     73                }
    6674                for (LineSegment ls : t.segments)
    6775                        if (!ls.isSelected()) // selected already in good color
    68                                 drawLineSegment(ls, t.isSelected() ? Color.WHITE : darkblue);
     76                                drawLineSegment(ls, t.isSelected() ? Color.WHITE : wayColor);
    6977        }
    7078
     
    8593         */
    8694        private void drawLineSegment(LineSegment ls, Color col) {
     95                if (ls.incomplete)
     96                        return;
    8797                if (ls.isSelected())
    8898                        col = Color.WHITE;
    8999                g.setColor(col);
    90                 Point p1 = nc.getScreenPoint(ls.start.coor);
    91                 Point p2 = nc.getScreenPoint(ls.end.coor);
     100                Point p1 = nc.getScreenPoint(ls.from.coor);
     101                Point p2 = nc.getScreenPoint(ls.to.coor);
    92102                g.drawLine(p1.x, p1.y, p2.x, p2.y);
    93103        }
  • src/org/openstreetmap/josm/data/osm/visitor/Visitor.java

    r64 r66  
    1414        void visit(Node n);
    1515        void visit(LineSegment ls);
    16         void visit(Way t);
     16        void visit(Way w);
    1717}
  • src/org/openstreetmap/josm/gui/MapMover.java

    r65 r66  
    8383         * Start movement by setting a new cursor and remember the current mouse
    8484         * position.
    85          * @param e The mouse event that leat to the movement start.
     85         * @param e The mouse event that leat to the movement from.
    8686         */
    8787        private void startMovement(MouseEvent e) {
  • src/org/openstreetmap/josm/gui/MapStatus.java

    r64 r66  
    139139                                                        if (osm.id != 0)
    140140                                                                text.append("<br>id="+osm.id);
    141                                                         if (osm.keys != null)
    142                                                                 for (Entry<String, String> e : osm.keys.entrySet())
    143                                                                         text.append("<br>"+e.getKey()+"="+e.getValue());
     141                                                        for (Entry<String, String> e : osm.entrySet())
     142                                                                text.append("<br>"+e.getKey()+"="+e.getValue());
    144143                                                        final JLabel l = new JLabel("<html>"+text.toString()+"</html>", visitor.icon, JLabel.HORIZONTAL);
    145144                                                        l.setFont(l.getFont().deriveFont(Font.PLAIN));
  • src/org/openstreetmap/josm/gui/NavigatableComponent.java

    r65 r66  
    156156                                        continue;
    157157                                for (LineSegment ls : w.segments) {
    158                                         if (ls.isDeleted())
     158                                        if (ls.isDeleted() || ls.incomplete)
    159159                                                continue;
    160                                         Point A = getScreenPoint(ls.start.coor);
    161                                         Point B = getScreenPoint(ls.end.coor);
     160                                        Point A = getScreenPoint(ls.from.coor);
     161                                        Point B = getScreenPoint(ls.to.coor);
    162162                                        double c = A.distanceSq(B);
    163163                                        double a = p.distanceSq(B);
     
    177177                // line segments
    178178                for (LineSegment ls : Main.main.ds.lineSegments) {
    179                         if (ls.isDeleted())
     179                        if (ls.isDeleted() || ls.incomplete)
    180180                                continue;
    181                         Point A = getScreenPoint(ls.start.coor);
    182                         Point B = getScreenPoint(ls.end.coor);
     181                        Point A = getScreenPoint(ls.from.coor);
     182                        Point B = getScreenPoint(ls.to.coor);
    183183                        double c = A.distanceSq(B);
    184184                        double a = p.distanceSq(B);
     
    225225                        for (LineSegment ls : Main.main.ds.lineSegments)
    226226                                // line segments never match nodes, so they are skipped by contains
    227                                 if (!ls.isDeleted() && (c.contains(ls.start) || c.contains(ls.end)))
     227                                if (!ls.isDeleted() && !ls.incomplete && (c.contains(ls.from) || c.contains(ls.to)))
    228228                                        c.add(ls);
    229229                }
     
    239239                                        continue;
    240240                                for (LineSegment ls : t.segments) {
    241                                         if (!ls.isDeleted() && c.contains(ls)) {
     241                                        if (!ls.isDeleted() && !ls.incomplete && c.contains(ls)) {
    242242                                                c.add(t);
    243243                                                break;
  • src/org/openstreetmap/josm/gui/SelectionManager.java

    r64 r66  
    135135
    136136        /**
    137          * If the correct button, start the "drawing rectangle" mode
     137         * If the correct button, from the "drawing rectangle" mode
    138138         */
    139139        public void mousePressed(MouseEvent e) {
     
    309309         */
    310310        private boolean rectangleContainLineSegment(Rectangle r, boolean alt, LineSegment ls) {
     311                if (ls.incomplete)
     312                        return false;
    311313                if (alt) {
    312                         Point p1 = nc.getScreenPoint(ls.start.coor);
    313                         Point p2 = nc.getScreenPoint(ls.end.coor);
     314                        Point p1 = nc.getScreenPoint(ls.from.coor);
     315                        Point p2 = nc.getScreenPoint(ls.to.coor);
    314316                        if (r.intersectsLine(p1.x, p1.y, p2.x, p2.y))
    315317                                return true;
    316318                } else {
    317                         if (r.contains(nc.getScreenPoint(ls.start.coor))
    318                                         && r.contains(nc.getScreenPoint(ls.end.coor)))
     319                        if (r.contains(nc.getScreenPoint(ls.from.coor))
     320                                        && r.contains(nc.getScreenPoint(ls.to.coor)))
    319321                                return true;
    320322                }
  • src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java

    r64 r66  
    1414import java.awt.event.WindowFocusListener;
    1515import java.util.Collection;
     16import java.util.HashMap;
    1617import java.util.Iterator;
     18import java.util.Map;
    1719import java.util.TreeMap;
    1820import java.util.TreeSet;
     
    6163
    6264        /**
    63          * Watches for double clicks and start editing or new property, depending on the
     65         * Watches for double clicks and from editing or new property, depending on the
    6466         * location, the click was.
    6567         * @author imi
     
    7880                }
    7981        }
    80        
     82
    8183        /**
    8284         * Edit the value in the table row
     
    143145                Vector<String> allKeys = new Vector<String>();
    144146                for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives())
    145                         if (osm.keys != null)
    146                                 allKeys.addAll(osm.keys.keySet());
     147                        allKeys.addAll(osm.keySet());
    147148                for (Iterator<String> it = allKeys.iterator(); it.hasNext();) {
    148149                        String s = it.next();
     
    293294                        propertyTable.getCellEditor().cancelCellEditing();
    294295                data.setRowCount(0);
     296               
     297                Map<String, Integer> valueCount = new HashMap<String, Integer>();
    295298                TreeMap<String, Collection<String>> props = new TreeMap<String, Collection<String>>();
    296299                for (OsmPrimitive osm : newSelection) {
    297                         if (osm.keys != null) {
    298                                 for (Entry<String, String> e : osm.keys.entrySet()) {
    299                                         Collection<String> value = props.get(e.getKey());
    300                                         if (value == null) {
    301                                                 value = new TreeSet<String>();
    302                                                 props.put(e.getKey(), value);
    303                                         }
    304                                         value.add(e.getValue());
     300                        for (Entry<String, String> e : osm.entrySet()) {
     301                                Collection<String> value = props.get(e.getKey());
     302                                if (value == null) {
     303                                        value = new TreeSet<String>();
     304                                        props.put(e.getKey(), value);
    305305                                }
     306                                value.add(e.getValue());
     307                                valueCount.put(e.getKey(), valueCount.containsKey(e.getKey()) ? valueCount.get(e.getKey())+1 : 1);
    306308                        }
    307309                }
     
    309311                        JComboBox value = new JComboBox(e.getValue().toArray());
    310312                        value.setEditable(true);
    311                         value.getEditor().setItem(e.getValue().size() > 1 ? "<different>" : e.getValue().iterator().next());
     313                        value.getEditor().setItem(valueCount.get(e.getKey()) != newSelection.size() ? "<different>" : e.getValue().iterator().next());
    312314                        data.addRow(new Object[]{e.getKey(), value});
    313315                }
  • src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java

    r64 r66  
    9393                                Main.main.ds.clearSelection();
    9494                                for (OsmPrimitive osm : Main.main.ds.allNonDeletedPrimitives()) {
    95                                         if (osm.keys != null) {
    96                                                 for (Entry<String, String> ent : osm.keys.entrySet()) {
    97                                                         if (match(lastSearch, ent.getKey(), ent.getValue())) {
    98                                                                 osm.setSelected(true);
    99                                                                 break;
    100                                                         }
     95                                        for (Entry<String, String> ent : osm.entrySet()) {
     96                                                if (match(lastSearch, ent.getKey(), ent.getValue())) {
     97                                                        osm.setSelected(true);
     98                                                        break;
    10199                                                }
    102100                                        }
  • src/org/openstreetmap/josm/io/GpxReader.java

    r64 r66  
    7373         */
    7474        private Node parseWaypoint(Element e) {
    75                 Node data = new Node();
    76                 data.coor = new GeoPoint(
     75                Node data = new Node(new GeoPoint(
    7776                        Double.parseDouble(e.getAttributeValue("lat")),
    78                         Double.parseDouble(e.getAttributeValue("lon")));
     77                        Double.parseDouble(e.getAttributeValue("lon"))));
    7978               
    8079                for (Object o : e.getChildren()) {
     
    200199                if (e != null) {
    201200                        for (Object o : e.getChildren("property", OSM)) {
    202                                 if (osm.keys == null)
    203                                         osm.keys = new HashMap<String, String>();
    204201                                Element child = (Element)o;
    205202                                String keyname = child.getAttributeValue("key");
     
    208205                                        if (value == null)
    209206                                                value = "";
    210                                         osm.keys.put(keyname, value);
     207                                        osm.put(keyname, value);
    211208                                }
    212209                        }
     
    251248        private void parseKeyValueLink(OsmPrimitive osm, Element e) {
    252249                if (e != null) {
    253                         if (osm.keys == null)
    254                                 osm.keys = new HashMap<String, String>();
    255250                        String link = e.getChildText("type") + ";" + e.getChildText("text");
    256                         osm.keys.put("link", link);
     251                        osm.put("link", link);
    257252                }
    258253        }
  • src/org/openstreetmap/josm/io/GpxWriter.java

    r64 r66  
    127127                        for (LineSegment ls : t.segments) {
    128128                                tElem.getChildren().add(parseLineSegment(ls));
    129                                 unrefNodes.remove(ls.start);
    130                                 unrefNodes.remove(ls.end);
     129                                unrefNodes.remove(ls.from);
     130                                unrefNodes.remove(ls.to);
    131131                                unrefLs.remove(ls);
    132132                        }
     
    141141                        Element t = new Element("trk", GPX);
    142142                        t.getChildren().add(parseLineSegment(ls));
    143                         unrefNodes.remove(ls.start);
    144                         unrefNodes.remove(ls.end);
     143                        unrefNodes.remove(ls.from);
     144                        unrefNodes.remove(ls.to);
    145145                        Element ext = new Element("extensions", GPX);
    146146                        ext.getChildren().add(new Element("segment", JOSM));
     
    180180                Element lsElem = new Element("trkseg", GPX);
    181181                addPropertyExtensions(lsElem, ls.keys, ls);
    182                 lsElem.getChildren().add(parseWaypoint(ls.start, "trkpt"));
    183                 lsElem.getChildren().add(parseWaypoint(ls.end, "trkpt"));
     182                lsElem.getChildren().add(parseWaypoint(ls.from, "trkpt"));
     183                lsElem.getChildren().add(parseWaypoint(ls.to, "trkpt"));
    184184                return lsElem;
    185185        }
  • src/org/openstreetmap/josm/io/OsmReader.java

    r65 r66  
    1515import org.xml.sax.Attributes;
    1616import org.xml.sax.SAXException;
    17 import org.xml.sax.SAXParseException;
    1817
    1918import uk.co.wilson.xml.MinML2;
     
    7776                                        throw new SAXException("Unknown version: "+atts.getValue("version"));
    7877                        } else if (qName.equals("node")) {
    79                                 Node n = new Node();
    80                                 n.coor = new GeoPoint(getDouble(atts, "lat"), getDouble(atts, "lon"));
     78                                Node n = new Node(new GeoPoint(getDouble(atts, "lat"), getDouble(atts, "lon")));
    8179                                current = n;
    8280                                readCommon(atts);
     
    9492                        } else if (qName.equals("seg")) {
    9593                                if (current instanceof Way) {
    96                                         LineSegment ls = lineSegments.get(getLong(atts, "id"));
    97                                         if (ls == null)
    98                                                 fatalError(new SAXParseException("Line segment "+getLong(atts, "id")+" has not been transfered before.", null));
     94                                        long id = getLong(atts, "id");
     95                                        LineSegment ls = lineSegments.get(id);
     96                                        if (ls == null) {
     97                                                ls = new LineSegment(id); // incomplete line segment
     98                                                lineSegments.put(id, ls);
     99                                                adder.visit(ls);
     100                                        }
    99101                                        ((Way)current).segments.add(ls);
    100102                                }
  • src/org/openstreetmap/josm/io/OsmReaderOld.java

    r64 r66  
    44import java.io.Reader;
    55import java.util.Collection;
    6 import java.util.HashMap;
    76import java.util.StringTokenizer;
    87
     
    6362         */
    6463        private Node parseNode(Element e) throws JDOMException {
    65                 Node data = new Node();
    66                 data.coor = new GeoPoint(
     64                Node data = new Node(new GeoPoint(
    6765                        Double.parseDouble(e.getAttributeValue("lat")),
    68                         Double.parseDouble(e.getAttributeValue("lon")));
     66                        Double.parseDouble(e.getAttributeValue("lon"))));
    6967                if (Double.isNaN(data.coor.lat) ||
    7068                                data.coor.lat < -90 || data.coor.lat > 90 ||
     
    175173                String propStr = e.getAttributeValue("tags");
    176174                if (propStr != null && !propStr.equals("")) {
    177                         data.keys = new HashMap<String, String>();
    178175                        StringTokenizer st = new StringTokenizer(propStr, ";");
    179176                        while (st.hasMoreTokens()) {
     
    183180                                int equalPos = next.indexOf('=');
    184181                                if (equalPos == -1)
    185                                         data.keys.put(next, "");
     182                                        data.put(next, "");
    186183                                else {
    187184                                        String keyStr = next.substring(0, equalPos);
    188                                         data.keys.put(keyStr, next.substring(equalPos+1));
     185                                        data.put(keyStr, next.substring(equalPos+1));
    189186                                }
    190187                        }
     
    210207                String key = e.getAttributeValue("key");
    211208                String value = e.getAttributeValue("value");
    212                 if (value != null) {
    213                         if (osm.keys == null)
    214                                 osm.keys = new HashMap<String, String>();
    215                         osm.keys.put(key, value);
    216                 }
     209                if (value != null)
     210                        osm.put(key, value);
    217211        }
    218212
  • src/org/openstreetmap/josm/io/OsmServerWriter.java

    r64 r66  
    1212import java.net.UnknownHostException;
    1313import java.util.Collection;
    14 import java.util.HashMap;
    1514import java.util.LinkedList;
    1615
     
    6766        public void visit(Node n) {
    6867                if (n.id == 0 && !n.isDeleted()) {
    69                         setCredits(n);
     68                        n.put("created_by", "JOSM");
    7069                        sendRequest("PUT", "node", n, true);
    7170                } else if (n.isDeleted()) {
     
    8281        public void visit(LineSegment ls) {
    8382                if (ls.id == 0 && !ls.isDeleted()) {
    84                         setCredits(ls);
     83                        ls.put("created_by", "JOSM");
    8584                        sendRequest("PUT", "segment", ls, true);
    8685                } else if (ls.isDeleted()) {
     
    9796        public void visit(Way w) {
    9897                if (w.id == 0 && !w.isDeleted()) {
    99                         setCredits(w);
     98                        w.put("created_by", "JOSM");
    10099                        sendRequest("PUT", "way", w, true);
    101100                } else if (w.isDeleted()) {
     
    106105                processed.add(w);
    107106        }
    108 
    109         /**
    110          * Add the created_by - property to indicate that JOSM was the
    111          * creating application.
    112          * @param osm The primitive to add the credits to
    113          */
    114         private void setCredits(OsmPrimitive osm) {
    115                 if (osm.keys == null)
    116                         osm.keys = new HashMap<String, String>();
    117                 osm.keys.put("created_by", "JOSM");
    118         }
    119 
    120107
    121108        /**
  • src/org/openstreetmap/josm/io/OsmWriter.java

    r64 r66  
    104104
    105105        public void visit(LineSegment ls) {
     106                if (ls.incomplete)
     107                        throw new IllegalArgumentException("Cannot write an incomplete LineSegment.");
    106108                addCommon(ls, "segment");
    107                 out.print(" from='"+getUsedId(ls.start)+"' to='"+getUsedId(ls.end)+"'");
     109                out.print(" from='"+getUsedId(ls.from)+"' to='"+getUsedId(ls.to)+"'");
    108110                addTags(ls, "segment", true);
    109111        }
     
    164166
    165167        /**
    166          * Add the common part as the start of the tag as well as the id or the action tag.
     168         * Add the common part as the from of the tag as well as the id or the action tag.
    167169         */
    168170        private void addCommon(OsmPrimitive osm, String tagname) {
  • test/org/openstreetmap/josm/test/MergeVisitorTest.java

    r57 r66  
    2525                ls1.id = 3;
    2626
    27                 Node newnode = new Node();
    28                 newnode.coor = new GeoPoint(n[1].coor.lat, n[1].coor.lon);
     27                Node newnode = new Node(new GeoPoint(n[1].coor.lat, n[1].coor.lon));
    2928                LineSegment newls = new LineSegment(n[0], newnode);
    3029
     
    5756                v.fixReferences();
    5857               
    59                 assertSame(ls1.start, ls2.start);
     58                assertSame(ls1.from, ls2.from);
    6059        }
    6160       
  • test/org/openstreetmap/josm/test/framework/DataSetTestCaseHelper.java

    r64 r66  
    5959         */
    6060        public static Node createNode(DataSet ds) {
    61                 Node node = new Node();
    62                 node.coor = new GeoPoint(Math.random(), Math.random());
     61                Node node = new Node(new GeoPoint(Math.random(), Math.random()));
    6362                ds.nodes.add(node);
    6463                return node;
Note: See TracChangeset for help on using the changeset viewer.