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

Last change on this file since 6520 was 6316, checked in by Don-vip, 11 years ago

Sonar/FindBugs - Loose coupling

  • 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.ArrayList;
5import java.util.List;
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 List<ListSelectionModel> participants;
15
16 /**
17 * Constructs a new {@code SelectionSynchronizer}.
18 */
19 public SelectionSynchronizer() {
20 participants = new ArrayList<ListSelectionModel>();
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.