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

File:
1 edited

Legend:

Unmodified
Added
Removed
  • 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.