Changeset 8219 in josm for trunk/src/org/openstreetmap
- Timestamp:
- 2015-04-18T15:33:28+02:00 (10 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/history
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/DiffTableModel.java
r7937 r8219 1 1 // License: GPL. For details, see LICENSE file. 2 2 package org.openstreetmap.josm.gui.history; 3 4 import static org.openstreetmap.josm.tools.I18n.tr; 3 5 4 6 import java.util.ArrayList; … … 14 16 */ 15 17 class DiffTableModel extends AbstractTableModel { 16 private List<TwoColumnDiff.Item> rows; 18 private List<TwoColumnDiff.Item> rows = new ArrayList<>(); 19 private boolean reversed = false; 17 20 18 public void setRows(List<TwoColumnDiff.Item> rows ) {21 public void setRows(List<TwoColumnDiff.Item> rows, boolean reversed) { 19 22 this.rows = rows; 20 } 21 22 public DiffTableModel(List<TwoColumnDiff.Item> rows) { 23 this.rows = rows; 24 } 25 public DiffTableModel() { 26 this.rows = new ArrayList<>(); 23 this.reversed = reversed; 24 fireTableDataChanged(); 27 25 } 28 26 @Override … … 34 32 public int getColumnCount() { 35 33 return 1; 34 } 35 36 public boolean isReversed() { 37 return reversed; 36 38 } 37 39 -
trunk/src/org/openstreetmap/josm/gui/history/HistoryBrowserModel.java
r7299 r8219 84 84 private HistoryOsmPrimitive latest; 85 85 86 private VersionTableModel versionTableModel;87 private TagTableModel currentTagTableModel;88 private TagTableModel referenceTagTableModel;89 private DiffTableModel currentRelationMemberTableModel;90 private DiffTableModel referenceRelationMemberTableModel;91 private DiffTableModel referenceNodeListTableModel;92 private DiffTableModel currentNodeListTableModel;86 private final VersionTableModel versionTableModel; 87 private final TagTableModel currentTagTableModel; 88 private final TagTableModel referenceTagTableModel; 89 private final DiffTableModel currentRelationMemberTableModel; 90 private final DiffTableModel referenceRelationMemberTableModel; 91 private final DiffTableModel referenceNodeListTableModel; 92 private final DiffTableModel currentNodeListTableModel; 93 93 94 94 /** … … 223 223 */ 224 224 protected void initNodeListTableModels() { 225 226 225 if(current.getType() != OsmPrimitiveType.WAY || reference.getType() != OsmPrimitiveType.WAY) 227 226 return; … … 229 228 ((HistoryWay)reference).getNodes().toArray(), 230 229 ((HistoryWay)current).getNodes().toArray()); 231 referenceNodeListTableModel.setRows(diff.referenceDiff); 232 currentNodeListTableModel.setRows(diff.currentDiff); 233 234 referenceNodeListTableModel.fireTableDataChanged(); 235 currentNodeListTableModel.fireTableDataChanged(); 230 referenceNodeListTableModel.setRows(diff.referenceDiff, diff.referenceReversed); 231 currentNodeListTableModel.setRows(diff.currentDiff, false); 236 232 } 237 233 … … 239 235 if(current.getType() != OsmPrimitiveType.RELATION || reference.getType() != OsmPrimitiveType.RELATION) 240 236 return; 241 242 237 TwoColumnDiff diff = new TwoColumnDiff( 243 238 ((HistoryRelation)reference).getMembers().toArray(), 244 239 ((HistoryRelation)current).getMembers().toArray()); 245 246 referenceRelationMemberTableModel.setRows(diff.referenceDiff); 247 currentRelationMemberTableModel.setRows(diff.currentDiff); 248 249 currentRelationMemberTableModel.fireTableDataChanged(); 250 referenceRelationMemberTableModel.fireTableDataChanged(); 240 referenceRelationMemberTableModel.setRows(diff.referenceDiff, diff.referenceReversed); 241 currentRelationMemberTableModel.setRows(diff.currentDiff, false); 251 242 } 252 243 -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r6936 r8219 18 18 import javax.swing.JTable; 19 19 import javax.swing.ListSelectionModel; 20 import javax.swing.event.TableModelEvent; 21 import javax.swing.event.TableModelListener; 20 22 import javax.swing.table.TableModel; 21 23 … … 60 62 61 63 protected JTable buildReferenceNodeListTable() { 62 JTable table = new JTable(63 model.getNodeListTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME),64 new NodeListTableColumnModel()65 );64 final DiffTableModel tableModel = model.getNodeListTableModel(PointInTimeType.REFERENCE_POINT_IN_TIME); 65 final NodeListTableColumnModel columnModel = new NodeListTableColumnModel(); 66 final JTable table = new JTable(tableModel, columnModel); 67 tableModel.addTableModelListener(newReversedChangeListener(table, columnModel)); 66 68 table.setName("table.referencenodelisttable"); 67 69 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 73 75 74 76 protected JTable buildCurrentNodeListTable() { 75 JTable table = new JTable(76 model.getNodeListTableModel(PointInTimeType.CURRENT_POINT_IN_TIME),77 new NodeListTableColumnModel()78 );77 final DiffTableModel tableModel = model.getNodeListTableModel(PointInTimeType.CURRENT_POINT_IN_TIME); 78 final NodeListTableColumnModel columnModel = new NodeListTableColumnModel(); 79 final JTable table = new JTable(tableModel, columnModel); 80 tableModel.addTableModelListener(newReversedChangeListener(table, columnModel)); 79 81 table.setName("table.currentnodelisttable"); 80 82 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); … … 83 85 table.addMouseListener(new DoubleClickAdapter(table)); 84 86 return table; 87 } 88 89 protected TableModelListener newReversedChangeListener(final JTable table, final NodeListTableColumnModel columnModel) { 90 return new TableModelListener() { 91 private Boolean reversed = null; 92 final String nonReversedText = tr("Nodes") + (table.getFont().canDisplay('\u25bc') ? " \u25bc" : " (1-n)"); 93 final String reversedText = tr("Nodes") + (table.getFont().canDisplay('\u25b2') ? " \u25b2" : " (n-1)"); 94 95 @Override 96 public void tableChanged(TableModelEvent e) { 97 if (e.getSource() instanceof DiffTableModel) { 98 final DiffTableModel model = (DiffTableModel) e.getSource(); 99 if (reversed == null || reversed != model.isReversed()) { 100 reversed = model.isReversed(); 101 columnModel.getColumn(0).setHeaderValue(reversed ? reversedText : nonReversedText); 102 table.getTableHeader().repaint(); 103 } 104 } 105 } 106 }; 85 107 } 86 108 -
trunk/src/org/openstreetmap/josm/gui/history/TwoColumnDiff.java
r7937 r8219 5 5 import java.awt.Color; 6 6 import java.util.ArrayList; 7 import java.util.Arrays; 8 import java.util.Collections; 7 9 import java.util.List; 8 10 … … 55 57 Object[] reference; 56 58 Object[] current; 59 boolean referenceReversed = false; 57 60 58 61 public TwoColumnDiff(Object[] reference, Object[] current) { … … 65 68 66 69 private void diff() { 67 Diff diff = new Diff(reference, current); 68 Diff.Change script = diff.diff_2(false); 69 twoColumnDiffFromScript(script, reference, current); 70 Diff.Change script = new Diff(reference, current).diff_2(false); 71 // attempt diff with reference reversed and test whether less deletions+inserts are required 72 Object[] referenceReversed = Utils.copyArray(reference); 73 Collections.reverse(Arrays.asList(referenceReversed)); 74 Diff.Change scriptReversed = new Diff(referenceReversed, current).diff_2(false); 75 if (scriptReversed == null /* reference and current are identical */ 76 || script != null && scriptReversed.deleted + scriptReversed.inserted < script.deleted + script.inserted) { 77 this.referenceReversed = true; 78 twoColumnDiffFromScript(scriptReversed, referenceReversed, current); 79 } else { 80 this.referenceReversed = false; 81 twoColumnDiffFromScript(script, reference, current); 82 } 70 83 } 71 84
Note:
See TracChangeset
for help on using the changeset viewer.