// number of hidden columns before last visited region
private int hiddenSoFar;
- // flag to indicate if current cursor settings are valid
- private boolean isValid;
-
private List<int[]> hiddenColumns;
protected HiddenColumnsCursor()
{
- isValid = false;
+
}
/**
* @param hiddenCount
* number of hidden columns before last visited region
*/
- protected void resetCursor(// int first, int last, int index, int hiddenCount,
- List<int[]> hiddenCols)
+ protected void resetCursor(List<int[]> hiddenCols)
{
- isValid = true;
- if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
+ synchronized (this)
{
- hiddenColumns = hiddenCols;
- firstColumn = hiddenColumns.get(0)[0];
- lastColumn = hiddenColumns.get(hiddenColumns.size() - 1)[1];
- regionIndex = 0;
- hiddenSoFar = 0;
+ if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
+ {
+ hiddenColumns = hiddenCols;
+ firstColumn = hiddenColumns.get(0)[0];
+ lastColumn = hiddenColumns.get(hiddenColumns.size() - 1)[1];
+ regionIndex = 0;
+ hiddenSoFar = 0;
+ }
}
}
protected void updateCursor(int index, int hiddenCount)
{
- regionIndex = index;
- hiddenSoFar = hiddenCount;
+ synchronized (this)
+ {
+ regionIndex = index;
+ hiddenSoFar = hiddenCount;
+ }
}
+ private synchronized int getIndex()
+ {
+ return regionIndex;
+ }
+
+ private synchronized int getHiddenSoFar()
+ {
+ return hiddenSoFar;
+ }
+
+
/**
* Get the index of the region that column is within (if column is hidden) or
* which is to the right of column (if column is visible). If no hidden
return -1;
}
- if ((hiddenColumns.get(regionIndex)[0] <= column)
- && (hiddenColumns.get(regionIndex)[1] >= column))
+ int index = getIndex();
+ int hiddenCount = getHiddenSoFar();
+
+ if (index == hiddenColumns.size())
+ {
+ // went past the end of hiddenColumns collection last time
+ index--;
+ int[] region = hiddenColumns.get(index);
+ hiddenCount -= region[1] - region[0] + 1;
+ }
+
+ if ((hiddenColumns.get(index)[0] <= column)
+ && (hiddenColumns.get(index)[1] >= column))
{
// we hit the jackpot
- return regionIndex;
+ // don't need to move index
}
else if (column < firstColumn)
{
- return 0;
+ index = 0;
+ hiddenCount = 0;
}
else if (column > lastColumn)
{
- return hiddenColumns.size();
+ index = hiddenColumns.size();
+ // TODO resolve here - need full hidden count
}
- else if (column > hiddenColumns.get(regionIndex)[1])
+ else if (column > hiddenColumns.get(index)[1])
{
// iterate from where we are now, if we're lucky we'll be close by
// (but still better than iterating from 0)
- while ((regionIndex < hiddenColumns.size())
- && (hiddenColumns.get(regionIndex)[0] <= column))
+ while ((index < hiddenColumns.size())
+ && (hiddenColumns.get(index)[0] <= column))
{
- int[] region = hiddenColumns.get(regionIndex);
- hiddenSoFar += region[1] - region[0] + 1;
- regionIndex++;
+ int[] region = hiddenColumns.get(index);
+ hiddenCount += region[1] - region[0] + 1;
+ index++;
}
}
else // (column < hiddenColumns.get(regionIndex)[0])
{
- int lastHidden = 0;
- while ((regionIndex >= 0)
- && (hiddenColumns.get(regionIndex)[0] > column))
+ while ((index > 0) && (hiddenColumns.get(index)[1] > column))
{
- int[] region = hiddenColumns.get(regionIndex);
- hiddenSoFar -= lastHidden;
- lastHidden = region[1] - region[0] + 1;
- regionIndex--;
+ index--;
+ int[] region = hiddenColumns.get(index);
+ hiddenCount -= region[1] - region[0] + 1;
}
- hiddenSoFar -= lastHidden;
}
- return regionIndex;
+ updateCursor(index, hiddenCount);
+ return index;
}
protected int getHiddenOffset(int column)
return -1;
}
+ int index = getIndex();
+ int hiddenCount = getHiddenSoFar();
+
if (column < firstColumn)
{
- return 0;
+ index = 0;
+ hiddenCount = 0;
}
- else if ((regionIndex < hiddenColumns.size())
- && (hiddenColumns.get(regionIndex)[0] <= column
- + hiddenSoFar))
+ else if ((index < hiddenColumns.size())
+ && (hiddenColumns.get(index)[0] <= column + hiddenCount))
{
-
// iterate from where we are now, if we're lucky we'll be close by
// (but still better than iterating from 0)
- while ((regionIndex < hiddenColumns.size())
- && (hiddenColumns.get(regionIndex)[0] <= column
- + hiddenSoFar))
+ while ((index < hiddenColumns.size())
+ && (hiddenColumns.get(index)[0] <= column + hiddenCount))
{
- int[] region = hiddenColumns.get(regionIndex);
- hiddenSoFar += region[1] - region[0] + 1;
- regionIndex++;
+ int[] region = hiddenColumns.get(index);
+ hiddenCount += region[1] - region[0] + 1;
+ index++;
}
}
- else if (regionIndex < hiddenColumns.size())
+ else if (index < hiddenColumns.size())
{
- int lastHidden = hiddenColumns.get(regionIndex)[1]
- - hiddenColumns.get(regionIndex)[0] + 1;
-
- while ((regionIndex >= 0)
- && (hiddenColumns.get(regionIndex)[0] <= column + hiddenSoFar
- - lastHidden))
+ while ((index > 0)
+ && (hiddenColumns.get(index)[1] > column + hiddenCount))
{
- int[] region = hiddenColumns.get(regionIndex);
- hiddenSoFar -= lastHidden;
- lastHidden = region[1] - region[0] + 1;
- regionIndex--;
+ index--;
+ int[] region = hiddenColumns.get(index);
+ hiddenCount -= region[1] - region[0] + 1;
}
}
-
- int result = hiddenSoFar;
- if ((regionIndex >= 0) && (regionIndex < hiddenColumns.size())
- && (hiddenColumns.get(regionIndex)[0] <= column + hiddenSoFar)
- && (hiddenColumns.get(regionIndex)[1] >= column + hiddenSoFar))
- {
- int[] region = hiddenColumns.get(regionIndex);
- result += region[1] - region[0] + 1;
- }
-
- return result;
+ updateCursor(index, hiddenCount);
+ return hiddenCount;
}
-
- /* public int findVisiblePositionFromAbsolute(int column)
- {
-
- }
-
- public int findAbsolutePositionFromVisible(int column)
- {
-
- }*/
}