393 |
|
|
394 |
/** |
/** |
395 |
* If the {@link #selectionMode} property is equal to |
* If the {@link #selectionMode} property is equal to |
396 |
* <code>SINGLE_SELECTION</code> or |
* <code>SINGLE_SELECTION</code> equivalent to calling |
397 |
* <code>SINGLE_INTERVAL_SELECTION</code>, equivalent to calling |
* <code>setSelectionInterval(index1, index2)</code>; |
398 |
* <code>setSelectionInterval(index1, index2)</code>; otherwise adds the |
* If the {@link #selectionMode} property is equal to |
399 |
* range <code>[index0, index1]</code> to the selection interval set. |
* <code>SINGLE_INTERVAL_SELECTION</code> and the interval being |
400 |
|
* added is not adjacent to an already selected interval, |
401 |
|
* equivalent to <code>setSelectionInterval(index1, index2)</code>. |
402 |
|
* Otherwise adds the range <code>[index0, index1]</code> |
403 |
|
* to the selection interval set. |
404 |
* |
* |
405 |
* @param index0 The beginning of the range of indices to select |
* @param index0 The beginning of the range of indices to select |
406 |
* @param index1 The end of the range of indices to select |
* @param index1 The end of the range of indices to select |
410 |
*/ |
*/ |
411 |
public void addSelectionInterval(int index0, int index1) |
public void addSelectionInterval(int index0, int index1) |
412 |
{ |
{ |
413 |
|
int lo = Math.min(index0, index1); |
414 |
|
int hi = Math.max(index0, index1); |
415 |
oldSel = sel.clone(); |
oldSel = sel.clone(); |
416 |
if (selectionMode == SINGLE_SELECTION |
|
417 |
|| selectionMode == SINGLE_INTERVAL_SELECTION) |
if (selectionMode == SINGLE_SELECTION) |
418 |
sel.clear(); |
sel.clear(); |
419 |
|
|
420 |
|
// COMPAT: Like Sun (but not like IBM), we allow calls to |
421 |
|
// addSelectionInterval when selectionMode is |
422 |
|
// SINGLE_SELECTION_INTERVAL iff the interval being added |
423 |
|
// is adjacent to an already selected interval |
424 |
|
if (selectionMode == SINGLE_INTERVAL_SELECTION) |
425 |
|
if (!(isSelectedIndex(index0) || |
426 |
|
isSelectedIndex(index1) || |
427 |
|
isSelectedIndex(Math.max(lo-1,0)) || |
428 |
|
isSelectedIndex(Math.min(hi+1,sel.size())))) |
429 |
|
sel.clear(); |
430 |
|
|
431 |
if (selectionMode == SINGLE_SELECTION) |
if (selectionMode == SINGLE_SELECTION) |
432 |
index0 = index1; |
index0 = index1; |
433 |
|
|
434 |
int lo = Math.min(index0, index1); |
// We have to update the anchorSelectionIndex and leadSelectionIndex |
435 |
int hi = Math.max(index0, index1); |
// variables |
|
|
|
|
/* We have to update the anchorSelectionIndex and leadSelectionIndex |
|
|
variables */ |
|
436 |
|
|
437 |
/* The next if statements breaks down to "if this selection is adjacent |
// The next if statements breaks down to "if this selection is adjacent |
438 |
to the previous selection and going in the same direction" */ |
// to the previous selection and going in the same direction" |
439 |
if (((index0 - 1 == leadSelectionIndex && (index1 >= index0) |
if (((index0 - 1 == leadSelectionIndex && (index1 >= index0) |
440 |
&& (leadSelectionIndex >= anchorSelectionIndex)) |
&& (leadSelectionIndex >= anchorSelectionIndex)) |
441 |
|| (index0 + 1 == leadSelectionIndex && (index1 <= index0) |
|| (index0 + 1 == leadSelectionIndex && (index1 <= index0) |
442 |
&& (leadSelectionIndex <= anchorSelectionIndex))) |
&& (leadSelectionIndex <= anchorSelectionIndex))) |
443 |
&& (anchorSelectionIndex != -1 || leadSelectionIndex != -1)) |
&& (anchorSelectionIndex != -1 || leadSelectionIndex != -1)) |
444 |
{ |
{ |
445 |
/* setting setLeadCalledFromAdd to true tells setLeadSelectionIndex |
// setting setLeadCalledFromAdd to true tells setLeadSelectionIndex |
446 |
not to update oldSel */ |
// not to update oldSel |
447 |
setLeadCalledFromAdd = true; |
setLeadCalledFromAdd = true; |
448 |
setLeadSelectionIndex(index1); |
setLeadSelectionIndex(index1); |
449 |
setLeadCalledFromAdd = false; |
setLeadCalledFromAdd = false; |
475 |
oldSel = sel.clone(); |
oldSel = sel.clone(); |
476 |
int lo = Math.min(index0, index1); |
int lo = Math.min(index0, index1); |
477 |
int hi = Math.max(index0, index1); |
int hi = Math.max(index0, index1); |
478 |
|
|
479 |
|
// if selectionMode is SINGLE_INTERVAL_SELECTION and removing the interval |
480 |
|
// (index0,index1) would leave two disjoint selection intervals, remove all |
481 |
|
// selected indices from lo to the last selected index |
482 |
|
if (getMinSelectionIndex() > 0 && getMinSelectionIndex() < lo && |
483 |
|
selectionMode == SINGLE_INTERVAL_SELECTION) |
484 |
|
hi = sel.size() - 1; |
485 |
|
|
486 |
sel.clear(lo, hi+1); |
sel.clear(lo, hi+1); |
487 |
//update anchorSelectionIndex and leadSelectionIndex variables |
//update anchorSelectionIndex and leadSelectionIndex variables |
488 |
//TODO: will probably need MouseDragged to test properly and know if this works |
//TODO: will probably need MouseDragged to test properly and know if this works |