Changeset 1690 in josm for trunk/src/org/openstreetmap/josm/gui/conflict/properties/PropertiesMerger.java
- Timestamp:
- 23.06.2009 22:03:37 (3 years ago)
- File:
-
- 1 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/conflict/properties/PropertiesMerger.java
r1676 r1690 18 18 import javax.swing.JButton; 19 19 import javax.swing.JLabel; 20 import javax.swing.JOptionPane; 20 21 import javax.swing.JPanel; 21 22 import javax.swing.SwingUtilities; 23 24 import org.openstreetmap.josm.Main; 22 25 import org.openstreetmap.josm.data.coor.LatLon; 26 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 23 27 import org.openstreetmap.josm.gui.conflict.MergeDecisionType; 24 28 import org.openstreetmap.josm.tools.ImageProvider; … … 48 52 private JLabel lblTheirDeletedState; 49 53 54 private JLabel lblMyVisibleState; 55 private JLabel lblMergedVisibleState; 56 private JLabel lblTheirVisibleState; 57 50 58 private final PropertiesMergeModel model; 51 59 … … 59 67 } 60 68 61 protected void build() { 62 setLayout(new GridBagLayout()); 69 protected void buildHeaderRow() { 63 70 GridBagConstraints gc = new GridBagConstraints(); 64 71 65 // ------------------66 72 gc.gridx = 1; 67 73 gc.gridy = 0; … … 88 94 lblTheirVersion.setToolTipText(tr("Properties in their dataset, i.e. the server dataset")); 89 95 add(lblTheirVersion, gc); 90 91 // -------------------------------- 96 } 97 98 protected void buildCoordinateConflictRows() { 99 GridBagConstraints gc = new GridBagConstraints(); 100 92 101 gc.gridx = 0; 93 102 gc.gridy = 1; … … 161 170 JButton btnUndecideCoordinates = new JButton(actUndecideCoordinates); 162 171 add(btnUndecideCoordinates, gc); 163 // --------------------------------------------------- 172 } 173 174 protected void buildDeletedStateConflictRows() { 175 GridBagConstraints gc = new GridBagConstraints(); 164 176 165 177 gc.gridx = 0; … … 191 203 model.addObserver(actKeepMyDeletedState); 192 204 JButton btnKeepMyDeletedState = new JButton(actKeepMyDeletedState); 193 btnKeepMy Coordinates.setName("button.keepmydeletedstate");205 btnKeepMyDeletedState.setName("button.keepmydeletedstate"); 194 206 add(btnKeepMyDeletedState, gc); 195 207 … … 212 224 model.addObserver(actKeepTheirDeletedState); 213 225 JButton btnKeepTheirDeletedState = new JButton(actKeepTheirDeletedState); 214 btnKeep MyCoordinates.setName("button.keeptheirdeletedstate");226 btnKeepTheirDeletedState.setName("button.keeptheirdeletedstate"); 215 227 add(btnKeepTheirDeletedState, gc); 216 228 … … 233 245 model.addObserver(actUndecideDeletedState); 234 246 JButton btnUndecideDeletedState = new JButton(actUndecideDeletedState); 235 btn KeepMyCoordinates.setName("button.undecidedeletedstate");247 btnUndecideDeletedState.setName("button.undecidedeletedstate"); 236 248 add(btnUndecideDeletedState, gc); 237 249 } 250 251 protected void buildVisibleStateRows() { 252 GridBagConstraints gc = new GridBagConstraints(); 253 254 gc.gridx = 0; 255 gc.gridy = 5; 256 gc.gridwidth = 1; 257 gc.gridheight = 1; 258 gc.fill = GridBagConstraints.BOTH; 259 gc.anchor = GridBagConstraints.LINE_START; 260 gc.weightx = 0.0; 261 gc.weighty = 0.0; 262 gc.insets = new Insets(0,5,0,5); 263 add(new JLabel(tr("Visible State:")), gc); 264 265 gc.gridx = 1; 266 gc.gridy = 5; 267 gc.fill = GridBagConstraints.BOTH; 268 gc.anchor = GridBagConstraints.CENTER; 269 gc.weightx = 0.33; 270 gc.weighty = 0.0; 271 add(lblMyVisibleState = buildValueLabel("label.myvisiblestate"), gc); 272 273 gc.gridx = 2; 274 gc.gridy = 5; 275 gc.fill = GridBagConstraints.NONE; 276 gc.anchor = GridBagConstraints.CENTER; 277 gc.weightx = 0.0; 278 gc.weighty = 0.0; 279 KeepMyVisibleStateAction actKeepMyVisibleState = new KeepMyVisibleStateAction(); 280 model.addObserver(actKeepMyVisibleState); 281 JButton btnKeepMyVisibleState = new JButton(actKeepMyVisibleState); 282 btnKeepMyVisibleState.setName("button.keepmyvisiblestate"); 283 add(btnKeepMyVisibleState, gc); 284 285 gc.gridx = 3; 286 gc.gridy = 5; 287 gc.fill = GridBagConstraints.BOTH; 288 gc.anchor = GridBagConstraints.CENTER; 289 gc.weightx = 0.33; 290 gc.weighty = 0.0; 291 add(lblMergedVisibleState = buildValueLabel("label.mergedvisiblestate"), gc); 292 293 gc.gridx = 4; 294 gc.gridy = 5; 295 gc.fill = GridBagConstraints.NONE; 296 gc.anchor = GridBagConstraints.CENTER; 297 gc.weightx = 0.0; 298 gc.weighty = 0.0; 299 KeepTheirVisibleStateAction actKeepTheirVisibleState = new KeepTheirVisibleStateAction(); 300 model.addObserver(actKeepTheirVisibleState); 301 JButton btnKeepTheirVisibleState = new JButton(actKeepTheirVisibleState); 302 btnKeepTheirVisibleState.setName("button.keeptheirvisiblestate"); 303 add(btnKeepTheirVisibleState, gc); 304 305 gc.gridx = 5; 306 gc.gridy = 5; 307 gc.fill = GridBagConstraints.BOTH; 308 gc.anchor = GridBagConstraints.CENTER; 309 gc.weightx = 0.33; 310 gc.weighty = 0.0; 311 add(lblTheirVisibleState = buildValueLabel("label.theirvisiblestate"), gc); 312 313 // --------------------------------------------------- 314 gc.gridx = 3; 315 gc.gridy = 6; 316 gc.fill = GridBagConstraints.NONE; 317 gc.anchor = GridBagConstraints.CENTER; 318 gc.weightx = 0.0; 319 gc.weighty = 0.0; 320 UndecideVisibleStateConflictAction actUndecideVisibleState = new UndecideVisibleStateConflictAction(); 321 model.addObserver(actUndecideVisibleState); 322 JButton btnUndecideVisibleState = new JButton(actUndecideVisibleState); 323 btnUndecideVisibleState.setName("button.undecidevisiblestate"); 324 add(btnUndecideVisibleState, gc); 325 } 326 327 protected void build() { 328 setLayout(new GridBagLayout()); 329 buildHeaderRow(); 330 buildCoordinateConflictRows(); 331 buildDeletedStateConflictRows(); 332 buildVisibleStateRows(); 238 333 } 239 334 … … 265 360 } 266 361 267 protected void updateCoordiates() { 362 public String visibleStateToString(Boolean visible) { 363 if (visible == null) 364 return tr("(none)"); 365 if (visible) 366 return tr("visible (on the server)"); 367 else 368 return tr("not visible (on the server)"); 369 } 370 371 public String visibleStateToStringMerged(Boolean visible) { 372 if (visible == null) 373 return tr("(none)"); 374 if (visible) 375 return tr("Keep a clone of the local version"); 376 else 377 return tr("Physically delete from local dataset"); 378 } 379 380 protected void updateCoordinates() { 268 381 lblMyCoordinates.setText(coordToString(model.getMyCoords())); 269 382 lblMergedCoordinates.setText(coordToString(model.getMergedCoords())); … … 320 433 } 321 434 435 protected void updateVisibleState() { 436 lblMyVisibleState.setText(visibleStateToString(model.getMyVisibleState())); 437 lblMergedVisibleState.setText(visibleStateToStringMerged(model.getMergedVisibleState())); 438 lblTheirVisibleState.setText(visibleStateToString(model.getTheirVisibleState())); 439 440 if (! model.hasVisibleStateConflict()) { 441 lblMyVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 442 lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 443 lblTheirVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 444 } else { 445 if (!model.isDecidedVisibleState()) { 446 lblMyVisibleState.setBackground(BGCOLOR_UNDECIDED); 447 lblMergedVisibleState.setBackground(BGCOLOR_NO_CONFLICT); 448 lblTheirVisibleState.setBackground(BGCOLOR_UNDECIDED); 449 } else { 450 lblMyVisibleState.setBackground( 451 model.isVisibleStateDecision(MergeDecisionType.KEEP_MINE) 452 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT 453 ); 454 lblMergedVisibleState.setBackground(BGCOLOR_DECIDED); 455 lblTheirVisibleState.setBackground( 456 model.isVisibleStateDecision(MergeDecisionType.KEEP_THEIR) 457 ? BGCOLOR_DECIDED : BGCOLOR_NO_CONFLICT 458 ); 459 } 460 } 461 } 462 322 463 public void update(Observable o, Object arg) { 323 updateCoordi ates();464 updateCoordinates(); 324 465 updateDeletedState(); 466 updateVisibleState(); 325 467 } 326 468 … … 418 560 } 419 561 } 562 563 class KeepMyVisibleStateAction extends AbstractAction implements Observer { 564 public KeepMyVisibleStateAction() { 565 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeepmine")); 566 putValue(Action.SHORT_DESCRIPTION, tr("Keep my visible state")); 567 } 568 569 public void actionPerformed(ActionEvent e) { 570 if (confirmKeepMine()) { 571 model.decideVisibleStateConflict(MergeDecisionType.KEEP_MINE); 572 } 573 } 574 575 public void update(Observable o, Object arg) { 576 setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState()); 577 } 578 579 protected boolean confirmKeepMine() { 580 String [] options = { 581 tr("Yes, reset the id"), 582 tr("No, abort") 583 }; 584 int ret = JOptionPane.showOptionDialog( 585 null, 586 tr("<html>To keep your local version, JOSM<br>" 587 + "has to reset the id of {0} {1} to 0.<br>" 588 + "On the next upload the server will assign<br>" 589 + "it a new id.<br>" 590 + "Do yo agree?</html>", 591 OsmPrimitiveType.from(model.getMyPrimitive()).getLocalizedDisplayNamePlural(), 592 model.getMyPrimitive().id 593 ), 594 tr("Reset id to 0"), 595 JOptionPane.YES_NO_OPTION, 596 JOptionPane.QUESTION_MESSAGE, 597 null, 598 options, 599 options[1] 600 ); 601 return ret == JOptionPane.YES_OPTION; 602 } 603 } 604 605 class KeepTheirVisibleStateAction extends AbstractAction implements Observer { 606 public KeepTheirVisibleStateAction() { 607 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagkeeptheir")); 608 putValue(Action.SHORT_DESCRIPTION, tr("Keep their visible state")); 609 } 610 611 public void actionPerformed(ActionEvent e) { 612 if (confirmKeepTheir()){ 613 model.decideVisibleStateConflict(MergeDecisionType.KEEP_THEIR); 614 } 615 } 616 617 public void update(Observable o, Object arg) { 618 setEnabled(model.hasVisibleStateConflict() && ! model.isDecidedVisibleState()); 619 } 620 621 protected boolean confirmKeepTheir() { 622 String [] options = { 623 tr("Yes, purge it"), 624 tr("No, abort") 625 }; 626 int ret = JOptionPane.showOptionDialog( 627 null, 628 tr("<html>JOSM will have to remove your local primitive with id {0}<br>" 629 + "from the dataset.<br>" 630 + "Do you agree?</html>", 631 model.getMyPrimitive().id 632 ), 633 tr("Remove from dataset"), 634 JOptionPane.YES_NO_OPTION, 635 JOptionPane.QUESTION_MESSAGE, 636 null, 637 options, 638 options[1] 639 ); 640 return ret == JOptionPane.YES_OPTION; 641 } 642 } 643 644 class UndecideVisibleStateConflictAction extends AbstractAction implements Observer { 645 public UndecideVisibleStateConflictAction() { 646 putValue(Action.SMALL_ICON, ImageProvider.get("dialogs/conflict", "tagundecide")); 647 putValue(Action.SHORT_DESCRIPTION, tr("Undecide conflict between visible state")); 648 } 649 650 public void actionPerformed(ActionEvent e) { 651 model.decideVisibleStateConflict(MergeDecisionType.UNDECIDED); 652 } 653 654 public void update(Observable o, Object arg) { 655 setEnabled(model.hasVisibleStateConflict() && model.isDecidedVisibleState()); 656 } 657 } 420 658 }
Note: See TracChangeset
for help on using the changeset viewer.
