On 02/02/2018 23:05, Pankaj Bansal wrote:
Hi Sergey,
Can somebody clarify why -1/-1 is incorrect? lead/anchor values are not min/max
selected element, it can be any elements: selected/unselected and is not necessary
>>first/last selected element.
According to API description of getAnchor/LeadSelectionIndex, anchor/lead
return the first/second index of most recent call to setSelectionInterval(),
addSelectionInterval() or removeSelectionInterval().
This means that if an application will call any of these methods then
the anchor/lead will be taken from the latest call. For example if the
application will select a few intervals then the anchor/lead will be
based on the latest interval. But if selection model will be
modified(for example via
insertIndexInterval/setAnchorSelectionIndex/setLeadSelectionIndex/removeIndexInterval/etc)after
that it does not mean that anchor/lead will be preserved.
Now in following example, most recent call to one of the three API was with 0/0
as first/second index as addSelectionInterval is called from
setSelectedIndices. So the anchor/lead should be 0/0 according to the API
description. So -1/-1 value is wrong.
list.setSelectedIndices(new int[] {1, 0}); // selection is [0 ,1] lead/anchor =
0/0
model.removeElementAt(0); // selection is [0] lead/anchor = 0/0 (before fix),
-1/-1(after fix)
But as I pointed out with next example, removeIndexInterval sets wrong
anchor/lead value for all indices even before the fix. removeIndexInterval
handles the 0 index specially and maintains correct value of anchor/lead. I
have just removed the code for special handling of 0 index.
list.setSelectedIndices(new int[] {2, 1}); // selection is [1 ,2] lead/anchor =
1/1
model.removeElementAt(1); // selection is [1] lead/anchor = 0/0 (before the
fix. I have verified it. It should be 1/1 according to API description)
I also feel that, if we go by API description, only setSelectionInterval(),
addSelectionInterval() or removeSelectionInterval() should change the
achor/lead values. But there are other APIs lile insertIndexInterval,
removeIndexInterval which change anchor/lead. Also there are set functions for
anchor/lead, which should not be there.
Regards,
Pankaj Bansal
-----Original Message-----
From: Sergey Bylokhov
Sent: Saturday, February 3, 2018 3:25 AM
To: Pankaj Bansal; Semyon Sadetsky; swing-dev@openjdk.java.net
Subject: Re: <Swing Dev> [11] Review Request: JDK-6481195 ListSelectionListener
indicates events on model.addElement after model.clear()
On 01/02/2018 23:25, Pankaj Bansal wrote:
Ok, I got your point. In the example you gave, as addSelectionInterval
was called from setSelectedIndices with 0 at last, the lead/anchor
should be 0/0 not -1/-1.
Can somebody clarify why -1/-1 is incorrect? lead/anchor values are not min/max
selected element, it can be any elements: selected/unselected and is not
necessary first/last selected element.
--
Best regards, Sergey.
--
Best regards, Sergey.