Changeset 11647 in josm for trunk/src/org
- Timestamp:
- 2017-03-02T00:32:19+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/HistoryBrowserModel.java
r11646 r11647 4 4 import static org.openstreetmap.josm.tools.I18n.tr; 5 5 6 import java.util.ArrayList;7 import java.util.Collections;8 6 import java.util.HashSet; 9 import java.util.List;10 7 import java.util.Set; 11 8 12 9 import javax.swing.JTable; 13 import javax.swing.table.AbstractTableModel;14 10 import javax.swing.table.TableModel; 15 11 … … 96 92 public HistoryBrowserModel() { 97 93 versionTableModel = new VersionTableModel(this); 98 currentTagTableModel = new TagTableModel( PointInTimeType.CURRENT_POINT_IN_TIME);99 referenceTagTableModel = new TagTableModel( PointInTimeType.REFERENCE_POINT_IN_TIME);94 currentTagTableModel = new TagTableModel(this, PointInTimeType.CURRENT_POINT_IN_TIME); 95 referenceTagTableModel = new TagTableModel(this, PointInTimeType.REFERENCE_POINT_IN_TIME); 100 96 referenceNodeListTableModel = new DiffTableModel(); 101 97 currentNodeListTableModel = new DiffTableModel(); … … 482 478 * Returns the latest {@code HistoryOsmPrimitive}. 483 479 * @return the latest {@code HistoryOsmPrimitive} 480 * @since 11646 484 481 */ 485 482 public HistoryOsmPrimitive getLatest() { … … 488 485 489 486 /** 490 * The table model for the tags of the version at {@link PointInTimeType#REFERENCE_POINT_IN_TIME} 491 * or {@link PointInTimeType#CURRENT_POINT_IN_TIME} 492 * 493 */ 494 public final class TagTableModel extends AbstractTableModel { 495 496 private List<String> keys; 497 private final PointInTimeType pointInTimeType; 498 499 private TagTableModel(PointInTimeType type) { 500 pointInTimeType = type; 501 initKeyList(); 502 } 503 504 private void initKeyList() { 505 Set<String> keySet = new HashSet<>(); 506 if (current != null) { 507 keySet.addAll(current.getTags().keySet()); 508 } 509 if (reference != null) { 510 keySet.addAll(reference.getTags().keySet()); 511 } 512 keys = new ArrayList<>(keySet); 513 Collections.sort(keys); 514 fireTableDataChanged(); 515 } 516 517 @Override 518 public int getRowCount() { 519 if (keys == null) 520 return 0; 521 return keys.size(); 522 } 523 524 @Override 525 public Object getValueAt(int row, int column) { 526 return getKeyAt(row); 527 } 528 529 /** 530 * Get the key for the given row. 531 * @param row The row 532 * @return The key in that row. 533 * @since 10637 534 */ 535 public String getKeyAt(int row) { 536 return keys.get(row); 537 } 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 */ 544 public boolean hasTag(String key) { 545 HistoryOsmPrimitive primitive = getPointInTime(pointInTimeType); 546 return primitive != null && primitive.hasKey(key); 547 } 548 549 /** 550 * Returns the tag value for the given key. 551 * @param key tag key 552 * @return tag value, or null 553 */ 554 public String getValue(String key) { 555 HistoryOsmPrimitive primitive = getPointInTime(pointInTimeType); 556 if (primitive == null) 557 return null; 558 return primitive.get(key); 559 } 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 */ 566 public boolean oppositeHasTag(String key) { 567 PointInTimeType opposite = pointInTimeType.opposite(); 568 HistoryOsmPrimitive primitive = getPointInTime(opposite); 569 return primitive != null && primitive.hasKey(key); 570 } 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 */ 577 public String getOppositeValue(String key) { 578 PointInTimeType opposite = pointInTimeType.opposite(); 579 HistoryOsmPrimitive primitive = getPointInTime(opposite); 580 if (primitive == null) 581 return null; 582 return primitive.get(key); 583 } 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 */ 590 public boolean hasSameValueAsOpposite(String key) { 591 String value = getValue(key); 592 String oppositeValue = getOppositeValue(key); 593 return value != null && value.equals(oppositeValue); 594 } 595 596 /** 597 * Returns the type of point in time. 598 * @return the type of point in time 599 */ 600 public PointInTimeType getPointInTimeType() { 601 return pointInTimeType; 602 } 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 */ 608 public boolean isCurrentPointInTime() { 609 return pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME); 610 } 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 */ 616 public boolean isReferencePointInTime() { 617 return pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME); 618 } 619 620 @Override 621 public int getColumnCount() { 622 return 2; 623 } 487 * Returns the key set (union of current and reference point in type key sets). 488 * @return the key set (union of current and reference point in type key sets) 489 * @since 11647 490 */ 491 public Set<String> getKeySet() { 492 Set<String> keySet = new HashSet<>(); 493 if (current != null) { 494 keySet.addAll(current.getTags().keySet()); 495 } 496 if (reference != null) { 497 keySet.addAll(reference.getTags().keySet()); 498 } 499 return keySet; 624 500 } 625 501 -
trunk/src/org/openstreetmap/josm/gui/history/TagInfoTransferHandler.java
r10755 r11647 13 13 import org.openstreetmap.josm.gui.datatransfer.TagTransferable; 14 14 import org.openstreetmap.josm.gui.datatransfer.data.TagTransferData; 15 import org.openstreetmap.josm.gui.history.HistoryBrowserModel.TagTableModel;16 15 17 16 /** -
trunk/src/org/openstreetmap/josm/gui/history/TagTableCellRenderer.java
r10670 r11647 33 33 } 34 34 35 protected void setBackgroundReadable(String key, HistoryBrowserModel.TagTableModel model, boolean isSelected, boolean hasFocus, 36 boolean isValue) { 35 protected void setBackgroundReadable(String key, TagTableModel model, boolean isSelected, boolean hasFocus, boolean isValue) { 37 36 Color bgColor = UIManager.getColor("Table.background"); 38 37 if ((!model.hasTag(key) && model.isCurrentPointInTime()) … … 64 63 65 64 String key = (String) value; 66 HistoryBrowserModel.TagTableModel model = getTagTableModel(table);65 TagTableModel model = getTagTableModel(table); 67 66 68 67 String text = ""; … … 87 86 } 88 87 89 protected HistoryBrowserModel.TagTableModel getTagTableModel(JTable table) {90 return ( HistoryBrowserModel.TagTableModel) table.getModel();88 protected TagTableModel getTagTableModel(JTable table) { 89 return (TagTableModel) table.getModel(); 91 90 } 92 91 }
Note:
See TracChangeset
for help on using the changeset viewer.