Changeset 8 in josm for src/org/openstreetmap/josm


Ignore:
Timestamp:
2005-10-03T04:18:02+02:00 (19 years ago)
Author:
imi
Message:
  • added Selection Dialog
  • added support for graphic engines with a better default engine
  • reorganized data classes with back references
Location:
src/org/openstreetmap/josm
Files:
12 added
18 edited

Legend:

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

    r7 r8  
    130130                if (start != end) {
    131131                        // try to find a line segment
    132                         for (Track t : ds.tracks)
    133                                 for (LineSegment ls : t.segments)
    134                                         if (start == ls.start && end == ls.end) {
     132                        for (Track t : ds.tracks())
     133                                for (LineSegment ls : t.segments())
     134                                        if (start == ls.getStart() && end == ls.getEnd()) {
    135135                                                JOptionPane.showMessageDialog(Main.main, "There is already an line segment with the same direction between the selected nodes.");
    136136                                                return;
     
    142142                        if (((e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0)) {
    143143                                // find a track for the new line segment
    144                                 for (Track t : ds.tracks) {
     144                                for (Track t : ds.tracks()) {
    145145                                        if (t.getEndingNode() == start) {
    146                                                 t.segments.add(ls);
     146                                                t.add(ls);
    147147                                                foundTrack = true;
    148148                                        }
    149149                                }
    150150                                if (!foundTrack) {
    151                                         for (Track t : ds.tracks) {
     151                                        for (Track t : ds.tracks()) {
    152152                                                if (t.getStartingNode() == end) {
    153                                                         t.segments.add(0,ls);
     153                                                        t.addStart(ls);
    154154                                                        foundTrack = true;
    155155                                                }
     
    158158                        }
    159159                        if (!foundTrack)
    160                                 ds.pendingLineSegments.add(ls);
     160                                ds.addPendingLineSegment(ls);
    161161                }
    162162               
  • src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java

    r7 r8  
    8080                Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt);
    8181                for (OsmPrimitive osm : selectionList)
    82                         osm.selected = !ctrl;
     82                        osm.setSelected(!ctrl, ds);
    8383
    8484                mv.repaint(); // from now on, the map has to be repainted.
     
    9595                for (OsmPrimitive osm : selection) {
    9696                        if (osm instanceof Track)
    97                                 lineSegments.addAll(((Track)osm).segments);
     97                                lineSegments.addAll(((Track)osm).segments());
    9898                        else if (osm instanceof LineSegment)
    9999                                lineSegments.add((LineSegment)osm);
    100100                }
    101101                Track t = new Track();
    102                 t.segments.addAll(lineSegments);
    103                 ds.tracks.add(t);
    104                 ds.pendingLineSegments.removeAll(lineSegments);
     102                for (LineSegment ls : lineSegments)
     103                        ds.assignPendingLineSegment(ls, t, true);
     104                ds.addTrack(t);
    105105                ds.clearSelection();
    106106        }
  • src/org/openstreetmap/josm/actions/mapmode/CombineAction.java

    r7 r8  
    136136                        return;
    137137
    138                 if (first == null || second == null) {
     138                if (first == null || second == null || first == second) {
    139139                        first = null;
    140140                        second = null;
     
    160160                                        t2 = (Track)first;
    161161                                }
    162                                 t1.segments.addAll(t2.segments);
     162                                t1.addAll(t2.segments());
    163163                                if (t1.keys == null)
    164164                                        t1.keys = t2.keys;
    165165                                else   
    166166                                        t1.keys.putAll(t2.keys);
    167                                 ds.tracks.remove(t2);
     167                                ds.removeTrack(t2);
    168168                        }
    169169                }
     
    178178         */
    179179        private void combine(LineSegment ls, Track t) {
    180                 if (!ds.pendingLineSegments.contains(first))
     180                if (!ds.pendingLineSegments().contains(ls))
    181181                        throw new IllegalStateException("Should not be able to select non-pending line segments.");
    182182               
    183                 if (t.getStartingNode() == ls.end)
    184                         t.segments.add(0, ls);
    185                 else
    186                         t.segments.add(ls);
    187                 ds.pendingLineSegments.remove(ls);
     183                ds.assignPendingLineSegment(ls, t, t.getStartingNode() != ls.getEnd());
    188184        }
    189185
     
    203199
    204200                Graphics g = mv.getGraphics();
    205                 g.setColor(draw ? Color.WHITE : Color.GRAY); // HACK
     201                g.setColor(Color.BLACK);
     202                g.setXORMode(Color.WHITE);
    206203                draw(g, first);
    207204                draw(g, second);
     
    217214                if (osm instanceof LineSegment) {
    218215                        LineSegment ls = (LineSegment)osm;
    219                         Point start = mv.getScreenPoint(ls.start.coor);
    220                         Point end = mv.getScreenPoint(ls.end.coor);
    221                         if (mv.dataSet.pendingLineSegments.contains(osm) && g.getColor() == Color.GRAY) {
    222                                 // HACK
    223                                 g.setColor(Color.LIGHT_GRAY);
     216                        Point start = mv.getScreenPoint(ls.getStart().coor);
     217                        Point end = mv.getScreenPoint(ls.getEnd().coor);
     218                        if (mv.dataSet.pendingLineSegments().contains(osm) && g.getColor() == Color.GRAY)
    224219                                g.drawLine(start.x, start.y, end.x, end.y);
    225                                 g.setColor(Color.GRAY);
    226                         } else
     220                        else
    227221                                g.drawLine(start.x, start.y, end.x, end.y);
    228222                } else if (osm instanceof Track) {
    229                         for (LineSegment ls : ((Track)osm).segments)
     223                        for (LineSegment ls : ((Track)osm).segments())
    230224                                draw(g, ls);
    231225                }
  • src/org/openstreetmap/josm/actions/mapmode/DebugAction.java

    r7 r8  
    4848                Graphics g = mapFrame.mapView.getGraphics();
    4949                g.setColor(Color.WHITE);
    50                 for (Track t :mapFrame.mapView.dataSet.tracks)
    51                         for (LineSegment ls : t.segments) {
    52                                 Point A = mapFrame.mapView.getScreenPoint(ls.start.coor);
    53                                 Point B = mapFrame.mapView.getScreenPoint(ls.end.coor);
     50                for (Track t :mapFrame.mapView.dataSet.tracks())
     51                        for (LineSegment ls : t.segments()) {
     52                                Point A = mapFrame.mapView.getScreenPoint(ls.getStart().coor);
     53                                Point B = mapFrame.mapView.getScreenPoint(ls.getEnd().coor);
    5454                                Point C = e.getPoint();
    5555                                Rectangle r = new Rectangle(A.x, A.y, B.x-A.x, B.y-A.y);
  • src/org/openstreetmap/josm/actions/mapmode/DeleteAction.java

    r7 r8  
    55import java.util.ArrayList;
    66import java.util.HashMap;
    7 import java.util.Iterator;
     7import java.util.LinkedList;
    88import java.util.Map;
    99
     
    133133                if (osm instanceof Node) {
    134134                        // delete any track and line segment the node is in.
    135                         for (Track t : ds.tracks)
    136                                 for (LineSegment ls : t.segments)
    137                                         if (ls.start == osm || ls.end == osm)
     135                        for (Track t : ds.tracks())
     136                                for (LineSegment ls : t.segments())
     137                                        if (ls.getStart() == osm || ls.getEnd() == osm)
    138138                                                tracksToDelete.add(t);
    139                         for (LineSegment ls : ds.pendingLineSegments)
    140                                 if (ls.start == osm || ls.end == osm)
     139                        for (LineSegment ls : ds.pendingLineSegments())
     140                                if (ls.getStart() == osm || ls.getEnd() == osm)
    141141                                        lineSegmentsToDelete.add(ls);
    142142                               
     
    144144                        LineSegment lineSegment = (LineSegment)osm;
    145145                        lineSegmentsToDelete.add(lineSegment);
    146                         for (Track t : ds.tracks)
    147                                 for (LineSegment ls : t.segments)
     146                        for (Track t : ds.tracks())
     147                                for (LineSegment ls : t.segments())
    148148                                        if (lineSegment == ls)
    149149                                                tracksToDelete.add(t);
     
    154154                ArrayList<Node> checkUnreferencing = new ArrayList<Node>();
    155155                for (Track t : tracksToDelete) {
    156                         for (LineSegment ls : t.segments) {
    157                                 checkUnreferencing.add(ls.start);
    158                                 checkUnreferencing.add(ls.end);
     156                        for (LineSegment ls : t.segments()) {
     157                                checkUnreferencing.add(ls.getStart());
     158                                checkUnreferencing.add(ls.getEnd());
    159159                        }
    160160                }
    161161                for (LineSegment ls : lineSegmentsToDelete) {
    162                         checkUnreferencing.add(ls.start);
    163                         checkUnreferencing.add(ls.end);
     162                        checkUnreferencing.add(ls.getStart());
     163                        checkUnreferencing.add(ls.getEnd());
    164164                }
    165165               
    166166                // delete tracks and areas
    167                 ds.tracks.removeAll(tracksToDelete);
    168                 ds.pendingLineSegments.removeAll(lineSegmentsToDelete);
     167                for (Track t : tracksToDelete)
     168                        ds.removeTrack(t);
     169                for (LineSegment ls : lineSegmentsToDelete)
     170                        ds.destroyPendingLineSegment(ls);
    169171
    170172                // removing all unreferenced nodes
     
    198200                        ds.nodes.remove(n);
    199201                } else if (osm instanceof LineSegment) {
    200                         for (Iterator<Track> it = ds.tracks.iterator(); it.hasNext();) {
    201                                 Track t = it.next();
    202                                 t.segments.remove(osm);
    203                                 if (t.segments.isEmpty())
    204                                         it.remove();
    205                         }
    206                         ds.pendingLineSegments.remove(osm);
     202                        LinkedList<Track> tracksToDelete = new LinkedList<Track>();
     203                        for (Track t : ds.tracks()) {
     204                                t.remove((LineSegment)osm);
     205                                if (t.segments().isEmpty())
     206                                        tracksToDelete.add(t);
     207                        }
     208                        for (Track t : tracksToDelete)
     209                                ds.removeTrack(t);
     210                        ds.destroyPendingLineSegment((LineSegment)osm);
    207211                } else if (osm instanceof Track) {
    208                         ds.tracks.remove(osm);
    209                         ds.pendingLineSegments.addAll(((Track)osm).segments);
     212                        ds.removeTrack((Track)osm);
     213                        for (LineSegment ls : ((Track)osm).segments())
     214                                ds.addPendingLineSegment(ls);
    210215                }
    211216        }
     
    218223         */
    219224        private boolean isReferenced(Node n) {
    220                 for (Track t : ds.tracks)
    221                         for (LineSegment ls : t.segments)
    222                                 if (ls.start == n || ls.end == n)
     225                for (Track t : ds.tracks())
     226                        for (LineSegment ls : t.segments())
     227                                if (ls.getStart() == n || ls.getEnd() == n)
    223228                                        return true;
    224                 for (LineSegment ls : ds.pendingLineSegments)
    225                         if (ls.start == n || ls.end == n)
     229                for (LineSegment ls : ds.pendingLineSegments())
     230                        if (ls.getStart() == n || ls.getEnd() == n)
    226231                                return true;
    227232                // TODO areas
     
    240245        private String combine(Node n) {
    241246                // first, check for pending line segments
    242                 for (LineSegment ls : ds.pendingLineSegments)
    243                         if (n == ls.start || n == ls.end)
     247                for (LineSegment ls : ds.pendingLineSegments())
     248                        if (n == ls.getStart() || n == ls.getEnd())
    244249                                return "Node used by a line segment which is not part of any track. Remove this first.";
    245250               
     
    253258                HashMap<ArrayList<LineSegment>, Track> lineSegments = new HashMap<ArrayList<LineSegment>, Track>();
    254259               
    255                 for (Track t : ds.tracks) {
     260                for (Track t : ds.tracks()) {
    256261                        ArrayList<LineSegment> current = new ArrayList<LineSegment>();
    257                         for (LineSegment ls : t.segments)
    258                                 if (ls.start == n || ls.end == n)
     262                        for (LineSegment ls : t.segments())
     263                                if (ls.getStart() == n || ls.getEnd() == n)
    259264                                        current.add(ls);
    260265                        if (!current.isEmpty()) {
     
    262267                                        return "Node used by more than two line segments.";
    263268                                if (current.size() == 1 &&
    264                                                 (current.get(0) == t.segments.get(0) || current.get(0) == t.segments.get(t.segments.size()-1)))
     269                                                (current.get(0) == t.getStartingSegment() || current.get(0) == t.getEndingSegment()))
    265270                                        pendingLineSegmentsForTrack.add(current.get(0));
    266                                 else if (current.get(0).end != current.get(1).start &&
    267                                                 current.get(1).end != current.get(0).start)
     271                                else if (current.get(0).getEnd() != current.get(1).getStart() &&
     272                                                current.get(1).getEnd() != current.get(0).getStart())
    268273                                        return "Node used by line segments that points together.";
    269274                                else if (!current.get(0).keyPropertiesMergable(current.get(1)))
     
    276281                // try to combine tracks
    277282                ArrayList<Track> tracks = new ArrayList<Track>();
    278                 for (Track t : ds.tracks)
    279                         if (!t.segments.isEmpty() && (t.segments.get(0).start == n || t.segments.get(t.segments.size()-1).end == n))
     283                for (Track t : ds.tracks())
     284                        if (t.getStartingNode() == n || t.getEndingNode() == n)
    280285                                tracks.add(t);
    281286                if (!tracks.isEmpty()) {
     
    286291                        Track t1 = tracks.get(0);
    287292                        Track t2 = tracks.get(1);
    288                         if (t1.segments.get(0).start != t2.segments.get(t2.segments.size()-1).end &&
    289                                         t2.segments.get(0).start != t1.segments.get(t1.segments.size()-1).end) {
    290                                 if (t1.segments.get(0).start == t2.segments.get(t2.segments.size()-1).start ||
    291                                                 t1.segments.get(0).end == t2.segments.get(t2.segments.size()-1).end)
     293                        if (t1.getStartingNode() != t2.getEndingNode() &&
     294                                        t2.getStartingNode() != t1.getEndingNode()) {
     295                                if (t1.getStartingNode() == t2.getStartingNode() ||
     296                                                t1.getEndingNode() == t2.getEndingNode())
    292297                                        return "Node used by tracks that point together.";
    293298                                return "Node used by tracks that cannot be combined.";
     
    301306                        LineSegment l1 = pendingLineSegmentsForTrack.get(0);
    302307                        LineSegment l2 = pendingLineSegmentsForTrack.get(1);
    303                         if (l1.start == l2.start || l1.end == l2.end)
     308                        if (l1.getStart() == l2.getStart() || l1.getEnd() == l2.getEnd())
    304309                                return "Node used by line segments that points together.";
    305                         if (l1.start == l2.end || l2.start == l1.end)
     310                        if (l1.getStart() == l2.getEnd() || l2.getStart() == l1.getEnd())
    306311                                pendingLineSegmentsForTrack.clear(); // resolved.
    307312                }
     
    316321                        LineSegment first = list.get(0);
    317322                        LineSegment second = list.get(1);
    318                         if (first.start == second.end) {
     323                        if (first.getStart() == second.getEnd()) {
    319324                                first = second;
    320325                                second = list.get(0);
    321326                        }
    322                         first.end = second.end;
     327                        first.setEnd(second.getEnd());
    323328                        first.keys = mergeKeys(first.keys, second.keys);
    324                         lineSegments.get(list).segments.remove(second);
     329                        lineSegments.get(list).remove(second);
    325330                }
    326331               
     
    329334                        Track first = tracks.get(0);
    330335                        Track second = tracks.get(1);
    331                         if (first.segments.get(0).start == second.segments.get(second.segments.size()-1).end) {
     336                        if (first.getStartingNode() == second.getEndingNode()) {
    332337                                first = second;
    333338                                second = tracks.get(0);
    334339                        }
    335340                        // concatenate the line segments.
    336                         LineSegment lastOfFirst = first.segments.get(first.segments.size()-1);
    337                         LineSegment firstOfSecond = second.segments.get(0);
    338                         lastOfFirst.end = firstOfSecond.end;
     341                        LineSegment lastOfFirst = first.getEndingSegment();
     342                        LineSegment firstOfSecond = second.getStartingSegment();
     343                        lastOfFirst.setEnd(firstOfSecond.getEnd());
    339344                        lastOfFirst.keys = mergeKeys(lastOfFirst.keys, firstOfSecond.keys);
    340                         second.segments.remove(firstOfSecond);
     345                        second.remove(firstOfSecond);
    341346                        // move the remaining line segments to first track.
    342                         first.segments.addAll(second.segments);
    343                         ds.tracks.remove(second);
     347                        first.addAll(second.segments());
     348                        ds.removeTrack(second);
    344349                }
    345350               
  • src/org/openstreetmap/josm/actions/mapmode/MoveAction.java

    r7 r8  
    113113                        OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0);
    114114                        if (osm != null)
    115                                 osm.selected = true;
     115                                osm.setSelected(true, ds);
    116116                        singleOsmPrimitive = osm;
    117117                        mv.repaint();
     
    131131                mv.setCursor(oldCursor);
    132132                if (singleOsmPrimitive != null) {
    133                         singleOsmPrimitive.selected = false;
     133                        singleOsmPrimitive.setSelected(false, ds);
    134134                        mv.repaint();
    135135                }
  • src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java

    r7 r8  
    9191                Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt);
    9292                for (OsmPrimitive osm : selectionList)
    93                         osm.selected = !ctrl;
     93                        osm.setSelected(!ctrl, ds);
    9494                mv.repaint();
    9595        }
  • src/org/openstreetmap/josm/data/osm/DataSet.java

    r7 r8  
    22
    33import java.util.Collection;
     4import java.util.Collections;
    45import java.util.HashSet;
    56import java.util.LinkedList;
    67
    78import org.openstreetmap.josm.data.Bounds;
     9import org.openstreetmap.josm.data.SelectionTracker;
    810
    911/**
     
    1719 * @author imi
    1820 */
    19 public class DataSet implements Cloneable {
     21public class DataSet extends SelectionTracker implements Cloneable {
    2022
    2123        /**
     
    3032         * are in this list but are in no track.
    3133         */
    32         public Collection<LineSegment> pendingLineSegments = new LinkedList<LineSegment>();
     34        private Collection<LineSegment> pendingLineSegments = new LinkedList<LineSegment>();
    3335
    3436        /**
     
    3941         * track list.
    4042         */
    41         public Collection<Track> tracks;
     43        private Collection<Track> tracks = new LinkedList<Track>();
     44
     45        /**
     46         * Add the track to the tracklist.
     47         */
     48        public void addTrack(Track t) {
     49                tracks.add(t);
     50        }
     51        /**
     52         * Remove the track from the tracklist.
     53         */
     54        public void removeTrack(Track t) {
     55                t.destroy();
     56                tracks.remove(t);
     57        }
     58        /**
     59         * Return a read-only collection of all tracks
     60         */
     61        public Collection<Track> tracks() {
     62                return Collections.unmodifiableCollection(tracks);
     63        }
     64
     65        /**
     66         * Add a newly created line segment to the pending lines list.
     67         */
     68        public void addPendingLineSegment(LineSegment ls) {
     69                pendingLineSegments.add(ls);
     70        }
     71        /**
     72         * Remove a line segment from the pending lines list, because it has been
     73         * assigned to the track.
     74         * @param ls The line segment from the pending list
     75         * @param t The track, that will hold the line segment
     76         * @param end <code>true</code> to attach on the end. <code>false</code>
     77         *              to attach on the beginning.
     78         */
     79        public void assignPendingLineSegment(LineSegment ls, Track t, boolean end) {
     80                pendingLineSegments.remove(ls);
     81                if (end)
     82                        t.add(ls);
     83                else
     84                        t.addStart(ls);
     85        }
     86        /**
     87         * Delete the pending line segment without moving it anywhere.
     88         */
     89        public void destroyPendingLineSegment(LineSegment ls) {
     90                pendingLineSegments.remove(ls);
     91                ls.destroy();
     92        }
     93        /**
     94         * Return an read-only iterator over all pending line segments.
     95         */
     96        public Collection<LineSegment> pendingLineSegments() {
     97                return Collections.unmodifiableCollection(pendingLineSegments);
     98        }
    4299
    43100        /**
     
    73130
    74131        /**
    75          * Return all tracks that contain the node. If nothing found, an empty array
    76          * is returned.
    77          *
    78          * @param node This node is searched.
    79          * @return All tracks, that reference the node in one of its line segments.
    80          */
    81         public Collection<Track> getReferencedTracks(Node n) {
    82                 Collection<Track> all = new LinkedList<Track>();
    83                 for (Track t : tracks) {
    84                         for (LineSegment ls : t.segments) {
    85                                 if (ls.start == n || ls.end == n) {
    86                                         all.add(t);
    87                                         break;
    88                                 }
    89                         }
    90                 }
    91                 return all;
    92         }
    93        
    94         /**
    95132         * Return the bounds of this DataSet, depending on lat/lon values.
    96133         * The min of the return value is the upper left GeoPoint, the max the lower
     
    131168                clearSelection(tracks);
    132169                for (Track t : tracks)
    133                         clearSelection(t.segments);
     170                        clearSelection(t.segments());
    134171        }
    135172
     
    138175         * @return List of all selected objects.
    139176         */
     177        @Override
    140178        public Collection<OsmPrimitive> getSelected() {
    141179                Collection<OsmPrimitive> sel = getSelected(nodes);
     
    143181                sel.addAll(getSelected(tracks));
    144182                for (Track t : tracks)
    145                         sel.addAll(getSelected(t.segments));
     183                        sel.addAll(getSelected(t.segments()));
    146184                return sel;
    147185        }
    148        
     186
    149187        /**
    150188         * Remove the selection from every value in the collection.
     
    155193                        return;
    156194                for (OsmPrimitive osm : list) {
    157                         osm.selected = false;
     195                        osm.setSelected(false, this);
    158196                        if (osm.keys != null)
    159197                                clearSelection(osm.keys.keySet());
     
    170208                        return sel;
    171209                for (OsmPrimitive osm : list) {
    172                         if (osm.selected)
     210                        if (osm.isSelected())
    173211                                sel.add(osm);
    174212                        if (osm.keys != null)
  • src/org/openstreetmap/josm/data/osm/Key.java

    r7 r8  
    22
    33import java.util.Collection;
     4import java.util.HashMap;
    45import java.util.LinkedList;
     6import java.util.Map;
     7
     8import org.openstreetmap.josm.data.osm.visitor.Visitor;
    59
    610
     
    1519         * The key's name
    1620         */
    17         public String name;
     21        public final String name;
    1822
     23        /**
     24         * All keys are stored here.
     25         */
     26        private static Map<String, Key> allKeys = new HashMap<String, Key>();
     27       
     28        /**
     29         * Generate a key with the given name. You cannot call this directly but
     30         * have to use the static constructor. This makes sure, you get every key
     31         * only once.
     32         */
     33        private Key(String name) {
     34                this.name = name;
     35        }
     36
     37        /**
     38         * Get an instance of the key with the given name.
     39         * @param name  The name of the key to get.
     40         * @return An shared instance of the key with the given name.
     41         */
     42        public static Key get(String name) {
     43                Key key = allKeys.get(name);
     44                if (key == null) {
     45                        key = new Key(name);
     46                        allKeys.put(name, key);
     47                }
     48                return key;
     49        }
     50       
    1951        /**
    2052         * Return an empty list, since keys cannot have nodes.
     
    3971                return name.hashCode();
    4072        }
     73
     74        @Override
     75        public void visit(Visitor visitor) {
     76                visitor.visit(this);
     77        }
    4178}
  • src/org/openstreetmap/josm/data/osm/LineSegment.java

    r7 r8  
    22
    33import java.util.Collection;
     4import java.util.Collections;
    45import java.util.LinkedList;
     6
     7import org.openstreetmap.josm.data.osm.visitor.Visitor;
    58
    69
     
    1316
    1417        /**
     18         * The starting node of the line segment
     19         */
     20        private Node start;
     21       
     22        /**
     23         * The ending node of the line segment
     24         */
     25        private Node end;
     26
     27        /**
     28         * The tracks, this line segment is part of.
     29         */
     30        transient Collection<Track> parent = new LinkedList<Track>();
     31
     32        /**
    1533         * Create an line segment from the given starting and ending node
    1634         * @param start Starting node of the line segment.
     
    2038                this.start = start;
    2139                this.end = end;
     40                start.parentSegment.add(this);
     41                end.parentSegment.add(this);
    2242        }
    2343
    2444        /**
    25          * The starting node of the line segment
     45         * Return all parent tracks this line segment is part of. The list is readonly.
    2646         */
    27         public Node start;
    28        
     47        public Collection<Track> getParents() {
     48                return Collections.unmodifiableCollection(parent);
     49        }
     50
     51        public void setStart(Node start) {
     52                this.start.parentSegment.remove(this);
     53                this.start = start;
     54                start.parentSegment.add(this);
     55        }
     56        public Node getStart() {
     57                return start;
     58        }
     59        public void setEnd(Node end) {
     60                this.end.parentSegment.remove(this);
     61                this.end = end;
     62                end.parentSegment.add(this);
     63        }
     64        public Node getEnd() {
     65                return end;
     66        }
     67
    2968        /**
    30          * The ending node of the line segment
     69         * The LineSegment is going to be destroyed. Unlink all back references.
    3170         */
    32         public Node end;
     71        void destroy() {
     72                start.parentSegment.remove(this);
     73                end.parentSegment.remove(this);
     74        }
    3375
    3476        /**
     
    3880        public Collection<Node> getAllNodes() {
    3981                LinkedList<Node> nodes = new LinkedList<Node>();
    40                 nodes.add(start);
    41                 nodes.add(end);
     82                nodes.add(getStart());
     83                nodes.add(getEnd());
    4284                return nodes;
    4385        }
     
    5294                        return false;
    5395                return super.equals(obj) &&
    54                         start.equals(((LineSegment)obj).start) &&
    55                         end.equals(((LineSegment)obj).end);
     96                        getStart().equals(((LineSegment)obj).getStart()) &&
     97                        getEnd().equals(((LineSegment)obj).getEnd());
    5698        }
    5799
    58100        @Override
    59101        public int hashCode() {
    60                 return super.hashCode() + start.hashCode() + end.hashCode();
     102                return super.hashCode() + getStart().hashCode() + getEnd().hashCode();
     103        }
     104
     105        @Override
     106        public void visit(Visitor visitor) {
     107                visitor.visit(this);
    61108        }
    62109}       
  • src/org/openstreetmap/josm/data/osm/Node.java

    r7 r8  
    22
    33import java.util.Collection;
     4import java.util.Collections;
    45import java.util.LinkedList;
    56
    67import org.openstreetmap.josm.data.GeoPoint;
     8import org.openstreetmap.josm.data.osm.visitor.Visitor;
    79
    810
     
    1921        public GeoPoint coor;
    2022
     23        /**
     24         * The list of line segments, this node is part of.
     25         */
     26        transient Collection<LineSegment> parentSegment = new LinkedList<LineSegment>();
     27
     28        /**
     29         * Returns a read-only list of all segments this node is in.
     30         * @return A list of all segments. Readonly.
     31         */
     32        public Collection<LineSegment> getParentSegments() {
     33                return Collections.unmodifiableCollection(parentSegment);
     34        }
     35       
    2136        /**
    2237         * Nodes are equal when their coordinates are equal.
     
    4964                return nodes;
    5065        }
    51        
    52        
     66
     67        @Override
     68        public void visit(Visitor visitor) {
     69                visitor.visit(this);
     70        }
    5371}
  • src/org/openstreetmap/josm/data/osm/OsmPrimitive.java

    r7 r8  
    33import java.util.Collection;
    44import java.util.Map;
     5
     6import org.openstreetmap.josm.data.osm.visitor.Visitor;
    57
    68
     
    2628         * If set to true, this object is currently selected.
    2729         */
    28         transient public boolean selected = false;
     30        transient private boolean selected = false;
    2931
    3032        /**
    3133         * Return a list of all nodes, this osmPrimitive consists of. Does return
    3234         * an empty list, if it is an primitive that cannot have nodes (e.g. Key)
     35         * TODO replace with visitor
    3336         */
    3437        abstract public Collection<Node> getAllNodes();
    3538
     39        /**
     40         * Implementation of the visitor scheme. Subclases have to call the correct
     41         * visitor function.
     42         * @param visitor The visitor from which the visit() function must be called.
     43         */
     44        abstract public void visit(Visitor visitor);
     45       
    3646        /**
    3747         * Return <code>true</code>, if either <code>this.keys</code> and
     
    7989                return keys == null ? 0 : keys.hashCode();
    8090        }
     91
     92        /**
     93         * Mark the primitive as selected or not selected and fires a selection
     94         * changed later, if the value actualy changed.
     95         * @param selected Whether the primitive should be selected or not.
     96         * @param ds The dataSet, this primitive is in.
     97         */
     98        public void setSelected(boolean selected, DataSet ds) {
     99                if (selected != this.selected)
     100                        ds.fireSelectionChanged();
     101                this.selected = selected;
     102        }
     103
     104        /**
     105         * @return Return whether the primitive is selected on screen.
     106         */
     107        public boolean isSelected() {
     108                return selected;
     109        }
    81110}
  • src/org/openstreetmap/josm/data/osm/Track.java

    r7 r8  
    33import java.util.ArrayList;
    44import java.util.Collection;
     5import java.util.Collections;
    56import java.util.List;
     7
     8import org.openstreetmap.josm.data.osm.visitor.Visitor;
    69
    710/**
     
    1518         * All track segments in this track
    1619         */
    17         public final List<LineSegment> segments = new ArrayList<LineSegment>();
     20        private final List<LineSegment> segments = new ArrayList<LineSegment>();
     21
     22       
     23        /**
     24         * Add the line segment to the track.
     25         */
     26        public void add(LineSegment ls) {
     27                segments.add(ls);
     28                ls.parent.add(this);
     29        }
     30
     31        /**
     32         * Add the line segment at first position to the track. First position means,
     33         * the line segment's start becomes the starting node.
     34         * @param ls The line segment to add at starting position.
     35         * @see #getStartingNode()
     36         */
     37        public void addStart(LineSegment ls) {
     38                segments.add(ls);
     39                ls.parent.add(this);
     40        }
     41
     42        /**
     43         * Add all LineSegment's to the list of segments.
     44         * @param lineSegments The line segments to add.
     45         */
     46        public void addAll(Collection<? extends LineSegment> lineSegments) {
     47                segments.addAll(lineSegments);
     48                for (LineSegment ls : lineSegments)
     49                        ls.parent.add(this);
     50        }
     51       
     52        /**
     53         * Remove the line segment from the track.
     54         */
     55        public void remove(LineSegment ls) {
     56                if (segments.remove(ls))
     57                        if (!ls.parent.remove(this))
     58                                throw new IllegalStateException("Parent violation detected.");
     59        }
     60
     61        /**
     62         * Return an read-only collection. Do not alter the object returned.
     63         * @return The read-only Collection of all segments.
     64         */
     65        public Collection<LineSegment> segments() {
     66                return Collections.unmodifiableCollection(segments);
     67        }
    1868
    1969        /**
     
    2676                        nodes.addAll(ls.getAllNodes());
    2777                return nodes;
     78        }
     79        /**
     80         * The track is going to be destroyed. Unlink all back references.
     81         */
     82        void destroy() {
     83                for (LineSegment ls : segments) {
     84                        ls.parent.remove(this);
     85                        if (ls.parent.isEmpty())
     86                                ls.destroy();
     87                }
     88                segments.clear();
    2889        }
    2990
     
    67128                if (segments.isEmpty())
    68129                        return null;
    69                 return segments.get(segments.size()-1).end;
     130                return segments.get(segments.size()-1).getEnd();
     131        }
     132       
     133        /**
     134         * Return the last segment.
     135         * @see #getEndingNode()
     136         */
     137        public LineSegment getEndingSegment() {
     138                if (segments.isEmpty())
     139                        return null;
     140                return segments.get(segments.size()-1);
    70141        }
    71142
     
    82153                if (segments.isEmpty())
    83154                        return null;
    84                 return segments.get(0).start;
     155                return segments.get(0).getStart();
     156        }
     157       
     158        /**
     159         * Return the first segment.
     160         * @see #getStartingNode()
     161         */
     162        public LineSegment getStartingSegment() {
     163                if (segments.isEmpty())
     164                        return null;
     165                return segments.get(0);
     166        }
     167
     168        @Override
     169        public void visit(Visitor visitor) {
     170                visitor.visit(this);
    85171        }
    86172}
  • src/org/openstreetmap/josm/gui/IconToggleButton.java

    r7 r8  
    4343
    4444        public void propertyChange(PropertyChangeEvent evt) {
    45                 if (evt.getPropertyName() == "active")
     45                if (evt.getPropertyName().equals("active"))
    4646                        setSelected((Boolean)evt.getNewValue());
    4747        }
  • src/org/openstreetmap/josm/gui/MapFrame.java

    r7 r8  
    33import java.awt.BorderLayout;
    44import java.awt.Component;
    5 import java.awt.event.ActionEvent;
    6 import java.awt.event.ActionListener;
    7 import java.awt.event.KeyEvent;
     5import java.awt.event.WindowAdapter;
     6import java.awt.event.WindowEvent;
     7import java.beans.PropertyChangeEvent;
     8import java.beans.PropertyChangeListener;
    89
    9 import javax.swing.AbstractAction;
    1010import javax.swing.AbstractButton;
    11 import javax.swing.BorderFactory;
    12 import javax.swing.Box;
    13 import javax.swing.BoxLayout;
    1411import javax.swing.ButtonGroup;
    15 import javax.swing.ImageIcon;
    16 import javax.swing.JComboBox;
    17 import javax.swing.JComponent;
    18 import javax.swing.JDialog;
    19 import javax.swing.JLabel;
    2012import javax.swing.JPanel;
    2113import javax.swing.JToggleButton;
    2214import javax.swing.JToolBar;
    23 import javax.swing.border.Border;
    24 import javax.swing.event.ChangeEvent;
    25 import javax.swing.event.ChangeListener;
    2615
    2716import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction;
     
    3524import org.openstreetmap.josm.actions.mapmode.SelectionAction;
    3625import org.openstreetmap.josm.actions.mapmode.ZoomAction;
    37 import org.openstreetmap.josm.data.Preferences;
    3826import org.openstreetmap.josm.data.osm.DataSet;
    39 import org.openstreetmap.josm.data.projection.Projection;
     27import org.openstreetmap.josm.gui.dialogs.PropertiesDialog;
     28import org.openstreetmap.josm.gui.dialogs.SelectionListDialog;
    4029
    4130/**
     
    4635 */
    4736public class MapFrame extends JPanel {
    48 
    49         /**
    50          * Open the properties page
    51          * @author imi
    52          */
    53         public class PropertiesAction extends AbstractAction {
    54                 private JDialog dlg;
    55                 public PropertiesAction() {
    56                         super("Properties", new ImageIcon("images/properties.png"));
    57                         putValue(MNEMONIC_KEY, KeyEvent.VK_P);
    58                 }
    59                 public void actionPerformed(ActionEvent e) {
    60                         if (dlg != null) {
    61                                 dlg.setVisible(true);
    62                                 dlg.requestFocus();
    63                                 return;
    64                         }
    65                         dlg = new JDialog(Main.main, "Properties of "+Main.main.getNameOfLoadedMapFrame(), false);
    66                         final Border panelBorder = BorderFactory.createEmptyBorder(5,0,0,0);
    67                         Box panel = Box.createVerticalBox();
    68 
    69                         // making an array of all projections and the current one within
    70                         Projection[] allProjections = Preferences.allProjections.clone();
    71                         for (int i = 0; i < allProjections.length; ++i)
    72                                 if (allProjections[i].getClass() == mapView.getProjection().getClass())
    73                                         allProjections[i] = mapView.getProjection();
    74                        
    75                         // projection
    76                         Box projectionPanel = Box.createHorizontalBox();
    77                         projectionPanel.setBorder(panelBorder);
    78                         projectionPanel.add(new JLabel("Projection"));
    79                         final JComboBox projectionCombo = new JComboBox(allProjections);
    80                         projectionPanel.add(projectionCombo);
    81                         panel.add(projectionPanel);
    82                         final JPanel configurationPanel = new JPanel();
    83                         configurationPanel.setLayout(new BoxLayout(configurationPanel, BoxLayout.X_AXIS));
    84                        
    85                         // projections details
    86                         projectionCombo.addActionListener(new ActionListener(){
    87                                 public void actionPerformed(ActionEvent e) {
    88                                         configurationPanel.removeAll();
    89                                         mapView.setProjection((Projection)projectionCombo.getSelectedItem());
    90                                         JComponent panel = mapView.getProjection().getConfigurationPanel();
    91                                         if (panel != null) {
    92                                                 panel.setBorder(panelBorder);
    93                                                 configurationPanel.add(panel);
    94                                         }
    95                                         dlg.pack();
    96                                 }
    97                         });
    98                         panel.add(configurationPanel);
    99                         projectionCombo.setSelectedItem(mapView.getProjection());
    100                        
    101                         panel.setBorder(BorderFactory.createEmptyBorder(10,10,10,10));
    102                         dlg.setContentPane(panel);
    103                         dlg.pack();
    104                         dlg.setResizable(false);
    105                         dlg.setVisible(true);
    106                 }
    107         }
    10837
    10938        /**
     
    15584                autoScaleButton.setText(null);
    15685                autoScaleButton.setSelected(mapView.isAutoScale());
    157                 mapView.addChangeListener(new ChangeListener(){
    158                         public void stateChanged(ChangeEvent e) {
    159                                 autoScaleButton.setSelected(mapView.isAutoScale());
     86                mapView.addPropertyChangeListener(new PropertyChangeListener(){
     87                        public void propertyChange(PropertyChangeEvent evt) {
     88                                if (evt.getPropertyName().equals("autoScale"))
     89                                        autoScaleButton.setSelected(mapView.isAutoScale());
    16090                        }
    16191                });
    16292
    16393                // properties
    164                 toolBarActions.add(new IconToggleButton(this, new PropertiesAction()));
     94                toolBarActions.add(new IconToggleButton(this, new PropertiesDialog(this)));
     95               
     96                // selection dialog
     97                SelectionListDialog selectionList = new SelectionListDialog(dataSet);
     98                final IconToggleButton buttonSelection = new IconToggleButton(this, selectionList);
     99                selectionList.addWindowListener(new WindowAdapter(){
     100                        @Override
     101                        public void windowClosing(WindowEvent e) {
     102                                buttonSelection.setSelected(false);
     103                        }
     104                });
     105                toolBarActions.add(buttonSelection);
    165106        }
    166107
  • src/org/openstreetmap/josm/gui/MapView.java

    r7 r8  
    11package org.openstreetmap.josm.gui;
    22
    3 import java.awt.Color;
    43import java.awt.Graphics;
    54import java.awt.Point;
     
    87import java.awt.event.ComponentListener;
    98import java.awt.event.KeyEvent;
    10 import java.util.HashSet;
    11 import java.util.LinkedList;
    12 import java.util.List;
    13 import java.util.Set;
    149
    1510import javax.swing.AbstractAction;
     
    2722import org.openstreetmap.josm.data.osm.Track;
    2823import org.openstreetmap.josm.data.projection.Projection;
     24import org.openstreetmap.josm.gui.engine.Engine;
     25import org.openstreetmap.josm.gui.engine.SimpleEngine;
    2926
    3027/**
     
    8178        public final DataSet dataSet;
    8279
     80        /**
     81         * The drawing engine.
     82         */
     83        private Engine engine;
    8384       
    8485        /**
     
    9495                // initialize the projection
    9596                setProjection(Main.pref.projection.clone());
     97               
     98                // initialize the engine
     99                engine = new SimpleEngine(this);
    96100        }
    97101
     
    136140                        projection.latlon2xy(p);
    137141                }
    138                 return new Point(toScreenX(p.x), toScreenY(p.y));
     142                int x = ((int)Math.round((p.x-center.x) / scale + getWidth()/2));
     143                int y = ((int)Math.round((center.y-p.y) / scale + getHeight()/2));
     144                return new Point(x,y);
    139145        }
    140146
     
    179185               
    180186                // pending line segments
    181                 for (LineSegment ls : dataSet.pendingLineSegments) {
    182                         Point A = getScreenPoint(ls.start.coor);
    183                         Point B = getScreenPoint(ls.end.coor);
     187                for (LineSegment ls : dataSet.pendingLineSegments()) {
     188                        Point A = getScreenPoint(ls.getStart().coor);
     189                        Point B = getScreenPoint(ls.getEnd().coor);
    184190                        double c = A.distanceSq(B);
    185191                        double a = p.distanceSq(B);
     
    194200                // tracks & line segments
    195201                minDistanceSq = Double.MAX_VALUE;
    196                 for (Track t : dataSet.tracks) {
    197                         for (LineSegment ls : t.segments) {
    198                                 Point A = getScreenPoint(ls.start.coor);
    199                                 Point B = getScreenPoint(ls.end.coor);
     202                for (Track t : dataSet.tracks()) {
     203                        for (LineSegment ls : t.segments()) {
     204                                Point A = getScreenPoint(ls.getStart().coor);
     205                                Point B = getScreenPoint(ls.getEnd().coor);
    200206                                double c = A.distanceSq(B);
    201207                                double a = p.distanceSq(B);
     
    213219                // TODO areas
    214220               
    215                
    216221                return null; // nothing found
    217222        }
     
    224229         */
    225230        public void zoomTo(GeoPoint newCenter, double scale) {
     231                boolean oldAutoScale = autoScale;
     232                GeoPoint oldCenter = center;
     233                double oldScale = this.scale;
     234               
    226235                autoScale = false;
    227236                center = newCenter.clone();
     
    229238                this.scale = scale;
    230239                recalculateCenterScale();
    231                 fireStateChanged(); // in case of autoScale, recalculate fired.
     240
     241                firePropertyChange("center", oldCenter, center);
     242                if (oldAutoScale != autoScale)
     243                        firePropertyChange("autoScale", oldAutoScale, autoScale);
     244                if (oldScale != scale)
     245                        firePropertyChange("scale", oldScale, scale);
    232246        }
    233247       
     
    254268                                h = 20;
    255269                        Bounds bounds = dataSet.getBoundsXY();
     270                       
     271                        boolean oldAutoScale = autoScale;
     272                        GeoPoint oldCenter = center;
     273                        double oldScale = this.scale;
     274                       
    256275                        if (bounds == null) {
    257276                                // no bounds means standard scale and center
     
    266285                                scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen
    267286                        }
    268                         fireStateChanged();
     287
     288                        firePropertyChange("center", oldCenter, center);
     289                        if (oldAutoScale != autoScale)
     290                                firePropertyChange("autoScale", oldAutoScale, autoScale);
     291                        if (oldScale != scale)
     292                                firePropertyChange("scale", oldScale, scale);
    269293                }
    270294                repaint();
     
    283307        @Override
    284308        public void paint(Graphics g) {
    285                 // empty out everything
    286                 g.setColor(Color.BLACK);
    287                 g.fillRect(0,0,getWidth(),getHeight());
    288 
    289                 // draw tracks
    290                 if (dataSet.tracks != null)
    291                         for (Track track : dataSet.tracks)
    292                                 for (LineSegment ls : track.segments) {
    293                                         g.setColor(ls.selected || track.selected ? Color.WHITE : Color.GRAY);
    294                                         g.drawLine(toScreenX(ls.start.coor.x), toScreenY(ls.start.coor.y),
    295                                                         toScreenX(ls.end.coor.x), toScreenY(ls.end.coor.y));
    296                                 }
    297 
    298                 // draw pending line segments
    299                 for (LineSegment ls : dataSet.pendingLineSegments) {
    300                         g.setColor(ls.selected ? Color.WHITE : Color.LIGHT_GRAY);
    301                         g.drawLine(toScreenX(ls.start.coor.x), toScreenY(ls.start.coor.y),
    302                                         toScreenX(ls.end.coor.x), toScreenY(ls.end.coor.y));
    303                 }
    304 
    305                 // draw nodes
    306                 Set<Integer> alreadyDrawn = new HashSet<Integer>();
    307                 int width = getWidth();
    308                 for (Node w : dataSet.nodes) {
    309                         g.setColor(w.selected ? Color.WHITE : Color.RED);
    310                         int x = toScreenX(w.coor.x);
    311                         int y = toScreenY(w.coor.y);
    312                         int size = 3;
    313                         if (alreadyDrawn.contains(y*width+x)) {
    314                                 size = 7;
    315                                 x -= 2;
    316                                 y -= 2;
    317                         } else
    318                                 alreadyDrawn.add(y*width+x);
    319                         g.drawArc(x, y, size, size, 0, 360);
    320                 }
    321         }
    322 
    323         /**
    324          * Return the x-screen coordinate for the given point.
    325          * @param x The X-position (easting) of the desired point
    326          * @return The screen coordinate for the point.
    327          */
    328         public int toScreenX(double x) {
    329                 return (int)Math.round((x-center.x) / scale + getWidth()/2);
    330         }
    331 
    332         /**
    333          * Return the y-screen coordinate for the given point.
    334          * @param y The Y-position (northing) of the desired point
    335          * @return The screen coordinate for the point.
    336          */
    337         public int toScreenY(double y) {
    338                 return (int)Math.round((center.y-y) / scale + getHeight()/2);
    339         }
    340 
    341 
    342         // Event handling functions and data
    343        
    344         /**
    345          * The event list with all state chaned listener
    346          */
    347         List<ChangeListener> listener = new LinkedList<ChangeListener>();
    348         /**
    349          * Add an event listener to the state changed event queue. If passed
    350          * <code>null</code>, nothing happens.
    351          */
    352         public final void addChangeListener(ChangeListener l) {
    353                 if (l != null)
    354                         listener.add(l);
    355         }
    356         /**
    357          * Remove an event listener from the event queue. If passed
    358          * <code>null</code>, nothing happens.
    359          */
    360         public final void removeChangeListener(ChangeListener l) {
    361                 listener.remove(l);
    362         }
    363         /**
    364          * Fires an ChangeEvent. Occours, when an non-data value changed, as example
    365          * the autoScale - state or the center. Is not fired, dataSet internal things
    366          * changes.
    367          */
    368         public final void fireStateChanged() {
    369                 ChangeEvent e = null;
    370                 for(ChangeListener l : listener) {
    371                         if (e == null)
    372                                 e = new ChangeEvent(this);
    373                         l.stateChanged(e);
    374                 }
    375         }
    376        
     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
    377320        /**
    378321         * Notify from the projection, that something has changed.
     
    393336                if (projection == this.projection)
    394337                        return;
     338
     339                Projection oldProjection = this.projection;
     340               
    395341                if (this.projection != null)
    396342                        this.projection.removeChangeListener(this);
    397343                this.projection = projection;
    398344                projection.addChangeListener(this);
     345               
    399346                stateChanged(new ChangeEvent(this));
     347                firePropertyChange("projection", oldProjection, projection);
    400348        }
    401349
     
    421369                if (this.autoScale != autoScale) {
    422370                        this.autoScale = autoScale;
    423                         fireStateChanged();
     371                        firePropertyChange("autoScale", !autoScale, autoScale);
    424372                }
    425373        }
  • src/org/openstreetmap/josm/gui/SelectionManager.java

    r7 r8  
    137137         */
    138138        public void mousePressed(MouseEvent e) {
    139                 if (e.getButton() == MouseEvent.BUTTON1) {
    140                         mousePosStart = e.getPoint();
    141                         mousePos = e.getPoint();
    142                         paintRect();
    143                 }
     139                if (e.getButton() == MouseEvent.BUTTON1)
     140                        mousePosStart = mousePos = e.getPoint();
    144141        }
    145142
     
    150147                int buttonPressed = e.getModifiersEx() & (MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK);
    151148
     149               
    152150                if (buttonPressed != 0) {
    153                         if (mousePosStart == null) {
    154                                 mousePosStart = e.getPoint();
    155                                 mousePos = e.getPoint();
    156                                 paintRect();
    157                         }
     151                        if (mousePosStart == null)
     152                                mousePosStart = mousePos = e.getPoint();
    158153                        paintRect();
    159154                }
     
    176171                if (e.getButton() != MouseEvent.BUTTON1)
    177172                        return;
     173                if (mousePos == null || mousePosStart == null)
     174                        return; // injected release from outside
     175                       
    178176                // disable the selection rect
    179177                paintRect();
     
    195193         */
    196194        private void paintRect() {
     195                if (mousePos == null || mousePosStart == null || mousePos == mousePosStart)
     196                        return;
    197197                Graphics g = mv.getGraphics();
    198198                g.setColor(Color.BLACK);
     
    244244         */
    245245        public void propertyChange(PropertyChangeEvent evt) {
    246                 if (evt.getPropertyName() == "active" && !(Boolean)evt.getNewValue() && mousePosStart != null) {
     246                if (evt.getPropertyName().equals("active") && !(Boolean)evt.getNewValue() && mousePosStart != null) {
    247247                        paintRect();
    248248                        mousePosStart = null;
     
    277277                       
    278278                        // pending line segments
    279                         for (LineSegment ls : mv.dataSet.pendingLineSegments)
     279                        for (LineSegment ls : mv.dataSet.pendingLineSegments())
    280280                                if (rectangleContainLineSegment(r, alt, ls))
    281281                                        selection.add(ls);
    282282
    283283                        // tracks
    284                         for (Track t : mv.dataSet.tracks) {
    285                                 boolean wholeTrackSelected = t.segments.size() > 0;
    286                                 for (LineSegment ls : t.segments)
     284                        for (Track t : mv.dataSet.tracks()) {
     285                                boolean wholeTrackSelected = !t.segments().isEmpty();
     286                                for (LineSegment ls : t.segments())
    287287                                        if (rectangleContainLineSegment(r, alt, ls))
    288288                                                selection.add(ls);
     
    309309        private boolean rectangleContainLineSegment(Rectangle r, boolean alt, LineSegment ls) {
    310310                if (alt) {
    311                         Point p1 = mv.getScreenPoint(ls.start.coor);
    312                         Point p2 = mv.getScreenPoint(ls.end.coor);
     311                        Point p1 = mv.getScreenPoint(ls.getStart().coor);
     312                        Point p2 = mv.getScreenPoint(ls.getEnd().coor);
    313313                        if (r.intersectsLine(p1.x, p1.y, p2.x, p2.y))
    314314                                return true;
    315315                } else {
    316                         if (r.contains(mv.getScreenPoint(ls.start.coor))
    317                                         && r.contains(mv.getScreenPoint(ls.end.coor)))
     316                        if (r.contains(mv.getScreenPoint(ls.getStart().coor))
     317                                        && r.contains(mv.getScreenPoint(ls.getEnd().coor)))
    318318                                return true;
    319319                }
  • src/org/openstreetmap/josm/io/GpxReader.java

    r7 r8  
    33import java.io.IOException;
    44import java.io.Reader;
    5 import java.util.ArrayList;
    65
    76import org.jdom.Element;
     
    4645        }
    4746
    48        
     47
    4948        /**
    5049         * Read one node (waypoint).
     
    8382                                        else {
    8483                                                LineSegment lineSegment = new LineSegment(start, node);
    85                                                 track.segments.add(lineSegment);
     84                                                track.add(lineSegment);
    8685                                                start = null;
    8786                                        }
    8887                                }
    8988                        }
    90                         if (data.tracks == null)
    91                                 data.tracks = new ArrayList<Track>();
    92                         data.tracks.add(track);
     89                        data.addTrack(track);
    9390                }
    9491
Note: See TracChangeset for help on using the changeset viewer.