source: josm/trunk/src/org/openstreetmap/josm/gui/history/SelectionSynchronizer.java@ 10210

Last change on this file since 10210 was 8510, checked in by Don-vip, 9 years ago

checkstyle: enable relevant whitespace checks and fix them

  • Property svn:eol-style set to native
File size: 1.3 KB
Line 
1// License: GPL. For details, see LICENSE file.
2package org.openstreetmap.josm.gui.history;
3
4import java.util.HashSet;
5import java.util.Set;
6
7import javax.swing.DefaultListSelectionModel;
8import javax.swing.ListSelectionModel;
9import javax.swing.event.ListSelectionEvent;
10import javax.swing.event.ListSelectionListener;
11
12public class SelectionSynchronizer implements ListSelectionListener {
13
14 private final Set<ListSelectionModel> participants;
15
16 /**
17 * Constructs a new {@code SelectionSynchronizer}.
18 */
19 public SelectionSynchronizer() {
20 participants = new HashSet<>();
21 }
22
23 public void participateInSynchronizedSelection(ListSelectionModel model) {
24 if (model == null)
25 return;
26 if (participants.contains(model))
27 return;
28 participants.add(model);
29 model.addListSelectionListener(this);
30 }
31
32 @Override
33 public void valueChanged(ListSelectionEvent e) {
34 DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource();
35 int i = referenceModel.getMinSelectionIndex();
36 for (ListSelectionModel model : participants) {
37 if (model == e.getSource()) {
38 continue;
39 }
40 model.setSelectionInterval(i, i);
41 }
42 }
43}
Note: See TracBrowser for help on using the repository browser.