Last change
on this file since 9734 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
|
Rev | Line | |
---|
[2512] | 1 | // License: GPL. For details, see LICENSE file.
|
---|
| 2 | package org.openstreetmap.josm.gui.history;
|
---|
| 3 |
|
---|
[8390] | 4 | import java.util.HashSet;
|
---|
| 5 | import java.util.Set;
|
---|
[2512] | 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 |
|
---|
[8390] | 14 | private final Set<ListSelectionModel> participants;
|
---|
[2512] | 15 |
|
---|
[6316] | 16 | /**
|
---|
| 17 | * Constructs a new {@code SelectionSynchronizer}.
|
---|
| 18 | */
|
---|
[2512] | 19 | public SelectionSynchronizer() {
|
---|
[8390] | 20 | participants = new HashSet<>();
|
---|
[2512] | 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 |
|
---|
[6084] | 32 | @Override
|
---|
[2512] | 33 | public void valueChanged(ListSelectionEvent e) {
|
---|
[8510] | 34 | DefaultListSelectionModel referenceModel = (DefaultListSelectionModel) e.getSource();
|
---|
[2512] | 35 | int i = referenceModel.getMinSelectionIndex();
|
---|
| 36 | for (ListSelectionModel model : participants) {
|
---|
| 37 | if (model == e.getSource()) {
|
---|
| 38 | continue;
|
---|
| 39 | }
|
---|
[8510] | 40 | model.setSelectionInterval(i, i);
|
---|
[2512] | 41 | }
|
---|
| 42 | }
|
---|
| 43 | }
|
---|
Note:
See
TracBrowser
for help on using the repository browser.