Changeset 16609 in josm
- Timestamp:
- 2020-06-11T22:48:46+02:00 (5 years ago)
- Location:
- trunk/src/org/openstreetmap/josm/gui/history
- Files:
-
- 4 edited
Legend:
- Unmodified
- Added
- Removed
-
trunk/src/org/openstreetmap/josm/gui/history/HistoryViewerPanel.java
r16473 r16609 5 5 import java.awt.Insets; 6 6 import java.awt.event.ActionEvent; 7 import java.util.function.BiPredicate; 8 import java.util.stream.IntStream; 7 9 8 10 import javax.swing.AbstractAction; … … 10 12 import javax.swing.JScrollPane; 11 13 import javax.swing.JTable; 14 import javax.swing.ListSelectionModel; 12 15 13 16 import org.openstreetmap.josm.actions.AutoScaleAction; … … 94 97 } 95 98 99 /** 100 * Enables semantic highlighting for the {@link org.openstreetmap.josm.data.StructUtils.SerializeOptions} 101 * @param thisSelectionModel selection model 102 * @param thisModel table model (corresponding to the selection model) 103 * @param otherModel table model for the other point in time 104 * @param isSemanticallyEquivalent predicate to determine whether the items should be highlighted 105 */ 106 protected void enableSemanticSelectionSynchronization(ListSelectionModel thisSelectionModel, 107 DiffTableModel thisModel, DiffTableModel otherModel, 108 BiPredicate<TwoColumnDiff.Item, TwoColumnDiff.Item> isSemanticallyEquivalent) { 109 selectionSynchronizer.setSelectionIndexMapper((selection, sourceSelectionModel) -> { 110 DiffTableModel sourceModel = sourceSelectionModel == thisSelectionModel ? thisModel : otherModel; 111 DiffTableModel destinationModel = sourceSelectionModel == thisSelectionModel ? otherModel : thisModel; 112 return IntStream.range(0, destinationModel.getRowCount()) 113 .filter(i -> isSemanticallyEquivalent.test(sourceModel.getValueAt(selection, 0), destinationModel.getValueAt(i, 0))); 114 }); 115 } 116 96 117 static class ListPopupMenu extends JPopupMenu { 97 118 private final ZoomToObjectAction zoomToObjectAction; -
trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java
r16530 r16609 5 5 6 6 import java.awt.Point; 7 import java.util.Objects; 7 8 8 9 import javax.swing.JTable; … … 50 51 return primitiveIdAtRow(tableModel, row); 51 52 })); 53 enableSemanticSelectionSynchronization(table.getSelectionModel(), 54 tableModel, model.getNodeListTableModel(pointInTimeType.opposite()), 55 this::isSemanticallyEquivalent); 52 56 return table; 57 } 58 59 private boolean isSemanticallyEquivalent(TwoColumnDiff.Item o1, TwoColumnDiff.Item o2) { 60 return o1.value != null && Objects.equals(o1.value, o2.value); //compare node IDs 53 61 } 54 62 -
trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java
r16530 r16609 36 36 table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION); 37 37 selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel()); 38 enableSemanticSelectionSynchronization(table.getSelectionModel(), 39 tableModel, model.getRelationMemberTableModel(pointInTimeType.opposite()), 40 this::isSemanticallyEquivalent); 38 41 table.getTableHeader().setReorderingAllowed(false); 39 42 table.addMouseListener(new InternalPopupMenuLauncher()); … … 47 50 })); 48 51 return table; 52 } 53 54 private boolean isSemanticallyEquivalent(TwoColumnDiff.Item o1, TwoColumnDiff.Item o2) { 55 RelationMemberData rm1 = (RelationMemberData) o1.value; 56 RelationMemberData rm2 = (RelationMemberData) o2.value; 57 return rm1 != null && rm2 != null 58 && rm1.getMemberId() == rm2.getMemberId() 59 && rm1.getMemberType() == rm2.getMemberType(); 49 60 } 50 61 -
trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java
r16601 r16609 4 4 import java.util.Arrays; 5 5 import java.util.HashSet; 6 import java.util.Objects; 6 7 import java.util.Set; 8 import java.util.function.BiFunction; 9 import java.util.stream.IntStream; 7 10 8 import javax.swing.DefaultListSelectionModel;9 11 import javax.swing.ListSelectionModel; 10 12 import javax.swing.event.ListSelectionEvent; … … 23 25 private final Set<ListSelectionModel> participants; 24 26 private boolean preventRecursion; 27 private BiFunction<Integer, ListSelectionModel, IntStream> selectionIndexMapper = (i, model) -> IntStream.of(i); 25 28 26 29 /** … … 47 50 } 48 51 52 void setSelectionIndexMapper(BiFunction<Integer, ListSelectionModel, IntStream> selectionIndexMapper) { 53 this.selectionIndexMapper = Objects.requireNonNull(selectionIndexMapper); 54 } 55 49 56 @Override 50 57 public void valueChanged(ListSelectionEvent e) { … … 53 60 } 54 61 preventRecursion = true; 55 DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource();62 ListSelectionModel referenceModel = (ListSelectionModel) e.getSource(); 56 63 int[] selectedIndices = TableHelper.getSelectedIndices(referenceModel); 57 64 for (ListSelectionModel model : participants) { 58 if (model == e.getSource()) {65 if (model == referenceModel) { 59 66 continue; 60 67 } 61 TableHelper.setSelectedIndices(model, Arrays.stream(selectedIndices)); 68 TableHelper.setSelectedIndices(model, 69 Arrays.stream(selectedIndices).flatMap(i -> selectionIndexMapper.apply(i, referenceModel))); 62 70 } 63 71 preventRecursion = false;
Note:
See TracChangeset
for help on using the changeset viewer.