* @return cursor pointing to hidden region containing the column (if hidden)
* or to the right of the column (if visible)
*/
- protected HiddenCursorPosition findRegionForColumn(int column)
+ /*protected HiddenCursorPosition findRegionForColumn(int column)
{
- if (hiddenColumns.isEmpty())
- {
- return null;
- }
-
- HiddenCursorPosition oldpos = cursorPos;
- int index = oldpos.getRegionIndex();
- int hiddenCount = oldpos.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;
- }
-
- // this if statement excludes case where column is in current region
- // - no changes needed
- if (column < firstColumn)
- {
- index = 0;
- hiddenCount = 0;
- }
- // column is after current region
- 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)
- // stop when we find the region *before* column
- // i.e. the next region starts after column or if not, ends after column
- while ((index < hiddenColumns.size())
- && (column > hiddenColumns.get(index)[1]))
- {
- int[] region = hiddenColumns.get(index);
- hiddenCount += region[1] - region[0] + 1;
- index++;
- }
- }
- // column is before current region
- else if (column < hiddenColumns.get(index)[0])
- {
- // column is before or in the previous region
- while ((index > 0) && (hiddenColumns.get(index - 1)[1] >= column))
- {
- index--;
- int[] region = hiddenColumns.get(index);
- hiddenCount -= region[1] - region[0] + 1;
- }
- }
-
- if (index != oldpos.getRegionIndex()
- || hiddenCount != oldpos.getHiddenSoFar())
- {
- cursorPos = new HiddenCursorPosition(index,
- hiddenCount);
- return cursorPos;
- }
- return oldpos;
- }
+ return findRegionForColumn(column, false);
+ }*/
/**
* Get the cursor pointing to the hidden region just after a visible column
* column is visible)
* @return cursor pointing to hidden region to the right of the column
*/
- protected HiddenCursorPosition findRegionForVisColumn(int column)
+ /* protected HiddenCursorPosition findRegionForVisColumn(int column)
+ {
+ return findRegionForColumn(column, true);
+ }*/
+
+ /**
+ * Get the cursor pointing to the hidden region that column is within (if
+ * column is hidden) or which is to the right of column (if column is
+ * visible). If no hidden columns are to the right, returns a cursor pointing
+ * to an imaginary hidden region beyond the end of the hidden columns
+ * collection (this ensures the count of previous hidden columns is correct).
+ * If hidden columns is empty returns null.
+ *
+ * @param column
+ * index of column in visible or absolute coordinates
+ * @param useVisible
+ * true if column is in visible coordinates, false if absolute
+ * @return cursor pointing to hidden region containing the column (if hidden)
+ * or to the right of the column (if visible)
+ */
+ protected HiddenCursorPosition findRegionForColumn(int column,
+ boolean useVisible)
{
if (hiddenColumns.isEmpty())
{
return null;
}
+ // used to add in hiddenColumns offset when working with visible columns
+ int offset = (useVisible ? 1 : 0);
+
HiddenCursorPosition oldpos = cursorPos;
int index = oldpos.getRegionIndex();
int hiddenCount = oldpos.getHiddenSoFar();
index = 0;
hiddenCount = 0;
}
+
+ // column is after current region
else if ((index < hiddenColumns.size())
- && (hiddenColumns.get(index)[0] <= column + hiddenCount))
+ && (hiddenColumns.get(index)[0] <= column
+ + offset * hiddenCount))
{
// iterate from where we are now, if we're lucky we'll be close by
// (but still better than iterating from 0)
+ // stop when we find the region *before* column
+ // i.e. the next region starts after column or if not, ends after column
while ((index < hiddenColumns.size())
- && (hiddenColumns.get(index)[0] <= column + hiddenCount))
+ && (((useVisible && hiddenColumns.get(index)[0] <= column
+ + offset * hiddenCount))
+ || (!useVisible
+ && hiddenColumns.get(index)[1] < column)))
{
int[] region = hiddenColumns.get(index);
hiddenCount += region[1] - region[0] + 1;
index++;
}
}
+
+ // column is before current region
else
{
- while ((index > 0)
- && (hiddenColumns.get(index - 1)[1] >= column + hiddenCount))
+ // column is before or in the previous region
+ while ((index > 0) && (hiddenColumns.get(index - 1)[1] >= column
+ + offset * hiddenCount))
{
index--;
int[] region = hiddenColumns.get(index);
hiddenCount -= region[1] - region[0] + 1;
}
-
}
if (index != oldpos.getRegionIndex()
|| hiddenCount != oldpos.getHiddenSoFar())
{
- cursorPos = new HiddenCursorPosition(index,
- hiddenCount);
- return cursorPos;
+ return new HiddenCursorPosition(index, hiddenCount);
}
return oldpos;
}
+
}