Changeset 8 in josm
- Timestamp:
- 2005-10-03T04:18:02+02:00 (19 years ago)
- Files:
-
- 19 added
- 18 edited
- 1 moved
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/actions/mapmode/AddLineSegmentAction.java
r7 r8 130 130 if (start != end) { 131 131 // 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()) { 135 135 JOptionPane.showMessageDialog(Main.main, "There is already an line segment with the same direction between the selected nodes."); 136 136 return; … … 142 142 if (((e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0)) { 143 143 // find a track for the new line segment 144 for (Track t : ds.tracks) { 144 for (Track t : ds.tracks()) { 145 145 if (t.getEndingNode() == start) { 146 t. segments.add(ls);146 t.add(ls); 147 147 foundTrack = true; 148 148 } 149 149 } 150 150 if (!foundTrack) { 151 for (Track t : ds.tracks) { 151 for (Track t : ds.tracks()) { 152 152 if (t.getStartingNode() == end) { 153 t. segments.add(0,ls);153 t.addStart(ls); 154 154 foundTrack = true; 155 155 } … … 158 158 } 159 159 if (!foundTrack) 160 ds. pendingLineSegments.add(ls);160 ds.addPendingLineSegment(ls); 161 161 } 162 162 -
src/org/openstreetmap/josm/actions/mapmode/AddTrackAction.java
r7 r8 80 80 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt); 81 81 for (OsmPrimitive osm : selectionList) 82 osm.se lected = !ctrl;82 osm.setSelected(!ctrl, ds); 83 83 84 84 mv.repaint(); // from now on, the map has to be repainted. … … 95 95 for (OsmPrimitive osm : selection) { 96 96 if (osm instanceof Track) 97 lineSegments.addAll(((Track)osm).segments); 97 lineSegments.addAll(((Track)osm).segments()); 98 98 else if (osm instanceof LineSegment) 99 99 lineSegments.add((LineSegment)osm); 100 100 } 101 101 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); 105 105 ds.clearSelection(); 106 106 } -
src/org/openstreetmap/josm/actions/mapmode/CombineAction.java
r7 r8 136 136 return; 137 137 138 if (first == null || second == null) { 138 if (first == null || second == null || first == second) { 139 139 first = null; 140 140 second = null; … … 160 160 t2 = (Track)first; 161 161 } 162 t1. segments.addAll(t2.segments);162 t1.addAll(t2.segments()); 163 163 if (t1.keys == null) 164 164 t1.keys = t2.keys; 165 165 else 166 166 t1.keys.putAll(t2.keys); 167 ds. tracks.remove(t2);167 ds.removeTrack(t2); 168 168 } 169 169 } … … 178 178 */ 179 179 private void combine(LineSegment ls, Track t) { 180 if (!ds.pendingLineSegments.contains( first))180 if (!ds.pendingLineSegments().contains(ls)) 181 181 throw new IllegalStateException("Should not be able to select non-pending line segments."); 182 182 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()); 188 184 } 189 185 … … 203 199 204 200 Graphics g = mv.getGraphics(); 205 g.setColor(draw ? Color.WHITE : Color.GRAY); // HACK 201 g.setColor(Color.BLACK); 202 g.setXORMode(Color.WHITE); 206 203 draw(g, first); 207 204 draw(g, second); … … 217 214 if (osm instanceof LineSegment) { 218 215 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) 224 219 g.drawLine(start.x, start.y, end.x, end.y); 225 g.setColor(Color.GRAY); 226 } else 220 else 227 221 g.drawLine(start.x, start.y, end.x, end.y); 228 222 } else if (osm instanceof Track) { 229 for (LineSegment ls : ((Track)osm).segments) 223 for (LineSegment ls : ((Track)osm).segments()) 230 224 draw(g, ls); 231 225 } -
src/org/openstreetmap/josm/actions/mapmode/DebugAction.java
r7 r8 48 48 Graphics g = mapFrame.mapView.getGraphics(); 49 49 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); 54 54 Point C = e.getPoint(); 55 55 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 5 5 import java.util.ArrayList; 6 6 import java.util.HashMap; 7 import java.util. Iterator;7 import java.util.LinkedList; 8 8 import java.util.Map; 9 9 … … 133 133 if (osm instanceof Node) { 134 134 // 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) 138 138 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) 141 141 lineSegmentsToDelete.add(ls); 142 142 … … 144 144 LineSegment lineSegment = (LineSegment)osm; 145 145 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()) 148 148 if (lineSegment == ls) 149 149 tracksToDelete.add(t); … … 154 154 ArrayList<Node> checkUnreferencing = new ArrayList<Node>(); 155 155 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()); 159 159 } 160 160 } 161 161 for (LineSegment ls : lineSegmentsToDelete) { 162 checkUnreferencing.add(ls. start);163 checkUnreferencing.add(ls. end);162 checkUnreferencing.add(ls.getStart()); 163 checkUnreferencing.add(ls.getEnd()); 164 164 } 165 165 166 166 // 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); 169 171 170 172 // removing all unreferenced nodes … … 198 200 ds.nodes.remove(n); 199 201 } 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); 207 211 } 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); 210 215 } 211 216 } … … 218 223 */ 219 224 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) 223 228 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) 226 231 return true; 227 232 // TODO areas … … 240 245 private String combine(Node n) { 241 246 // 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()) 244 249 return "Node used by a line segment which is not part of any track. Remove this first."; 245 250 … … 253 258 HashMap<ArrayList<LineSegment>, Track> lineSegments = new HashMap<ArrayList<LineSegment>, Track>(); 254 259 255 for (Track t : ds.tracks) { 260 for (Track t : ds.tracks()) { 256 261 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) 259 264 current.add(ls); 260 265 if (!current.isEmpty()) { … … 262 267 return "Node used by more than two line segments."; 263 268 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())) 265 270 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()) 268 273 return "Node used by line segments that points together."; 269 274 else if (!current.get(0).keyPropertiesMergable(current.get(1))) … … 276 281 // try to combine tracks 277 282 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) 280 285 tracks.add(t); 281 286 if (!tracks.isEmpty()) { … … 286 291 Track t1 = tracks.get(0); 287 292 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()) 292 297 return "Node used by tracks that point together."; 293 298 return "Node used by tracks that cannot be combined."; … … 301 306 LineSegment l1 = pendingLineSegmentsForTrack.get(0); 302 307 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()) 304 309 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()) 306 311 pendingLineSegmentsForTrack.clear(); // resolved. 307 312 } … … 316 321 LineSegment first = list.get(0); 317 322 LineSegment second = list.get(1); 318 if (first. start== second.end) {323 if (first.getStart() == second.getEnd()) { 319 324 first = second; 320 325 second = list.get(0); 321 326 } 322 first. end =second.end;327 first.setEnd(second.getEnd()); 323 328 first.keys = mergeKeys(first.keys, second.keys); 324 lineSegments.get(list). segments.remove(second);329 lineSegments.get(list).remove(second); 325 330 } 326 331 … … 329 334 Track first = tracks.get(0); 330 335 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()) { 332 337 first = second; 333 338 second = tracks.get(0); 334 339 } 335 340 // 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()); 339 344 lastOfFirst.keys = mergeKeys(lastOfFirst.keys, firstOfSecond.keys); 340 second. segments.remove(firstOfSecond);345 second.remove(firstOfSecond); 341 346 // 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); 344 349 } 345 350 -
src/org/openstreetmap/josm/actions/mapmode/MoveAction.java
r7 r8 113 113 OsmPrimitive osm = mv.getNearest(e.getPoint(), (e.getModifiersEx() & MouseEvent.ALT_DOWN_MASK) != 0); 114 114 if (osm != null) 115 osm.se lected = true;115 osm.setSelected(true, ds); 116 116 singleOsmPrimitive = osm; 117 117 mv.repaint(); … … 131 131 mv.setCursor(oldCursor); 132 132 if (singleOsmPrimitive != null) { 133 singleOsmPrimitive.se lected = false;133 singleOsmPrimitive.setSelected(false, ds); 134 134 mv.repaint(); 135 135 } -
src/org/openstreetmap/josm/actions/mapmode/SelectionAction.java
r7 r8 91 91 Collection<OsmPrimitive> selectionList = selectionManager.getObjectsInRectangle(r,alt); 92 92 for (OsmPrimitive osm : selectionList) 93 osm.se lected = !ctrl;93 osm.setSelected(!ctrl, ds); 94 94 mv.repaint(); 95 95 } -
src/org/openstreetmap/josm/data/osm/DataSet.java
r7 r8 2 2 3 3 import java.util.Collection; 4 import java.util.Collections; 4 5 import java.util.HashSet; 5 6 import java.util.LinkedList; 6 7 7 8 import org.openstreetmap.josm.data.Bounds; 9 import org.openstreetmap.josm.data.SelectionTracker; 8 10 9 11 /** … … 17 19 * @author imi 18 20 */ 19 public class DataSet implements Cloneable { 21 public class DataSet extends SelectionTracker implements Cloneable { 20 22 21 23 /** … … 30 32 * are in this list but are in no track. 31 33 */ 32 p ublicCollection<LineSegment> pendingLineSegments = new LinkedList<LineSegment>();34 private Collection<LineSegment> pendingLineSegments = new LinkedList<LineSegment>(); 33 35 34 36 /** … … 39 41 * track list. 40 42 */ 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 } 42 99 43 100 /** … … 73 130 74 131 /** 75 * Return all tracks that contain the node. If nothing found, an empty array76 * 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 /**95 132 * Return the bounds of this DataSet, depending on lat/lon values. 96 133 * The min of the return value is the upper left GeoPoint, the max the lower … … 131 168 clearSelection(tracks); 132 169 for (Track t : tracks) 133 clearSelection(t.segments); 170 clearSelection(t.segments()); 134 171 } 135 172 … … 138 175 * @return List of all selected objects. 139 176 */ 177 @Override 140 178 public Collection<OsmPrimitive> getSelected() { 141 179 Collection<OsmPrimitive> sel = getSelected(nodes); … … 143 181 sel.addAll(getSelected(tracks)); 144 182 for (Track t : tracks) 145 sel.addAll(getSelected(t.segments)); 183 sel.addAll(getSelected(t.segments())); 146 184 return sel; 147 185 } 148 186 149 187 /** 150 188 * Remove the selection from every value in the collection. … … 155 193 return; 156 194 for (OsmPrimitive osm : list) { 157 osm.se lected = false;195 osm.setSelected(false, this); 158 196 if (osm.keys != null) 159 197 clearSelection(osm.keys.keySet()); … … 170 208 return sel; 171 209 for (OsmPrimitive osm : list) { 172 if (osm. selected)210 if (osm.isSelected()) 173 211 sel.add(osm); 174 212 if (osm.keys != null) -
src/org/openstreetmap/josm/data/osm/Key.java
r7 r8 2 2 3 3 import java.util.Collection; 4 import java.util.HashMap; 4 5 import java.util.LinkedList; 6 import java.util.Map; 7 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 5 9 6 10 … … 15 19 * The key's name 16 20 */ 17 public String name; 21 public final String name; 18 22 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 19 51 /** 20 52 * Return an empty list, since keys cannot have nodes. … … 39 71 return name.hashCode(); 40 72 } 73 74 @Override 75 public void visit(Visitor visitor) { 76 visitor.visit(this); 77 } 41 78 } -
src/org/openstreetmap/josm/data/osm/LineSegment.java
r7 r8 2 2 3 3 import java.util.Collection; 4 import java.util.Collections; 4 5 import java.util.LinkedList; 6 7 import org.openstreetmap.josm.data.osm.visitor.Visitor; 5 8 6 9 … … 13 16 14 17 /** 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 /** 15 33 * Create an line segment from the given starting and ending node 16 34 * @param start Starting node of the line segment. … … 20 38 this.start = start; 21 39 this.end = end; 40 start.parentSegment.add(this); 41 end.parentSegment.add(this); 22 42 } 23 43 24 44 /** 25 * The starting node of theline segment45 * Return all parent tracks this line segment is part of. The list is readonly. 26 46 */ 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 29 68 /** 30 * The ending node of the line segment69 * The LineSegment is going to be destroyed. Unlink all back references. 31 70 */ 32 public Node end; 71 void destroy() { 72 start.parentSegment.remove(this); 73 end.parentSegment.remove(this); 74 } 33 75 34 76 /** … … 38 80 public Collection<Node> getAllNodes() { 39 81 LinkedList<Node> nodes = new LinkedList<Node>(); 40 nodes.add( start);41 nodes.add( end);82 nodes.add(getStart()); 83 nodes.add(getEnd()); 42 84 return nodes; 43 85 } … … 52 94 return false; 53 95 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()); 56 98 } 57 99 58 100 @Override 59 101 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); 61 108 } 62 109 } -
src/org/openstreetmap/josm/data/osm/Node.java
r7 r8 2 2 3 3 import java.util.Collection; 4 import java.util.Collections; 4 5 import java.util.LinkedList; 5 6 6 7 import org.openstreetmap.josm.data.GeoPoint; 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 7 9 8 10 … … 19 21 public GeoPoint coor; 20 22 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 21 36 /** 22 37 * Nodes are equal when their coordinates are equal. … … 49 64 return nodes; 50 65 } 51 52 66 67 @Override 68 public void visit(Visitor visitor) { 69 visitor.visit(this); 70 } 53 71 } -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r7 r8 3 3 import java.util.Collection; 4 4 import java.util.Map; 5 6 import org.openstreetmap.josm.data.osm.visitor.Visitor; 5 7 6 8 … … 26 28 * If set to true, this object is currently selected. 27 29 */ 28 transient p ublicboolean selected = false;30 transient private boolean selected = false; 29 31 30 32 /** 31 33 * Return a list of all nodes, this osmPrimitive consists of. Does return 32 34 * an empty list, if it is an primitive that cannot have nodes (e.g. Key) 35 * TODO replace with visitor 33 36 */ 34 37 abstract public Collection<Node> getAllNodes(); 35 38 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 36 46 /** 37 47 * Return <code>true</code>, if either <code>this.keys</code> and … … 79 89 return keys == null ? 0 : keys.hashCode(); 80 90 } 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 } 81 110 } -
src/org/openstreetmap/josm/data/osm/Track.java
r7 r8 3 3 import java.util.ArrayList; 4 4 import java.util.Collection; 5 import java.util.Collections; 5 6 import java.util.List; 7 8 import org.openstreetmap.josm.data.osm.visitor.Visitor; 6 9 7 10 /** … … 15 18 * All track segments in this track 16 19 */ 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 } 18 68 19 69 /** … … 26 76 nodes.addAll(ls.getAllNodes()); 27 77 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(); 28 89 } 29 90 … … 67 128 if (segments.isEmpty()) 68 129 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); 70 141 } 71 142 … … 82 153 if (segments.isEmpty()) 83 154 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); 85 171 } 86 172 } -
src/org/openstreetmap/josm/gui/IconToggleButton.java
r7 r8 43 43 44 44 public void propertyChange(PropertyChangeEvent evt) { 45 if (evt.getPropertyName() =="active")45 if (evt.getPropertyName().equals("active")) 46 46 setSelected((Boolean)evt.getNewValue()); 47 47 } -
src/org/openstreetmap/josm/gui/MapFrame.java
r7 r8 3 3 import java.awt.BorderLayout; 4 4 import java.awt.Component; 5 import java.awt.event.ActionEvent; 6 import java.awt.event.ActionListener; 7 import java.awt.event.KeyEvent; 5 import java.awt.event.WindowAdapter; 6 import java.awt.event.WindowEvent; 7 import java.beans.PropertyChangeEvent; 8 import java.beans.PropertyChangeListener; 8 9 9 import javax.swing.AbstractAction;10 10 import javax.swing.AbstractButton; 11 import javax.swing.BorderFactory;12 import javax.swing.Box;13 import javax.swing.BoxLayout;14 11 import 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;20 12 import javax.swing.JPanel; 21 13 import javax.swing.JToggleButton; 22 14 import javax.swing.JToolBar; 23 import javax.swing.border.Border;24 import javax.swing.event.ChangeEvent;25 import javax.swing.event.ChangeListener;26 15 27 16 import org.openstreetmap.josm.actions.mapmode.AddLineSegmentAction; … … 35 24 import org.openstreetmap.josm.actions.mapmode.SelectionAction; 36 25 import org.openstreetmap.josm.actions.mapmode.ZoomAction; 37 import org.openstreetmap.josm.data.Preferences;38 26 import org.openstreetmap.josm.data.osm.DataSet; 39 import org.openstreetmap.josm.data.projection.Projection; 27 import org.openstreetmap.josm.gui.dialogs.PropertiesDialog; 28 import org.openstreetmap.josm.gui.dialogs.SelectionListDialog; 40 29 41 30 /** … … 46 35 */ 47 36 public class MapFrame extends JPanel { 48 49 /**50 * Open the properties page51 * @author imi52 */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 within70 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 // projection76 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 details86 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 }108 37 109 38 /** … … 155 84 autoScaleButton.setText(null); 156 85 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()); 160 90 } 161 91 }); 162 92 163 93 // 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); 165 106 } 166 107 -
src/org/openstreetmap/josm/gui/MapView.java
r7 r8 1 1 package org.openstreetmap.josm.gui; 2 2 3 import java.awt.Color;4 3 import java.awt.Graphics; 5 4 import java.awt.Point; … … 8 7 import java.awt.event.ComponentListener; 9 8 import java.awt.event.KeyEvent; 10 import java.util.HashSet;11 import java.util.LinkedList;12 import java.util.List;13 import java.util.Set;14 9 15 10 import javax.swing.AbstractAction; … … 27 22 import org.openstreetmap.josm.data.osm.Track; 28 23 import org.openstreetmap.josm.data.projection.Projection; 24 import org.openstreetmap.josm.gui.engine.Engine; 25 import org.openstreetmap.josm.gui.engine.SimpleEngine; 29 26 30 27 /** … … 81 78 public final DataSet dataSet; 82 79 80 /** 81 * The drawing engine. 82 */ 83 private Engine engine; 83 84 84 85 /** … … 94 95 // initialize the projection 95 96 setProjection(Main.pref.projection.clone()); 97 98 // initialize the engine 99 engine = new SimpleEngine(this); 96 100 } 97 101 … … 136 140 projection.latlon2xy(p); 137 141 } 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); 139 145 } 140 146 … … 179 185 180 186 // 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); 184 190 double c = A.distanceSq(B); 185 191 double a = p.distanceSq(B); … … 194 200 // tracks & line segments 195 201 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); 200 206 double c = A.distanceSq(B); 201 207 double a = p.distanceSq(B); … … 213 219 // TODO areas 214 220 215 216 221 return null; // nothing found 217 222 } … … 224 229 */ 225 230 public void zoomTo(GeoPoint newCenter, double scale) { 231 boolean oldAutoScale = autoScale; 232 GeoPoint oldCenter = center; 233 double oldScale = this.scale; 234 226 235 autoScale = false; 227 236 center = newCenter.clone(); … … 229 238 this.scale = scale; 230 239 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); 232 246 } 233 247 … … 254 268 h = 20; 255 269 Bounds bounds = dataSet.getBoundsXY(); 270 271 boolean oldAutoScale = autoScale; 272 GeoPoint oldCenter = center; 273 double oldScale = this.scale; 274 256 275 if (bounds == null) { 257 276 // no bounds means standard scale and center … … 266 285 scale = Math.max(scaleX, scaleY); // minimum scale to see all of the screen 267 286 } 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); 269 293 } 270 294 repaint(); … … 283 307 @Override 284 308 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 377 320 /** 378 321 * Notify from the projection, that something has changed. … … 393 336 if (projection == this.projection) 394 337 return; 338 339 Projection oldProjection = this.projection; 340 395 341 if (this.projection != null) 396 342 this.projection.removeChangeListener(this); 397 343 this.projection = projection; 398 344 projection.addChangeListener(this); 345 399 346 stateChanged(new ChangeEvent(this)); 347 firePropertyChange("projection", oldProjection, projection); 400 348 } 401 349 … … 421 369 if (this.autoScale != autoScale) { 422 370 this.autoScale = autoScale; 423 fire StateChanged();371 firePropertyChange("autoScale", !autoScale, autoScale); 424 372 } 425 373 } -
src/org/openstreetmap/josm/gui/SelectionManager.java
r7 r8 137 137 */ 138 138 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(); 144 141 } 145 142 … … 150 147 int buttonPressed = e.getModifiersEx() & (MouseEvent.BUTTON1_DOWN_MASK | MouseEvent.BUTTON3_DOWN_MASK); 151 148 149 152 150 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(); 158 153 paintRect(); 159 154 } … … 176 171 if (e.getButton() != MouseEvent.BUTTON1) 177 172 return; 173 if (mousePos == null || mousePosStart == null) 174 return; // injected release from outside 175 178 176 // disable the selection rect 179 177 paintRect(); … … 195 193 */ 196 194 private void paintRect() { 195 if (mousePos == null || mousePosStart == null || mousePos == mousePosStart) 196 return; 197 197 Graphics g = mv.getGraphics(); 198 198 g.setColor(Color.BLACK); … … 244 244 */ 245 245 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) { 247 247 paintRect(); 248 248 mousePosStart = null; … … 277 277 278 278 // pending line segments 279 for (LineSegment ls : mv.dataSet.pendingLineSegments) 279 for (LineSegment ls : mv.dataSet.pendingLineSegments()) 280 280 if (rectangleContainLineSegment(r, alt, ls)) 281 281 selection.add(ls); 282 282 283 283 // 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()) 287 287 if (rectangleContainLineSegment(r, alt, ls)) 288 288 selection.add(ls); … … 309 309 private boolean rectangleContainLineSegment(Rectangle r, boolean alt, LineSegment ls) { 310 310 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); 313 313 if (r.intersectsLine(p1.x, p1.y, p2.x, p2.y)) 314 314 return true; 315 315 } 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))) 318 318 return true; 319 319 } -
src/org/openstreetmap/josm/io/GpxReader.java
r7 r8 3 3 import java.io.IOException; 4 4 import java.io.Reader; 5 import java.util.ArrayList;6 5 7 6 import org.jdom.Element; … … 46 45 } 47 46 48 47 49 48 /** 50 49 * Read one node (waypoint). … … 83 82 else { 84 83 LineSegment lineSegment = new LineSegment(start, node); 85 track. segments.add(lineSegment);84 track.add(lineSegment); 86 85 start = null; 87 86 } 88 87 } 89 88 } 90 if (data.tracks == null) 91 data.tracks = new ArrayList<Track>(); 92 data.tracks.add(track); 89 data.addTrack(track); 93 90 } 94 91
Note:
See TracChangeset
for help on using the changeset viewer.