On 02/02/2018 11:54 PM, Pankaj Bansal wrote:

Hi Sergey,

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.
Thanks for clarification. This makes perfect sense. Anchor/lead can't be 
preserved if selection model is changed by calls to removeIndexInterval, 
insertIndexInterval etc.

Hi Semyon,
please let me know if this explanation looks good to you.
I cannot accept this explanation. It looks like an attempt to read what actually was not written. The proposed changes will have direct consequences in the user experience which this bug never required. The point of the bug to have anchor/lead cleanup after the model becomes empty and so it may not have any selection. This doesn't cause any exceptions so we might close this bug as won't fix because the application developer may set anchor/lead index to -1 after the model is cleaned up like we do in many places in Swing after the selection model is cleared. Although, the bug submitter mentioned that "Setting it to -1 does not work". It is not clear why.

So, we might either close this bug as "Won't fix" and give an explanation how to clear anchor/lead, or the change should only fix the reported issue. I'm against to change the selection behavior as part of this bug. If it really need to be changed it should be reported and discussed separately.

--Semyon

Regards,
Pankaj Bansal

-----Original Message-----
From: Sergey Bylokhov
Sent: Saturday, February 3, 2018 1:07 PM
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 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.

Reply via email to