> Te usage of ArrayList.BinarySearch isn't what I think the
documentation
describes, for example:
array of [21, 43, 65] and y is 64 should result a positive 2 but it
return
-3.  As this, we have to do the -(x + 1) every time.

Actually, this is exactly what the documentation describes:  the
negative number returned means the value was not found, but the -(index
+ 1) is the slot where the value should go.

> In case, we want to keep using BinarySearch.  I also figure out a
simpler
way of doing it:

rowIndex = -1;
for (int i = 0; i < rowBoundaries.getLength(); i++)
if (y < rowBoundaries.get(i).intValue())
  return rowIndex = i;

>not sure in terms of performance, is this really so much poorer? but
for
sure, it more clear and less problem.

I'm thinking this would be better:
        int rowIndex;
        if (variableRowHeight) {
            if (y == 0) {
                rowIndex = 0;
            } else {
                rowIndex = ArrayList.binarySearch(rowBoundaries, y);
                if (rowIndex < 0) {
                    rowIndex = -(rowIndex + 1);
                }
            }
        } else {
            rowIndex = (y / (fixedRowHeight + 1));
        }

        List<Object> tableData = (List<Object>)tableView.getTableData();
        if (rowIndex >= tableData.getLength()) {
            rowIndex = -1;
        }

This way the same test for index past the end of the table gets applied
in both the fixed and variable row height cases.


~Roger

Reply via email to