mirror of
https://github.com/openjdk/jdk.git
synced 2025-09-18 10:04:42 +02:00
8191436: ListSelectionModel.setSelectionMode() underspecified
Reviewed-by: serb, ssadetsky
This commit is contained in:
parent
81c1d53cdb
commit
2940eb8a25
2 changed files with 158 additions and 7 deletions
|
@ -95,14 +95,37 @@ public class DefaultListSelectionModel implements ListSelectionModel, Cloneable,
|
|||
* @throws IllegalArgumentException {@inheritDoc}
|
||||
*/
|
||||
public void setSelectionMode(int selectionMode) {
|
||||
int oldMode = this.selectionMode;
|
||||
switch (selectionMode) {
|
||||
case SINGLE_SELECTION:
|
||||
case SINGLE_INTERVAL_SELECTION:
|
||||
case MULTIPLE_INTERVAL_SELECTION:
|
||||
this.selectionMode = selectionMode;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid selectionMode");
|
||||
case SINGLE_SELECTION:
|
||||
case SINGLE_INTERVAL_SELECTION:
|
||||
case MULTIPLE_INTERVAL_SELECTION:
|
||||
this.selectionMode = selectionMode;
|
||||
break;
|
||||
default:
|
||||
throw new IllegalArgumentException("invalid selectionMode");
|
||||
}
|
||||
|
||||
/*
|
||||
This code will only be executed when selection needs to be updated on
|
||||
changing selection mode. It will happen only if selection mode is changed
|
||||
from MULTIPLE_INTERVAL to SINGLE_INTERVAL or SINGLE or from
|
||||
SINGLE_INTERVAL to SINGLE
|
||||
*/
|
||||
if (oldMode > this.selectionMode) {
|
||||
if (this.selectionMode == SINGLE_SELECTION) {
|
||||
if (!isSelectionEmpty()) {
|
||||
setSelectionInterval(minIndex, minIndex);
|
||||
}
|
||||
} else if (this.selectionMode == SINGLE_INTERVAL_SELECTION) {
|
||||
if(!isSelectionEmpty()) {
|
||||
int selectionEndindex = minIndex;
|
||||
while (value.get(selectionEndindex + 1)) {
|
||||
selectionEndindex++;
|
||||
}
|
||||
setSelectionInterval(minIndex, selectionEndindex);
|
||||
}
|
||||
}
|
||||
}
|
||||
}
|
||||
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue