Changeset 203 in josm
- Timestamp:
- 2007-02-17T17:09:49+01:00 (18 years ago)
- Files:
-
- 2 deleted
- 21 edited
Legend:
- Unmodified
- Added
- Removed
-
src/org/openstreetmap/josm/Main.java
r192 r203 160 160 public final void removeLayer(final Layer layer) { 161 161 map.mapView.removeLayer(layer); 162 if (layer instanceof OsmDataLayer) 163 ds = new DataSet(); 162 if (layer instanceof OsmDataLayer) { 163 DataSet newDs = new DataSet(); 164 newDs.listeners.addAll(ds.listeners); 165 ds = newDs; 166 } 164 167 if (map.mapView.getAllLayers().isEmpty()) 165 168 setMapFrame(null); -
src/org/openstreetmap/josm/actions/AutoScaleAction.java
r155 r203 60 60 setCurrent(0); 61 61 this.mapFrame = mapFrame; 62 Main.ds. addSelectionChangedListener(new SelectionChangedListener(){62 Main.ds.listeners.add(new SelectionChangedListener(){ 63 63 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 64 64 if (mode.equals("selection")) -
src/org/openstreetmap/josm/actions/SplitWayAction.java
r194 r203 98 98 public SplitWayAction() { 99 99 super(tr("Split Way"), "splitway", tr("Split a way at the selected node."), KeyEvent.VK_P, KeyEvent.CTRL_MASK | KeyEvent.SHIFT_MASK, true); 100 Main.ds. addSelectionChangedListener(this);100 Main.ds.listeners.add(this); 101 101 } 102 102 … … 230 230 231 231 // finally check if the selected way is complete. 232 for (Segment s : selectedWay.segments) { 233 if (s.incomplete) { 234 JOptionPane.showMessageDialog(Main.parent, tr("Warning: This way is incomplete. Try to download it before splitting.")); 235 return; 236 } 232 if (selectedWay.isIncomplete()) { 233 JOptionPane.showMessageDialog(Main.parent, tr("Warning: This way is incomplete. Try to download it before splitting.")); 234 return; 237 235 } 238 236 … … 311 309 // the moveSegments method. 312 310 if (split) { 313 ArrayList<Segment> subSegments = new ArrayList<Segment>();311 LinkedList<Segment> subSegments = new LinkedList<Segment>(); 314 312 moveSegments(allSegments, subSegments, splitSeg, selectedNodes); 315 313 segmentSets.add(subSegments); … … 356 354 partThatContainsSegments.removeAll(selectedSegments); 357 355 if (!partThatContainsSegments.isEmpty()) { 358 ArrayList<Segment> contiguousSubpart = new ArrayList<Segment>();356 LinkedList<Segment> contiguousSubpart = new LinkedList<Segment>(); 359 357 moveSegments(partThatContainsSegments, contiguousSubpart, partThatContainsSegments.get(0), null); 360 358 // if partThatContainsSegments was contiguous before, it will now be empty as all segments … … 380 378 381 379 while (!allSegments.isEmpty()) { 382 Li st<Segment> subSegments = new LinkedList<Segment>();380 LinkedList<Segment> subSegments = new LinkedList<Segment>(); 383 381 moveSegments(allSegments, subSegments, allSegments.get(0), null); 384 382 segmentSets.add(subSegments); … … 465 463 * @param stopNodes collection of nodes which should be considered end points for moving (may be null). 466 464 */ 467 private void moveSegments(Collection<Segment> source, Collection<Segment> destination, Segment start, Collection<Node> stopNodes) {465 private void moveSegments(Collection<Segment> source, LinkedList<Segment> destination, Segment start, Collection<Node> stopNodes) { 468 466 source.remove(start); 469 destination.add(start); 467 if (destination.isEmpty() || destination.iterator().next().from.equals(start.to)) 468 destination.addFirst(start); 469 else 470 destination.addLast(start); 470 471 Segment moveSeg = start; 471 472 while(moveSeg != null) { … … 473 474 474 475 for (Node node : new Node[] { start.from, start.to }) { 475 if (stopNodes != null && stopNodes.contains(node)) continue; 476 if (stopNodes != null && stopNodes.contains(node)) 477 continue; 476 478 for (Segment sourceSeg : source) { 477 479 if (sourceSeg.from.equals(node) || sourceSeg.to.equals(node)) { -
src/org/openstreetmap/josm/actions/mapmode/AddWayAction.java
r184 r203 60 60 public AddWayAction(MapFrame mapFrame) { 61 61 super(tr("Add Way"), "addway", tr("Add a new way to the data."), KeyEvent.VK_W, mapFrame, ImageProvider.getCursor("normal", "way")); 62 63 Main.ds.addSelectionChangedListener(this); 62 Main.ds.listeners.add(this); 64 63 } 65 64 -
src/org/openstreetmap/josm/data/osm/DataSet.java
r175 r203 5 5 import java.util.Collections; 6 6 import java.util.HashSet; 7 import java.util.Iterator;8 7 import java.util.LinkedList; 9 8 import java.util.List; … … 47 46 * A list of listeners to selection changed events. 48 47 */ 49 transient Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>();48 transient public Collection<SelectionChangedListener> listeners = new LinkedList<SelectionChangedListener>(); 50 49 51 50 /** … … 143 142 l.selectionChanged(sel); 144 143 } 145 146 /**147 * Add a listener to the selection changed listener list. If <code>null</code>148 * is passed, nothing happens.149 * @param listener The listener to add to the list.150 */151 public void addSelectionChangedListener(SelectionChangedListener listener) {152 if (listener != null)153 listeners.add(listener);154 }155 156 /**157 * Remove a listener from the selection changed listener list.158 * If <code>null</code> is passed, nothing happens.159 * @param listener The listener to remove from the list.160 */161 public void removeSelectionChangedListener(SelectionChangedListener listener) {162 if (listener != null)163 listeners.remove(listener);164 }165 166 public void addAllSelectionListener(DataSet ds) {167 listeners.addAll(ds.listeners);168 }169 170 /**171 * Compares this and the parameter dataset and return <code>true</code> if both172 * contain the same data primitives (ignoring the selection)173 */174 public boolean realEqual(Collection<OsmPrimitive> other) {175 Collection<OsmPrimitive> my = allPrimitives();176 177 if (my.size() != other.size())178 return false;179 180 Iterator<OsmPrimitive> it = other.iterator();181 for (OsmPrimitive osm : my)182 if (!osm.realEqual(it.next()))183 return false;184 185 return true;186 }187 144 } -
src/org/openstreetmap/josm/data/osm/Node.java
r100 r203 43 43 } 44 44 45 @Override public boolean realEqual(OsmPrimitive osm ) {46 return osm instanceof Node ? super.realEqual(osm ) && coor.equals(((Node)osm).coor) : false;45 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) { 46 return osm instanceof Node ? super.realEqual(osm, semanticOnly) && coor.equals(((Node)osm).coor) : false; 47 47 } 48 48 -
src/org/openstreetmap/josm/data/osm/OsmPrimitive.java
r194 r203 166 166 /** 167 167 * Perform an equality compare for all non-volatile fields not only for the id 168 * but for the whole object (for conflict resolving etc) 168 * but for the whole object (for conflict resolving) 169 * @param semanticOnly if <code>true</code>, modified flag and timestamp are not compared 169 170 */ 170 public boolean realEqual(OsmPrimitive osm ) {171 public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) { 171 172 return 172 id == osm.id &&173 modified == osm.modified&&174 deleted == osm.deleted &&175 (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp)) &&176 (keys == null ? osm.keys==null : keys.equals(osm.keys));173 id == osm.id && 174 (semanticOnly || (modified == osm.modified)) && 175 deleted == osm.deleted && 176 (semanticOnly || (timestamp == null ? osm.timestamp==null : timestamp.equals(osm.timestamp))) && 177 (keys == null ? osm.keys==null : keys.equals(osm.keys)); 177 178 } 178 179 -
src/org/openstreetmap/josm/data/osm/Segment.java
r187 r203 79 79 } 80 80 81 @Override public boolean realEqual(OsmPrimitive osm ) {81 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) { 82 82 if (!(osm instanceof Segment)) 83 return super.realEqual(osm );83 return super.realEqual(osm, semanticOnly); 84 84 if (incomplete) 85 85 return ((Segment)osm).incomplete; 86 return super.realEqual(osm ) && from.equals(((Segment)osm).from) && to.equals(((Segment)osm).to);86 return super.realEqual(osm, semanticOnly) && from.equals(((Segment)osm).from) && to.equals(((Segment)osm).to); 87 87 } 88 88 -
src/org/openstreetmap/josm/data/osm/Way.java
r104 r203 43 43 } 44 44 45 @Override public boolean realEqual(OsmPrimitive osm ) {46 return osm instanceof Way ? super.realEqual(osm ) && segments.equals(((Way)osm).segments) : false;45 @Override public boolean realEqual(OsmPrimitive osm, boolean semanticOnly) { 46 return osm instanceof Way ? super.realEqual(osm, semanticOnly) && segments.equals(((Way)osm).segments) : false; 47 47 } 48 48 -
src/org/openstreetmap/josm/data/osm/visitor/MergeVisitor.java
r197 r203 295 295 296 296 /** 297 * @return <code>true</code>, if no merge is needed .297 * @return <code>true</code>, if no merge is needed or merge is performed already. 298 298 */ 299 299 private <P extends OsmPrimitive> boolean mergeAfterId(Map<P,P> merged, Collection<P> primitives, P other) { 300 300 for (P my : primitives) { 301 if (my.realEqual(other)) 301 Date d1 = my.timestamp == null ? new Date(0) : my.timestamp; 302 Date d2 = other.timestamp == null ? new Date(0) : other.timestamp; 303 if (my.realEqual(other, false)) 302 304 return true; // no merge needed. 305 if (my.realEqual(other, true)) { 306 // they differ in modified/timestamp combination only. Auto-resolve it. 307 if (merged != null) 308 merged.put(other, my); 309 if (d1.before(d2)) { 310 my.modified = other.modified; 311 my.timestamp = other.timestamp; 312 } 313 return true; // merge done. 314 } 303 315 if (my.id == other.id && my.id != 0) { 304 316 if (my instanceof Segment && ((Segment)my).incomplete) 305 317 return false; // merge always over an incomplete 306 Date d1 = my.timestamp == null ? new Date(0) : my.timestamp;307 Date d2 = other.timestamp == null ? new Date(0) : other.timestamp;308 318 if (my.modified && other.modified) { 309 319 conflicts.put(my, other); -
src/org/openstreetmap/josm/gui/MapView.java
r198 r203 89 89 90 90 // listend to selection changes to redraw the map 91 Main.ds. addSelectionChangedListener(new SelectionChangedListener(){91 Main.ds.listeners.add(new SelectionChangedListener(){ 92 92 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 93 93 repaint(); … … 119 119 } 120 120 editLayer = dataLayer; 121 dataLayer.data. addAllSelectionListener(Main.ds);121 dataLayer.data.listeners.addAll(Main.ds.listeners); 122 122 Main.ds = dataLayer.data; 123 123 dataLayer.listenerModified.add(new ModifiedChangedListener(){ -
src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r155 r203 86 86 add(buttonPanel, BorderLayout.SOUTH); 87 87 88 Main.ds. addSelectionChangedListener(new SelectionChangedListener(){88 Main.ds.listeners.add(new SelectionChangedListener(){ 89 89 public void selectionChanged(Collection<? extends OsmPrimitive> newSelection) { 90 90 displaylist.clearSelection(); -
src/org/openstreetmap/josm/gui/dialogs/HistoryDialog.java
r155 r203 143 143 @Override public void setVisible(boolean b) { 144 144 if (b) { 145 Main.ds. addSelectionChangedListener(this);145 Main.ds.listeners.add(this); 146 146 selectionChanged(Main.ds.getSelected()); 147 147 } else { 148 Main.ds. removeSelectionChangedListener(this);148 Main.ds.listeners.remove(this); 149 149 } 150 150 super.setVisible(b); -
src/org/openstreetmap/josm/gui/dialogs/PropertiesDialog.java
r198 r203 328 328 @Override public void setVisible(boolean b) { 329 329 if (b) { 330 Main.ds. addSelectionChangedListener(this);330 Main.ds.listeners.add(this); 331 331 selectionChanged(Main.ds.getSelected()); 332 332 } else { 333 Main.ds. removeSelectionChangedListener(this);333 Main.ds.listeners.remove(this); 334 334 } 335 335 super.setVisible(b); -
src/org/openstreetmap/josm/gui/dialogs/SelectionListDialog.java
r191 r203 89 89 @Override public void setVisible(boolean b) { 90 90 if (b) { 91 Main.ds. addSelectionChangedListener(this);91 Main.ds.listeners.add(this); 92 92 selectionChanged(Main.ds.getSelected()); 93 93 } else { 94 Main.ds. removeSelectionChangedListener(this);94 Main.ds.listeners.remove(this); 95 95 } 96 96 super.setVisible(b); -
src/org/openstreetmap/josm/io/OsmServerWriter.java
r179 r203 74 74 } 75 75 } catch (RuntimeException e) { 76 e.printStackTrace(); 76 77 throw new SAXException("An error occoured: "+e.getMessage()); 77 78 } -
test/org/openstreetmap/josm/data/osm/DataSetTest.java
r146 r203 77 77 public void testFireSelectionChanged() { 78 78 TestSelectionChangeListener l = new TestSelectionChangeListener(); 79 ds. addSelectionChangedListener(l);79 ds.listeners.add(l); 80 80 ds.setSelected(segment); 81 81 assertNotNull(l.called); … … 84 84 } 85 85 86 public void testAddRemoveSelectionChangedListener() {87 TestSelectionChangeListener l = new TestSelectionChangeListener();88 ds.addSelectionChangedListener(l);89 ds.removeSelectionChangedListener(l);90 ds.setSelected(way);91 assertNull(l.called);92 }93 94 86 public void testAddAllSelectionListener() { 95 87 DataSet ds2 = new DataSet(); 96 88 TestSelectionChangeListener l1 = new TestSelectionChangeListener(); 97 89 TestSelectionChangeListener l2 = new TestSelectionChangeListener(); 98 ds2. addSelectionChangedListener(l1);99 ds2. addSelectionChangedListener(l2);100 ds. addAllSelectionListener(ds2);101 ds2. removeSelectionChangedListener(l1);90 ds2.listeners.add(l1); 91 ds2.listeners.add(l2); 92 ds.listeners.addAll(ds2.listeners); 93 ds2.listeners.remove(l1); 102 94 ds.setSelected(node2); 103 95 assertNotNull(l1.called); 104 96 assertNotNull(l2.called); 105 97 } 106 107 public void testRealEqual() {108 Collection<OsmPrimitive> all = new LinkedList<OsmPrimitive>();109 all.add(new Node(node1));110 all.add(new Node(node2));111 all.add(new Node(node3));112 all.add(createSegment(segment.id, node1, node2));113 all.add(createWay(way.id, way.segments.iterator().next()));114 assertTrue(ds.realEqual(all));115 }116 98 } -
test/org/openstreetmap/josm/data/osm/NodeTest.java
r146 r203 21 21 public void testCloneFromRealEqual() { 22 22 Node node2 = createNode(23,3,4); 23 assertFalse(node2.realEqual(node ));24 assertFalse(node.realEqual(node2 ));23 assertFalse(node2.realEqual(node, false)); 24 assertFalse(node.realEqual(node2, false)); 25 25 node.cloneFrom(node2); 26 assertTrue(node2.realEqual(node ));27 assertTrue(node.realEqual(node2 ));26 assertTrue(node2.realEqual(node, false)); 27 assertTrue(node.realEqual(node2, false)); 28 28 } 29 29 30 30 public void testNodeNode() { 31 31 Node node2 = new Node(node); 32 assertTrue(node2.realEqual(node ));32 assertTrue(node2.realEqual(node, false)); 33 33 } 34 34 -
test/org/openstreetmap/josm/data/osm/SegmentTest.java
r146 r203 21 21 Segment s2 = createSegment(23, createNode(1,2,3), createNode(2,3,4)); 22 22 segment.cloneFrom(s2); 23 assertTrue(segment.realEqual(s2 ));24 assertTrue(s2.realEqual(segment ));23 assertTrue(segment.realEqual(s2, false)); 24 assertTrue(s2.realEqual(segment, false)); 25 25 assertSame(segment.from, s2.from); 26 26 assertSame(segment.to, s2.to); … … 29 29 public void testSegmentSegment() { 30 30 Segment s = new Segment(segment); 31 assertTrue(s.realEqual(segment ));31 assertTrue(s.realEqual(segment, false)); 32 32 } 33 33 -
test/org/openstreetmap/josm/data/osm/WayTest.java
r146 r203 21 21 Way w2 = createWay(42); 22 22 way.cloneFrom(w2); 23 assertTrue(way.realEqual(w2 ));23 assertTrue(way.realEqual(w2, false)); 24 24 assertEquals(w2.segments.size(), way.segments.size()); 25 25 } … … 28 28 Way w = new Way(way); 29 29 assertEquals(way.id, w.id); 30 assertTrue(way.realEqual(w ));30 assertTrue(way.realEqual(w, false)); 31 31 } 32 32 -
test/org/openstreetmap/josm/data/osm/visitor/MergeVisitorTest.java
r198 r203 197 197 s2.timestamp = new Date(); 198 198 v.visit(s2); 199 assertTrue(s1.realEqual(s2 ));199 assertTrue(s1.realEqual(s2, false)); 200 200 } 201 201 /** … … 312 312 assertEquals(1, ds.segments.size()); 313 313 } 314 314 315 /** 316 * The merger should auto-resolve items, that have not changed but are marked as 317 * changed. In the case where an unmodified newer item is merged over an modified 318 * older, the modified-flag should be removed and the newer timestamp is used. 319 */ 320 public void testMergeModifiedWithOlderTimestampOverUnmodifiedNewerDoesNotConflict() throws Exception { 321 DataSet ds = new DataSet(); 322 323 Node oldNode = createNodes(ds, 1)[0]; 324 oldNode.modified = true; 325 oldNode.timestamp = new Date(); 326 327 Node newNode = new Node(oldNode); 328 Date date = new Date(oldNode.timestamp.getTime()+10000); 329 newNode.modified = false; 330 newNode.timestamp = new Date(date.getTime()); 331 332 MergeVisitor v = new MergeVisitor(ds); 333 v.visit(newNode); 334 335 assertEquals(0, v.conflicts.size()); 336 assertEquals(date, ds.nodes.iterator().next().timestamp); 337 assertFalse(ds.nodes.iterator().next().modified); 338 } 315 339 }
Note:
See TracChangeset
for help on using the changeset viewer.