Last change
on this file was 127, checked in by Wouter Pasman, 6 years ago |
#41 ROLL BACK of rev.126 . So this version is equal to rev. 125
|
File size:
1.0 KB
|
Rev | Line | |
---|
[127] | 1 | package genius.gui.panels;
|
---|
| 2 |
|
---|
| 3 | import javax.swing.DefaultListSelectionModel;
|
---|
| 4 |
|
---|
| 5 | /**
|
---|
| 6 | * Selection model for JList's which allows multiple elements to be selected
|
---|
| 7 | * by toggling an item when clicked.
|
---|
| 8 | *
|
---|
| 9 | * @author Mark Hendrikx (m.j.c.hendrikx@student.tudelft.nl)
|
---|
| 10 | * @version 05/12/11
|
---|
| 11 | */
|
---|
| 12 | public class MultiListSelectionModel extends DefaultListSelectionModel {
|
---|
| 13 | private static final long serialVersionUID = 3815068403424389993L;
|
---|
| 14 | private int i0 = -1;
|
---|
| 15 | private int i1 = -1;
|
---|
| 16 |
|
---|
| 17 | public void setSelectionInterval(int index0, int index1) {
|
---|
| 18 | if (i0 == index0 && i1 == index1) {
|
---|
| 19 | if (getValueIsAdjusting()) {
|
---|
| 20 | setValueIsAdjusting(false);
|
---|
| 21 | setSelection(index0, index1);
|
---|
| 22 | }
|
---|
| 23 | } else {
|
---|
| 24 | i0 = index0;
|
---|
| 25 | i1 = index1;
|
---|
| 26 | setValueIsAdjusting(false);
|
---|
| 27 | setSelection(index0, index1);
|
---|
| 28 | }
|
---|
| 29 | }
|
---|
| 30 |
|
---|
| 31 | private void setSelection(int index0, int index1) {
|
---|
| 32 | if (super.isSelectedIndex(index0)) {
|
---|
| 33 | super.removeSelectionInterval(index0, index1);
|
---|
| 34 | } else {
|
---|
| 35 | super.addSelectionInterval(index0, index1);
|
---|
| 36 | }
|
---|
| 37 | }
|
---|
[1] | 38 | } |
---|
Note:
See
TracBrowser
for help on using the repository browser.