Changeset 11646 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2017-03-02T00:19:17+01:00 (8 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/history
- Files:
-
- 1 added
- 3 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserDialog.java
r10791 r11646 104 104 105 105 btn = new JButton(closeAction); 106 final String closeHistoryBrowserDialogKey = "CloseHistoryBrowserDialog";107 106 btn.setName("btn.close"); 108 107 pnl.add(btn); … … 158 157 } 159 158 160 publicvoid run() {159 void run() { 161 160 getHistoryBrowser().getModel().unlinkAsListener(); 162 161 HistoryDataSet.getInstance().removeHistoryDataSetListener(HistoryBrowserDialog.this); -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r11608 r11646 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.text.DateFormat;7 6 import java.util.ArrayList; 8 7 import java.util.Collections; … … 16 15 17 16 import org.openstreetmap.josm.Main; 18 import org.openstreetmap.josm.data.osm.Changeset;19 17 import org.openstreetmap.josm.data.osm.Node; 20 18 import org.openstreetmap.josm.data.osm.OsmPrimitive; … … 48 46 import org.openstreetmap.josm.gui.util.ChangeNotifier; 49 47 import org.openstreetmap.josm.tools.CheckParameterUtil; 50 import org.openstreetmap.josm.tools.date.DateUtils;51 48 52 49 /** … … 98 95 */ 99 96 public HistoryBrowserModel() { 100 versionTableModel = new VersionTableModel( );97 versionTableModel = new VersionTableModel(this); 101 98 currentTagTableModel = new TagTableModel(PointInTimeType.CURRENT_POINT_IN_TIME); 102 99 referenceTagTableModel = new TagTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME); … … 135 132 } 136 133 137 pr otectedboolean canShowAsLatest(OsmPrimitive primitive) {134 private boolean canShowAsLatest(OsmPrimitive primitive) { 138 135 if (primitive == null) 139 136 return false; … … 197 194 } 198 195 199 pr otectedvoid fireModelChange() {196 private void fireModelChange() { 200 197 initNodeListTableModels(); 201 198 initMemberListTableModels(); … … 214 211 } 215 212 216 pr otectedvoid initTagTableModels() {213 private void initTagTableModels() { 217 214 currentTagTableModel.initKeyList(); 218 215 referenceTagTableModel.initKeyList(); … … 223 220 * TODO: Maybe rename to reflect this? eg. updateNodeListTableModels 224 221 */ 225 pr otectedvoid initNodeListTableModels() {222 private void initNodeListTableModels() { 226 223 if (current == null || current.getType() != OsmPrimitiveType.WAY 227 224 || reference == null || reference.getType() != OsmPrimitiveType.WAY) … … 234 231 } 235 232 236 pr otectedvoid initMemberListTableModels() {233 private void initMemberListTableModels() { 237 234 if (current == null || current.getType() != OsmPrimitiveType.RELATION 238 235 || reference == null || reference.getType() != OsmPrimitiveType.RELATION) … … 397 394 398 395 /** 399 * The table model for the list of versions in the current history 400 * 401 */ 402 public final class VersionTableModel extends AbstractTableModel { 403 404 private VersionTableModel() { 405 } 406 407 @Override 408 public int getRowCount() { 409 if (history == null) 410 return 0; 411 int ret = history.getNumVersions(); 396 * Sets the reference point in time to the given row. 397 * @param row row number 398 */ 399 public void setReferencePointInTime(int row) { 400 if (history == null) 401 return; 402 if (row == history.getNumVersions()) { 412 403 if (latest != null) { 413 ret++; 414 } 415 return ret; 416 } 417 418 @Override 419 public Object getValueAt(int row, int column) { 420 switch (column) { 421 case VersionTableColumnModel.COL_VERSION: 422 HistoryOsmPrimitive p1 = getPrimitive(row); 423 if (p1 != null) 424 return Long.toString(p1.getVersion()); 425 return null; 426 case VersionTableColumnModel.COL_REFERENCE: 427 return isReferencePointInTime(row); 428 case VersionTableColumnModel.COL_CURRENT: 429 return isCurrentPointInTime(row); 430 case VersionTableColumnModel.COL_DATE: 431 HistoryOsmPrimitive p3 = getPrimitive(row); 432 if (p3 != null && p3.getTimestamp() != null) 433 return DateUtils.formatDateTime(p3.getTimestamp(), DateFormat.SHORT, DateFormat.SHORT); 434 return null; 435 case VersionTableColumnModel.COL_USER: 436 HistoryOsmPrimitive p4 = getPrimitive(row); 437 if (p4 != null) { 438 User user = p4.getUser(); 439 if (user != null) 440 return user.getName(); 441 } 442 return null; 443 case VersionTableColumnModel.COL_EDITOR: 444 HistoryOsmPrimitive p5 = getPrimitive(row); 445 if (p5 != null) { 446 Changeset cs = p5.getChangeset(); 447 if (cs != null) { 448 return cs.get("created_by"); 449 } 450 } 451 return null; 452 } 404 setReferencePointInTime(latest); 405 } 406 return; 407 } 408 if (row < 0 || row > history.getNumVersions()) 409 return; 410 setReferencePointInTime(history.get(row)); 411 } 412 413 /** 414 * Sets the current point in time to the given row. 415 * @param row row number 416 */ 417 public void setCurrentPointInTime(int row) { 418 if (history == null) 419 return; 420 if (row == history.getNumVersions()) { 421 if (latest != null) { 422 setCurrentPointInTime(latest); 423 } 424 return; 425 } 426 if (row < 0 || row > history.getNumVersions()) 427 return; 428 setCurrentPointInTime(history.get(row)); 429 } 430 431 /** 432 * Determines if the given row is the reference point in time. 433 * @param row row number 434 * @return {@code true} if the given row is the reference point in time 435 */ 436 public boolean isReferencePointInTime(int row) { 437 if (history == null) 438 return false; 439 if (row == history.getNumVersions()) 440 return latest == reference; 441 if (row < 0 || row > history.getNumVersions()) 442 return false; 443 return history.get(row) == reference; 444 } 445 446 /** 447 * Determines if the given row is the current point in time. 448 * @param row row number 449 * @return {@code true} if the given row is the current point in time 450 */ 451 public boolean isCurrentPointInTime(int row) { 452 if (history == null) 453 return false; 454 if (row == history.getNumVersions()) 455 return latest == current; 456 if (row < 0 || row > history.getNumVersions()) 457 return false; 458 return history.get(row) == current; 459 } 460 461 /** 462 * Returns the {@code HistoryPrimitive} at the given row. 463 * @param row row number 464 * @return the {@code HistoryPrimitive} at the given row 465 */ 466 public HistoryOsmPrimitive getPrimitive(int row) { 467 if (history == null) 453 468 return null; 454 } 455 456 @Override 457 public void setValueAt(Object aValue, int row, int column) { 458 if (!((Boolean) aValue)) 459 return; 460 switch (column) { 461 case 1: 462 setReferencePointInTime(row); 463 break; 464 case 2: 465 setCurrentPointInTime(row); 466 break; 467 default: 468 return; 469 } 470 fireTableDataChanged(); 471 } 472 473 @Override 474 public boolean isCellEditable(int row, int column) { 475 return column >= 1 && column <= 2; 476 } 477 478 public void setReferencePointInTime(int row) { 479 if (history == null) 480 return; 481 if (row == history.getNumVersions()) { 482 if (latest != null) { 483 HistoryBrowserModel.this.setReferencePointInTime(latest); 484 } 485 return; 486 } 487 if (row < 0 || row > history.getNumVersions()) 488 return; 489 HistoryOsmPrimitive reference = history.get(row); 490 HistoryBrowserModel.this.setReferencePointInTime(reference); 491 } 492 493 public void setCurrentPointInTime(int row) { 494 if (history == null) 495 return; 496 if (row == history.getNumVersions()) { 497 if (latest != null) { 498 HistoryBrowserModel.this.setCurrentPointInTime(latest); 499 } 500 return; 501 } 502 if (row < 0 || row > history.getNumVersions()) 503 return; 504 HistoryOsmPrimitive current = history.get(row); 505 HistoryBrowserModel.this.setCurrentPointInTime(current); 506 } 507 508 public boolean isReferencePointInTime(int row) { 509 if (history == null) 510 return false; 511 if (row == history.getNumVersions()) 512 return latest == reference; 513 if (row < 0 || row > history.getNumVersions()) 514 return false; 515 HistoryOsmPrimitive p = history.get(row); 516 return p == reference; 517 } 518 519 public boolean isCurrentPointInTime(int row) { 520 if (history == null) 521 return false; 522 if (row == history.getNumVersions()) 523 return latest == current; 524 if (row < 0 || row > history.getNumVersions()) 525 return false; 526 HistoryOsmPrimitive p = history.get(row); 527 return p == current; 528 } 529 530 public HistoryOsmPrimitive getPrimitive(int row) { 531 if (history == null) 532 return null; 533 return isLatest(row) ? latest : history.get(row); 534 } 535 536 public boolean isLatest(int row) { 537 return row >= history.getNumVersions(); 538 } 539 540 public OsmPrimitive getLatest() { 541 if (latest == null) 542 return null; 543 OsmDataLayer editLayer = Main.getLayerManager().getEditLayer(); 544 if (editLayer == null) 545 return null; 546 return editLayer.data.getPrimitiveById(latest.getId(), latest.getType()); 547 } 548 549 @Override 550 public int getColumnCount() { 551 return 6; 552 } 469 return isLatest(row) ? latest : history.get(row); 470 } 471 472 /** 473 * Determines if the given row is the latest. 474 * @param row row number 475 * @return {@code true} if the given row is the latest 476 */ 477 public boolean isLatest(int row) { 478 return row >= history.getNumVersions(); 479 } 480 481 /** 482 * Returns the latest {@code HistoryOsmPrimitive}. 483 * @return the latest {@code HistoryOsmPrimitive} 484 */ 485 public HistoryOsmPrimitive getLatest() { 486 return latest; 553 487 } 554 488 … … 558 492 * 559 493 */ 560 public class TagTableModel extends AbstractTableModel {494 public final class TagTableModel extends AbstractTableModel { 561 495 562 496 private List<String> keys; 563 497 private final PointInTimeType pointInTimeType; 564 498 565 pr otectedTagTableModel(PointInTimeType type) {499 private TagTableModel(PointInTimeType type) { 566 500 pointInTimeType = type; 567 501 initKeyList(); 568 502 } 569 503 570 pr otectedvoid initKeyList() {504 private void initKeyList() { 571 505 Set<String> keySet = new HashSet<>(); 572 506 if (current != null) { … … 603 537 } 604 538 539 /** 540 * Determines if a tag exists for the given key. 541 * @param key tag key 542 * @return {@code true} if a tag exists for the given key 543 */ 605 544 public boolean hasTag(String key) { 606 545 HistoryOsmPrimitive primitive = getPointInTime(pointInTimeType); … … 608 547 } 609 548 549 /** 550 * Returns the tag value for the given key. 551 * @param key tag key 552 * @return tag value, or null 553 */ 610 554 public String getValue(String key) { 611 555 HistoryOsmPrimitive primitive = getPointInTime(pointInTimeType); … … 615 559 } 616 560 561 /** 562 * Determines if a tag exists in the opposite point in time for the given key. 563 * @param key tag key 564 * @return {@code true} if a tag exists for the given key 565 */ 617 566 public boolean oppositeHasTag(String key) { 618 567 PointInTimeType opposite = pointInTimeType.opposite(); … … 621 570 } 622 571 572 /** 573 * Returns the tag value in the opposite point in time for the given key. 574 * @param key tag key 575 * @return tag value, or null 576 */ 623 577 public String getOppositeValue(String key) { 624 578 PointInTimeType opposite = pointInTimeType.opposite(); … … 629 583 } 630 584 585 /** 586 * Determines if the tag value is the same in the opposite point in time for the given key. 587 * @param key tag key 588 * @return {@code true} if the tag value is the same in the opposite point in time for the given key 589 */ 631 590 public boolean hasSameValueAsOpposite(String key) { 632 591 String value = getValue(key); … … 635 594 } 636 595 596 /** 597 * Returns the type of point in time. 598 * @return the type of point in time 599 */ 637 600 public PointInTimeType getPointInTimeType() { 638 601 return pointInTimeType; 639 602 } 640 603 604 /** 605 * Determines if this is the current point in time. 606 * @return {@code true} if this is the current point in time 607 */ 641 608 public boolean isCurrentPointInTime() { 642 609 return pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME); 643 610 } 644 611 612 /** 613 * Determines if this is the reference point in time. 614 * @return {@code true} if this is the reference point in time 615 */ 645 616 public boolean isReferencePointInTime() { 646 617 return pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME); … … 653 624 } 654 625 626 /** 627 * Sets the latest {@code HistoryOsmPrimitive}. 628 * @param latest the latest {@code HistoryOsmPrimitive} 629 */ 655 630 protected void setLatest(HistoryOsmPrimitive latest) { 656 631 if (latest == null) { … … 744 719 return; 745 720 OsmPrimitive primitive = event.getDataset().getPrimitiveById(history.getId(), history.getType()); 746 HistoryOsmPrimitive latest;721 HistoryOsmPrimitive newLatest; 747 722 if (canShowAsLatest(primitive)) { 748 latest = new HistoryPrimitiveBuilder().build(primitive);723 newLatest = new HistoryPrimitiveBuilder().build(primitive); 749 724 } else { 750 latest = null;751 } 752 setLatest( latest);725 newLatest = null; 726 } 727 setLatest(newLatest); 753 728 fireModelChange(); 754 729 } … … 825 800 } 826 801 827 publicHistoryOsmPrimitive build(OsmPrimitive primitive) {802 HistoryOsmPrimitive build(OsmPrimitive primitive) { 828 803 primitive.accept(this); 829 804 return clone; -
trunk/src/org/openstreetmap/josm/gui/history/VersionTable.java
r11322 r11646 58 58 } 59 59 60 /** 61 * Builds the table. 62 */ 60 63 protected void build() { 61 64 getTableHeader().setFont(getTableHeader().getFont().deriveFont(9f)); … … 108 111 } 109 112 110 protected HistoryBrowserModel.VersionTableModel getVersionTableModel() {111 return (HistoryBrowserModel.VersionTableModel) getModel();112 }113 114 113 @Override 115 114 public void stateChanged(ChangeEvent e) { … … 129 128 int col = columnAtPoint(e.getPoint()); 130 129 if (row >= 0 && (col == VersionTableColumnModel.COL_DATE || col == VersionTableColumnModel.COL_USER)) { 131 model. getVersionTableModel().setCurrentPointInTime(row);132 model. getVersionTableModel().setReferencePointInTime(Math.max(0, row - 1));130 model.setCurrentPointInTime(row); 131 model.setReferencePointInTime(Math.max(0, row - 1)); 133 132 } 134 133 } … … 137 136 @Override 138 137 protected int checkTableSelection(JTable table, Point p) { 139 HistoryBrowserModel.VersionTableModel tableModel = getVersionTableModel();140 138 int row = rowAtPoint(p); 141 if (row > -1 && ! tableModel.isLatest(row)) {142 popupMenu.prepare( tableModel.getPrimitive(row));139 if (row > -1 && !model.isLatest(row)) { 140 popupMenu.prepare(model.getPrimitive(row)); 143 141 } 144 142 return row; … … 315 313 } 316 314 317 // for unit tests 318 private AlignedRenderer() { 315 AlignedRenderer() { 319 316 this(SwingConstants.LEFT); 320 317 }
Note:
See TracChangeset
for help on using the changeset viewer.