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