Changeset 5627 in josm for trunk/src/org
- Timestamp:
- 2012-12-20T22:43:02+01:00 (12 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/history
- Files:
-
- 6 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/DiffTableModel.java
r5266 r5627 6 6 7 7 import javax.swing.table.AbstractTableModel; 8 9 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType; 8 10 9 11 /** … … 39 41 return rows.get(rowIndex); 40 42 } 43 44 public int getFirstChange() { 45 for (int i=0; i<rows.size(); i++) { 46 if (rows.get(i).state != DiffItemType.SAME) 47 return i; 48 } 49 return -1; 50 } 41 51 } -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r5495 r5627 42 42 import org.openstreetmap.josm.gui.MapView; 43 43 import org.openstreetmap.josm.gui.MapView.LayerChangeListener; 44 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType; 44 45 import org.openstreetmap.josm.gui.layer.Layer; 45 46 import org.openstreetmap.josm.gui.layer.OsmDataLayer; … … 86 87 private TagTableModel currentTagTableModel; 87 88 private TagTableModel referenceTagTableModel; 88 private RelationMemberTableModel currentRelationMemberTableModel;89 private RelationMemberTableModel referenceRelationMemberTableModel;89 private DiffTableModel currentRelationMemberTableModel; 90 private DiffTableModel referenceRelationMemberTableModel; 90 91 private DiffTableModel referenceNodeListTableModel; 91 92 private DiffTableModel currentNodeListTableModel; … … 100 101 referenceNodeListTableModel = new DiffTableModel(); 101 102 currentNodeListTableModel = new DiffTableModel(); 102 currentRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME);103 referenceRelationMemberTableModel = new RelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME);103 currentRelationMemberTableModel = new DiffTableModel(); 104 referenceRelationMemberTableModel = new DiffTableModel(); 104 105 105 106 if (getEditLayer() != null) { … … 208 209 protected void fireModelChange() { 209 210 initNodeListTableModels(); 211 initMemberListTableModels(); 210 212 setChanged(); 211 213 notifyObservers(); … … 247 249 248 250 protected void initMemberListTableModels() { 251 if(current.getType() != OsmPrimitiveType.RELATION || reference.getType() != OsmPrimitiveType.RELATION) 252 return; 253 254 TwoColumnDiff diff = new TwoColumnDiff( 255 ((HistoryRelation)reference).getMembers().toArray(), 256 ((HistoryRelation)current).getMembers().toArray()); 257 258 referenceRelationMemberTableModel.setRows(diff.referenceDiff); 259 currentRelationMemberTableModel.setRows(diff.currentDiff); 260 249 261 currentRelationMemberTableModel.fireTableDataChanged(); 250 262 referenceRelationMemberTableModel.fireTableDataChanged(); … … 280 292 } 281 293 282 public RelationMemberTableModel getRelationMemberTableModel(PointInTimeType pointInTimeType) throws IllegalArgumentException {294 public DiffTableModel getRelationMemberTableModel(PointInTimeType pointInTimeType) throws IllegalArgumentException { 283 295 CheckParameterUtil.ensureParameterNotNull(pointInTimeType, "pointInTimeType"); 284 296 if (pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME)) … … 429 441 return isCurrentPointInTime(row); 430 442 case 3: { 431 HistoryOsmPrimitive p = getPrimitive(row); 432 if (p != null && p.getTimestamp() != null) 433 return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(p.getTimestamp()); 434 return null; 443 HistoryOsmPrimitive p = getPrimitive(row); 444 if (p != null && p.getTimestamp() != null) 445 return DateFormat.getDateTimeInstance(DateFormat.SHORT, DateFormat.SHORT).format(p.getTimestamp()); 446 return null; 447 } 448 case 4: { 449 HistoryOsmPrimitive p = getPrimitive(row); 450 if (p != null) { 451 User user = p.getUser(); 452 if (user != null) 453 return "<html>" + XmlWriter.encode(user.getName(), true) + " <font color=gray>(" + user.getId() + ")</font></html>"; 435 454 } 436 case 4: { 437 HistoryOsmPrimitive p = getPrimitive(row); 438 if (p != null) { 439 User user = p.getUser(); 440 if (user != null) 441 return "<html>" + XmlWriter.encode(user.getName(), true) + " <font color=gray>(" + user.getId() + ")</font></html>"; 442 } 443 return null; 444 } 455 return null; 456 } 445 457 } 446 458 return null; … … 635 647 } 636 648 637 /**638 * The table model for the relation members of the version at {@link PointInTimeType#REFERENCE_POINT_IN_TIME}639 * or {@link PointInTimeType#CURRENT_POINT_IN_TIME}640 *641 */642 643 public class RelationMemberTableModel extends AbstractTableModel {644 645 private PointInTimeType pointInTimeType;646 647 private RelationMemberTableModel(PointInTimeType pointInTimeType) {648 this.pointInTimeType = pointInTimeType;649 }650 651 @Override652 public int getRowCount() {653 // Match the size of the opposite table so comparison is less confusing.654 // (scroll bars lines up properly, etc.)655 int n = 0;656 if (current != null && current.getType().equals(OsmPrimitiveType.RELATION)) {657 n = ((HistoryRelation)current).getNumMembers();658 }659 if (reference != null && reference.getType().equals(OsmPrimitiveType.RELATION)) {660 n = Math.max(n,((HistoryRelation)reference).getNumMembers());661 }662 return n;663 }664 665 protected HistoryRelation getRelation() {666 if (pointInTimeType.equals(PointInTimeType.CURRENT_POINT_IN_TIME)) {667 if (! current.getType().equals(OsmPrimitiveType.RELATION))668 return null;669 return (HistoryRelation)current;670 }671 if (pointInTimeType.equals(PointInTimeType.REFERENCE_POINT_IN_TIME)) {672 if (! reference.getType().equals(OsmPrimitiveType.RELATION))673 return null;674 return (HistoryRelation)reference;675 }676 677 // should not happen678 return null;679 }680 681 protected HistoryRelation getOppositeRelation() {682 PointInTimeType opposite = pointInTimeType.opposite();683 if (opposite.equals(PointInTimeType.CURRENT_POINT_IN_TIME)) {684 if (! current.getType().equals(OsmPrimitiveType.RELATION))685 return null;686 return (HistoryRelation)current;687 }688 if (opposite.equals(PointInTimeType.REFERENCE_POINT_IN_TIME)) {689 if (! reference.getType().equals(OsmPrimitiveType.RELATION))690 return null;691 return (HistoryRelation)reference;692 }693 694 // should not happen695 return null;696 }697 698 @Override699 public Object getValueAt(int row, int column) {700 HistoryRelation relation = getRelation();701 if (relation == null)702 return null;703 if (row >= relation.getNumMembers()) // see getRowCount704 return null;705 return relation.getMembers().get(row);706 }707 708 @Override709 public boolean isCellEditable(int row, int column) {710 return false;711 }712 713 public boolean isSameInOppositeWay(int row) {714 HistoryRelation thisRelation = getRelation();715 HistoryRelation oppositeRelation = getOppositeRelation();716 if (thisRelation == null || oppositeRelation == null)717 return false;718 if (row >= oppositeRelation.getNumMembers())719 return false;720 return721 thisRelation.getMembers().get(row).getMemberId() == oppositeRelation.getMembers().get(row).getMemberId()722 && thisRelation.getMembers().get(row).getRole().equals(oppositeRelation.getMembers().get(row).getRole());723 }724 725 public boolean isInOppositeWay(int row) {726 HistoryRelation thisRelation = getRelation();727 HistoryRelation oppositeRelation = getOppositeRelation();728 if (thisRelation == null || oppositeRelation == null)729 return false;730 return oppositeRelation.getMembers().contains(thisRelation.getMembers().get(row));731 }732 733 @Override734 public int getColumnCount() {735 return 1;736 }737 }738 739 649 protected void setLatest(HistoryOsmPrimitive latest) { 740 650 if (latest == null) { -
trunk/src/org/openstreetmap/josm/gui/history/NodeListTableCellRenderer.java
r4566 r5627 12 12 import javax.swing.table.TableCellRenderer; 13 13 14 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType; 14 15 import org.openstreetmap.josm.tools.ImageProvider; 15 16 16 17 public class NodeListTableCellRenderer extends JLabel implements TableCellRenderer { 17 18 18 public final static Color BGCOLOR_EMPTY_ROW = new Color(234,234,234);19 public final static Color BGCOLOR_DELETED = new Color(255,197,197);20 public final static Color BGCOLOR_INSERTED = new Color(0xDD, 0xFF, 0xDD);21 public final static Color BGCOLOR_CHANGED = new Color(255,234,213);22 19 public final static Color BGCOLOR_SELECTED = new Color(143,170,255); 23 20 … … 37 34 text = tr("Node {0}", item.value.toString()); 38 35 } 39 switch(item.state) {40 case TwoColumnDiff.Item.EMPTY:36 bgColor = item.state.getColor(); 37 if (item.state == DiffItemType.EMPTY) { 41 38 text = ""; 42 bgColor = BGCOLOR_EMPTY_ROW;43 39 setIcon(null); 44 break;45 case TwoColumnDiff.Item.CHANGED:46 bgColor = BGCOLOR_CHANGED;47 break;48 case TwoColumnDiff.Item.INSERTED:49 bgColor = BGCOLOR_INSERTED;50 break;51 case TwoColumnDiff.Item.DELETED:52 bgColor = BGCOLOR_DELETED;53 break;54 default:55 bgColor = BGCOLOR_EMPTY_ROW;56 40 } 57 41 if (isSelected) { -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListTableCellRenderer.java
r5266 r5627 15 15 import org.openstreetmap.josm.data.osm.OsmPrimitiveType; 16 16 import org.openstreetmap.josm.data.osm.RelationMemberData; 17 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item; 17 18 import org.openstreetmap.josm.tools.ImageProvider; 18 19 … … 47 48 } 48 49 49 protected void renderRole( HistoryBrowserModel.RelationMemberTableModel model, RelationMemberData member, int row, boolean isSelected) {50 protected void renderRole(Item diffItem, int row, boolean isSelected) { 50 51 String text = ""; 51 Color bgColor = Color.WHITE; 52 if (member == null) { 53 bgColor = BGCOLOR_EMPTY_ROW; 54 } else { 55 text = member.getRole(); 56 if (model.isSameInOppositeWay(row)) { 57 bgColor = Color.WHITE; 58 } else if (model.isInOppositeWay(row)) { 59 bgColor = BGCOLOR_IN_OPPOSITE; 60 } else { 61 bgColor = BGCOLOR_NOT_IN_OPPOSITE; 62 } 63 } 52 Color bgColor = diffItem.state.getColor(); 53 RelationMemberData member = (RelationMemberData) diffItem.value; 54 text = member == null?"":member.getRole(); 64 55 setText(text); 65 56 setToolTipText(text); … … 67 58 } 68 59 69 protected void renderPrimitive( HistoryBrowserModel.RelationMemberTableModel model, RelationMemberData member, int row, boolean isSelected) {60 protected void renderPrimitive(Item diffItem, int row, boolean isSelected) { 70 61 String text = ""; 71 Color bgColor = Color.WHITE; 72 if (member == null) { 73 bgColor = BGCOLOR_EMPTY_ROW; 74 } else { 75 text = ""; 62 Color bgColor = diffItem.state.getColor(); 63 RelationMemberData member = (RelationMemberData) diffItem.value; 64 text = ""; 65 if (member != null) { 76 66 switch(member.getMemberType()) { 77 67 case NODE: text = tr("Node {0}", member.getMemberId()); break; 78 68 case WAY: text = tr("Way {0}", member.getMemberId()); break; 79 69 case RELATION: text = tr("Relation {0}", member.getMemberId()); break; 80 }81 if (model.isSameInOppositeWay(row)) {82 bgColor = Color.WHITE;83 } else if (model.isInOppositeWay(row)) {84 bgColor = BGCOLOR_IN_OPPOSITE;85 } else {86 bgColor = BGCOLOR_NOT_IN_OPPOSITE;87 70 } 88 71 } … … 96 79 int row, int column) { 97 80 98 HistoryBrowserModel.RelationMemberTableModel model = gteRelationMemberTableModel(table); 99 RelationMemberData member = (RelationMemberData)value; 100 renderIcon(member); 81 Item member = (TwoColumnDiff.Item)value; 82 renderIcon((RelationMemberData) member.value); 101 83 switch(column) { 102 84 case 0: 103 renderRole(m odel, member, row, isSelected);85 renderRole(member, row, isSelected); 104 86 break; 105 87 case 1: 106 renderPrimitive(m odel, member, row, isSelected);88 renderPrimitive(member, row, isSelected); 107 89 break; 108 90 } … … 111 93 } 112 94 113 protected HistoryBrowserModel.RelationMemberTableModel gteRelationMemberTableModel(JTable table) {114 return ( HistoryBrowserModel.RelationMemberTableModel) table.getModel();95 protected DiffTableModel getRelationMemberTableModel(JTable table) { 96 return (DiffTableModel) table.getModel(); 115 97 } 116 98 } -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java
r5266 r5627 5 5 import java.awt.GridBagLayout; 6 6 import java.awt.Insets; 7 import java.awt.Rectangle; 7 8 8 9 import javax.swing.JPanel; … … 10 11 import javax.swing.JTable; 11 12 import javax.swing.ListSelectionModel; 13 import javax.swing.event.TableModelEvent; 14 import javax.swing.event.TableModelListener; 15 16 import org.openstreetmap.josm.data.osm.history.History; 12 17 /** 13 18 * RelationMemberListViewer is a UI component which displays the list of relation members of two … … 37 42 } 38 43 44 protected class MemberModelChanged implements TableModelListener { 45 private final JTable table; 46 47 protected MemberModelChanged(JTable table) { 48 this.table = table; 49 } 50 51 @Override 52 public void tableChanged(TableModelEvent e) { 53 Rectangle rect = table.getCellRect(((DiffTableModel)e.getSource()).getFirstChange(), 0, true); 54 table.scrollRectToVisible(rect); 55 } 56 } 57 39 58 protected JTable buildReferenceMemberListTable() { 40 59 JTable table = new JTable( 41 60 model.getRelationMemberTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME), 42 61 new RelationMemberTableColumnModel() 43 );62 ); 44 63 table.setName("table.referencememberlisttable"); 45 64 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 46 65 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 66 table.getModel().addTableModelListener(new MemberModelChanged(table)); 47 67 return table; 48 68 } … … 52 72 model.getRelationMemberTableModel(PointInTimeType.CURRENT_POINT_IN_TIME), 53 73 new RelationMemberTableColumnModel() 54 );74 ); 55 75 table.setName("table.currentmemberlisttable"); 56 76 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 57 77 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 78 table.getModel().addTableModelListener(new MemberModelChanged(table)); 58 79 return table; 59 80 } -
trunk/src/org/openstreetmap/josm/gui/history/TwoColumnDiff.java
r4689 r5627 3 3 /// Feel free to move me somewhere else. Maybe a bit specific for josm.tools? 4 4 5 import java.awt.Color; 5 6 import java.util.ArrayList; 6 7 8 import org.openstreetmap.josm.gui.history.TwoColumnDiff.Item.DiffItemType; 7 9 import org.openstreetmap.josm.tools.Diff; 8 10 … … 24 26 class TwoColumnDiff { 25 27 public static class Item { 26 public static final int INSERTED = 1; 27 public static final int DELETED = 2; 28 public static final int CHANGED = 3; 29 public static final int SAME = 4; 30 public static final int EMPTY = 5; // value should be null 31 public Item(int state, Object value) { 28 29 public enum DiffItemType { 30 INSERTED(new Color(0xDD, 0xFF, 0xDD)), DELETED(new Color(255,197,197)), CHANGED(new Color(255,234,213)), 31 SAME(new Color(234,234,234)), EMPTY(new Color(234,234,234)); 32 33 private final Color color; 34 private DiffItemType(Color color) { 35 this.color = color; 36 } 37 public Color getColor() { 38 return color; 39 } 40 } 41 42 public Item(DiffItemType state, Object value) { 32 43 this.state = state; 33 this.value = state == EMPTY ? null : value;44 this.value = state == DiffItemType.EMPTY ? null : value; 34 45 } 35 46 36 47 public final Object value; 37 public final intstate;48 public final DiffItemType state; 38 49 } 39 50 … … 72 83 while(ia < script.line0 && ib < script.line1){ 73 84 // System.out.println(" "+a[ia] + "\t "+b[ib]); 74 Item cell = new Item( Item.SAME, a[ia]);85 Item cell = new Item(DiffItemType.SAME, a[ia]); 75 86 referenceDiff.add(cell); 76 87 currentDiff.add(cell); … … 82 93 if(inserted > 0 && deleted > 0) { 83 94 // System.out.println("="+a[ia] + "\t="+b[ib]); 84 referenceDiff.add(new Item( Item.CHANGED, a[ia++]));85 currentDiff.add(new Item( Item.CHANGED, b[ib++]));95 referenceDiff.add(new Item(DiffItemType.CHANGED, a[ia++])); 96 currentDiff.add(new Item(DiffItemType.CHANGED, b[ib++])); 86 97 } else if(inserted > 0) { 87 98 // System.out.println("\t+" + b[ib]); 88 referenceDiff.add(new Item( Item.EMPTY, null));89 currentDiff.add(new Item( Item.INSERTED, b[ib++]));99 referenceDiff.add(new Item(DiffItemType.EMPTY, null)); 100 currentDiff.add(new Item(DiffItemType.INSERTED, b[ib++])); 90 101 } else if(deleted > 0) { 91 102 // System.out.println("-"+a[ia]); 92 referenceDiff.add(new Item( Item.DELETED, a[ia++]));93 currentDiff.add(new Item( Item.EMPTY, null));103 referenceDiff.add(new Item(DiffItemType.DELETED, a[ia++])); 104 currentDiff.add(new Item(DiffItemType.EMPTY, null)); 94 105 } 95 106 inserted--; … … 100 111 while(ia < a.length && ib < b.length) { 101 112 // System.out.println((ia < a.length ? " "+a[ia]+"\t" : "\t") + (ib < b.length ? " "+b[ib] : "")); 102 referenceDiff.add(new Item( Item.SAME, a[ia++]));103 currentDiff.add(new Item( Item.SAME, b[ib++]));113 referenceDiff.add(new Item(DiffItemType.SAME, a[ia++])); 114 currentDiff.add(new Item(DiffItemType.SAME, b[ib++])); 104 115 } 105 116 }
Note:
See TracChangeset
for help on using the changeset viewer.