Ignore:
Timestamp:
2020-06-11T22:48:46+02:00 (4 years ago)
Author:
simon04
Message:

fix #19330 - History browser: Add semantic check to select equivalent nodes/members on opposite sides

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  
    55import java.awt.Insets;
    66import java.awt.event.ActionEvent;
     7import java.util.function.BiPredicate;
     8import java.util.stream.IntStream;
    79
    810import javax.swing.AbstractAction;
     
    1012import javax.swing.JScrollPane;
    1113import javax.swing.JTable;
     14import javax.swing.ListSelectionModel;
    1215
    1316import org.openstreetmap.josm.actions.AutoScaleAction;
     
    9497    }
    9598
     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
    96117    static class ListPopupMenu extends JPopupMenu {
    97118        private final ZoomToObjectAction zoomToObjectAction;
  • trunk/src/org/openstreetmap/josm/gui/history/NodeListViewer.java

    r16530 r16609  
    55
    66import java.awt.Point;
     7import java.util.Objects;
    78
    89import javax.swing.JTable;
     
    5051            return primitiveIdAtRow(tableModel, row);
    5152        }));
     53        enableSemanticSelectionSynchronization(table.getSelectionModel(),
     54                tableModel, model.getNodeListTableModel(pointInTimeType.opposite()),
     55                this::isSemanticallyEquivalent);
    5256        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
    5361    }
    5462
  • trunk/src/org/openstreetmap/josm/gui/history/RelationMemberListViewer.java

    r16530 r16609  
    3636        table.setSelectionMode(ListSelectionModel.SINGLE_SELECTION);
    3737        selectionSynchronizer.participateInSynchronizedSelection(table.getSelectionModel());
     38        enableSemanticSelectionSynchronization(table.getSelectionModel(),
     39                tableModel, model.getRelationMemberTableModel(pointInTimeType.opposite()),
     40                this::isSemanticallyEquivalent);
    3841        table.getTableHeader().setReorderingAllowed(false);
    3942        table.addMouseListener(new InternalPopupMenuLauncher());
     
    4750        }));
    4851        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();
    4960    }
    5061
  • trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java

    r16601 r16609  
    44import java.util.Arrays;
    55import java.util.HashSet;
     6import java.util.Objects;
    67import java.util.Set;
     8import java.util.function.BiFunction;
     9import java.util.stream.IntStream;
    710
    8 import javax.swing.DefaultListSelectionModel;
    911import javax.swing.ListSelectionModel;
    1012import javax.swing.event.ListSelectionEvent;
     
    2325    private final Set<ListSelectionModel> participants;
    2426    private boolean preventRecursion;
     27    private BiFunction<Integer, ListSelectionModel, IntStream> selectionIndexMapper = (i, model) -> IntStream.of(i);
    2528
    2629    /**
     
    4750    }
    4851
     52    void setSelectionIndexMapper(BiFunction<Integer, ListSelectionModel, IntStream> selectionIndexMapper) {
     53        this.selectionIndexMapper = Objects.requireNonNull(selectionIndexMapper);
     54    }
     55
    4956    @Override
    5057    public void valueChanged(ListSelectionEvent e) {
     
    5360        }
    5461        preventRecursion = true;
    55         DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource();
     62        ListSelectionModel referenceModel = (ListSelectionModel) e.getSource();
    5663        int[] selectedIndices = TableHelper.getSelectedIndices(referenceModel);
    5764        for (ListSelectionModel model : participants) {
    58             if (model == e.getSource()) {
     65            if (model == referenceModel) {
    5966                continue;
    6067            }
    61             TableHelper.setSelectedIndices(model, Arrays.stream(selectedIndices));
     68            TableHelper.setSelectedIndices(model,
     69                    Arrays.stream(selectedIndices).flatMap(i -> selectionIndexMapper.apply(i, referenceModel)));
    6270        }
    6371        preventRecursion = false;
Note: See TracChangeset for help on using the changeset viewer.