Changeset 9601 in josm
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/dialogs/ConflictDialog.java
r9452 r9601 71 71 * This dialog displays the {@link ConflictCollection} of the active {@link OsmDataLayer} in a toggle 72 72 * dialog on the right of the main frame. 73 * 73 * @since 86 74 74 */ 75 75 public final class ConflictDialog extends ToggleDialog implements MapView.EditLayerChangeListener, IConflictListener, SelectionChangedListener { 76 77 /** the collection of conflicts displayed by this conflict dialog */ 78 private transient ConflictCollection conflicts; 79 80 /** the model for the list of conflicts */ 81 private transient ConflictListModel model; 82 /** the list widget for the list of conflicts */ 83 private JList<OsmPrimitive> lstConflicts; 84 85 private final JPopupMenu popupMenu = new JPopupMenu(); 86 private final transient PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu); 87 88 private final ResolveAction actResolve = new ResolveAction(); 89 private final SelectAction actSelect = new SelectAction(); 90 91 /** 92 * Constructs a new {@code ConflictDialog}. 93 */ 94 public ConflictDialog() { 95 super(tr("Conflict"), "conflict", tr("Resolve conflicts."), 96 Shortcut.registerShortcut("subwindow:conflict", tr("Toggle: {0}", tr("Conflict")), 97 KeyEvent.VK_C, Shortcut.ALT_SHIFT), 100); 98 99 build(); 100 refreshView(); 101 } 76 102 77 103 /** … … 85 111 return Main.pref.getColor(marktr("conflict"), Color.gray); 86 112 } 87 88 /** the collection of conflicts displayed by this conflict dialog */89 private transient ConflictCollection conflicts;90 91 /** the model for the list of conflicts */92 private transient ConflictListModel model;93 /** the list widget for the list of conflicts */94 private JList<OsmPrimitive> lstConflicts;95 96 private final JPopupMenu popupMenu = new JPopupMenu();97 private final transient PopupMenuHandler popupMenuHandler = new PopupMenuHandler(popupMenu);98 99 private ResolveAction actResolve;100 private SelectAction actSelect;101 113 102 114 /** … … 117 129 }); 118 130 119 SideButton btnResolve = new SideButton(actResolve = new ResolveAction());131 SideButton btnResolve = new SideButton(actResolve); 120 132 addListSelectionListener(actResolve); 121 133 122 SideButton btnSelect = new SideButton(actSelect = new SelectAction());134 SideButton btnSelect = new SideButton(actSelect); 123 135 addListSelectionListener(actSelect); 124 136 … … 155 167 } 156 168 157 /**158 * constructor159 */160 public ConflictDialog() {161 super(tr("Conflict"), "conflict", tr("Resolve conflicts."),162 Shortcut.registerShortcut("subwindow:conflict", tr("Toggle: {0}", tr("Conflict")),163 KeyEvent.VK_C, Shortcut.ALT_SHIFT), 100);164 165 build();166 refreshView();167 }168 169 169 @Override 170 170 public void showNotify() { … … 209 209 /** 210 210 * Launches a conflict resolution dialog for the first selected conflict 211 *212 211 */ 213 212 private void resolve() { 214 if (conflicts == null || model.getSize() == 0) return; 213 if (conflicts == null || model.getSize() == 0) 214 return; 215 215 216 216 int index = lstConflicts.getSelectedIndex(); … … 234 234 public void refreshView() { 235 235 OsmDataLayer editLayer = Main.main.getEditLayer(); 236 conflicts = (editLayer == null ? new ConflictCollection() : editLayer.getConflicts());236 conflicts = editLayer == null ? new ConflictCollection() : editLayer.getConflicts(); 237 237 GuiHelper.runInEDT(new Runnable() { 238 238 @Override … … 269 269 return; 270 270 g.setColor(preferencesColor); 271 Visitor conflictPainter = new AbstractVisitor() { 272 // Manage a stack of visited relations to avoid infinite recursion with cyclic relations (fix #7938) 273 private final Set<Relation> visited = new HashSet<>(); 274 @Override 275 public void visit(Node n) { 276 Point p = nc.getPoint(n); 277 g.drawRect(p.x-1, p.y-1, 2, 2); 278 } 279 280 public void visit(Node n1, Node n2) { 281 Point p1 = nc.getPoint(n1); 282 Point p2 = nc.getPoint(n2); 283 g.drawLine(p1.x, p1.y, p2.x, p2.y); 284 } 285 286 @Override 287 public void visit(Way w) { 288 Node lastN = null; 289 for (Node n : w.getNodes()) { 290 if (lastN == null) { 291 lastN = n; 292 continue; 293 } 294 visit(lastN, n); 295 lastN = n; 296 } 297 } 298 299 @Override 300 public void visit(Relation e) { 301 if (!visited.contains(e)) { 302 visited.add(e); 303 try { 304 for (RelationMember em : e.getMembers()) { 305 em.getMember().accept(this); 306 } 307 } finally { 308 visited.remove(e); 309 } 310 } 311 } 312 }; 271 Visitor conflictPainter = new ConflictPainter(nc, g); 313 272 for (OsmPrimitive o : lstConflicts.getSelectedValuesList()) { 314 273 if (conflicts == null || !conflicts.hasConflictForMy(o)) { … … 330 289 } 331 290 332 333 291 /** 334 292 * replies the conflict collection currently held by this dialog; may be null … … 346 304 */ 347 305 public Conflict<? extends OsmPrimitive> getSelectedConflict() { 348 if (conflicts == null || model.getSize() == 0) return null; 306 if (conflicts == null || model.getSize() == 0) 307 return null; 349 308 350 309 int index = lstConflicts.getSelectedIndex(); 351 if (index < 0) return null; 352 353 return conflicts.get(index); 310 311 return index >= 0 ? conflicts.get(index) : null; 354 312 } 355 313 356 314 private boolean isConflictSelected() { 357 final ListSelectionModel model = lstConflicts.getSelectionModel();358 return model.getMinSelectionIndex() >= 0 &&model.getMaxSelectionIndex() >=model.getMinSelectionIndex();315 final ListSelectionModel selModel = lstConflicts.getSelectionModel(); 316 return selModel.getMinSelectionIndex() >= 0 && selModel.getMaxSelectionIndex() >= selModel.getMinSelectionIndex(); 359 317 } 360 318 … … 444 402 @Override 445 403 public OsmPrimitive getElementAt(int index) { 446 if (index < 0 ) return null;447 if (index >= getSize())return null;404 if (index < 0 || index >= getSize()) 405 return null; 448 406 return conflicts.get(index).getMy(); 449 407 } … … 451 409 @Override 452 410 public int getSize() { 453 if (conflicts == null) return 0; 454 return conflicts.size(); 411 return conflicts != null ? conflicts.size() : 0; 455 412 } 456 413 457 414 public int indexOf(OsmPrimitive my) { 458 if (conflicts == null) return -1; 459 for (int i = 0; i < conflicts.size(); i++) { 460 if (conflicts.get(i).isMatchingMy(my)) 461 return i; 415 if (conflicts != null) { 416 for (int i = 0; i < conflicts.size(); i++) { 417 if (conflicts.get(i).isMatchingMy(my)) 418 return i; 419 } 462 420 } 463 421 return -1; … … 465 423 466 424 public OsmPrimitive get(int idx) { 467 if (conflicts == null) return null; 468 return conflicts.get(idx).getMy(); 425 return conflicts != null ? conflicts.get(idx).getMy() : null; 469 426 } 470 427 } … … 529 486 for (OsmPrimitive osmPrimitive : lstConflicts.getSelectedValuesList()) { 530 487 Conflict<? extends OsmPrimitive> c = conflicts.getConflictForMy(osmPrimitive); 531 resolver.populate(c); 532 resolver.decideRemaining(type); 533 commands.add(resolver.buildResolveCommand()); 488 if (c != null) { 489 resolver.populate(c); 490 resolver.decideRemaining(type); 491 commands.add(resolver.buildResolveCommand()); 492 } 534 493 } 535 494 Main.main.undoRedo.add(new SequenceCommand(name, commands)); … … 553 512 } 554 513 514 class ConflictPainter extends AbstractVisitor { 515 // Manage a stack of visited relations to avoid infinite recursion with cyclic relations (fix #7938) 516 private final Set<Relation> visited = new HashSet<>(); 517 private final NavigatableComponent nc; 518 private final Graphics g; 519 520 ConflictPainter(NavigatableComponent nc, Graphics g) { 521 this.nc = nc; 522 this.g = g; 523 } 524 525 @Override 526 public void visit(Node n) { 527 Point p = nc.getPoint(n); 528 g.drawRect(p.x-1, p.y-1, 2, 2); 529 } 530 531 public void visit(Node n1, Node n2) { 532 Point p1 = nc.getPoint(n1); 533 Point p2 = nc.getPoint(n2); 534 g.drawLine(p1.x, p1.y, p2.x, p2.y); 535 } 536 537 @Override 538 public void visit(Way w) { 539 Node lastN = null; 540 for (Node n : w.getNodes()) { 541 if (lastN == null) { 542 lastN = n; 543 continue; 544 } 545 visit(lastN, n); 546 lastN = n; 547 } 548 } 549 550 @Override 551 public void visit(Relation e) { 552 if (!visited.contains(e)) { 553 visited.add(e); 554 try { 555 for (RelationMember em : e.getMembers()) { 556 em.getMember().accept(this); 557 } 558 } finally { 559 visited.remove(e); 560 } 561 } 562 } 563 } 564 555 565 /** 556 566 * Warns the user about the number of detected conflicts … … 560 570 */ 561 571 public void warnNumNewConflicts(int numNewConflicts) { 562 if (numNewConflicts == 0) return; 572 if (numNewConflicts == 0) 573 return; 563 574 564 575 String msg1 = trn( -
trunk/test/unit/org/openstreetmap/josm/gui/dialogs/LatLonDialogTest.java
r8857 r9601 16 16 */ 17 17 @Test 18 public void test parseLatLon() {18 public void testParseLatLon() { 19 19 assertEquals(new LatLon(49.29918, 19.24788), LatLonDialog.parseLatLon("49.29918° 19.24788°")); 20 20 assertEquals(new LatLon(49.29918, 19.24788), LatLonDialog.parseLatLon("N 49.29918 E 19.24788°"));
Note:
See TracChangeset
for help on using the changeset viewer.