{
try
{
- /* LOCK.readLock().lock();
- int result = hiddenColumn;
- int[] region = null;
- if (hiddenColumns != null)
- {
- Iterator<int[]> it = new RegionsIterator(0, hiddenColumn,
- hiddenColumns, cursor);
- while (it.hasNext())
- {
- region = it.next();
- if (hiddenColumn > region[1])
- {
- result -= region[1] + 1 - region[0];
- }
- }
-
- if (region != null && hiddenColumn >= region[0]
- && hiddenColumn <= region[1])
- {
- // Here the hidden column is within a region, so
- // we want to return the position of region[0]-1, adjusted for any
- // earlier hidden columns.
- // Calculate the difference between the actual hidden col position
- // and region[0]-1, and then subtract from result to convert result
- // from the adjusted hiddenColumn value to the adjusted region[0]-1
- // value.
-
- // However, if the region begins at 0 we cannot return region[0]-1
- // just return 0
- if (region[0] == 0)
- {
- return 0;
- }
- else
- {
- return result - (hiddenColumn - region[0] + 1);
- }
- }
- }
- return result; // return the shifted position after removing hidden
- // columns.
- } finally
- {
- LOCK.readLock().unlock();
- }*/
-
LOCK.readLock().lock();
int result = hiddenColumn;
- // int[] region = null;
+
if (hiddenColumns != null)
{
int index = cursor.findRegionForColumn(hiddenColumn);
}
}
}
- System.out.println(hiddenColumn + " " + result);
return result; // return the shifted position after removing hidden
// columns.
} finally
try
{
LOCK.writeLock().lock();
- Iterator<int[]> it = new RegionsIterator(start, start, hiddenColumns,
- cursor);
- while (it.hasNext())
+
+ if (hiddenColumns != null)
{
- int[] region = it.next();
- if (start == region[0])
+ int regionIndex = cursor.findRegionForColumn(start);
+
+ if (regionIndex != -1 && regionIndex != hiddenColumns.size())
{
- for (int j = region[0]; j < region[1] + 1; j++)
+ // regionIndex is the region which either contains start
+ // or lies to the right of start
+ int[] region = hiddenColumns.get(regionIndex);
+ if (start == region[0])
{
- sel.addElement(j);
+ for (int j = region[0]; j < region[1] + 1; j++)
+ {
+ sel.addElement(j);
+ }
+ hiddenColumns.remove(regionIndex);
+
+ if (hiddenColumns.isEmpty())
+ {
+ hiddenColumns = null;
+ }
+ cursor.updateForDeletedRegion(hiddenColumns);
}
- it.remove();
- break;
- }
- else if (start < region[0])
- {
- break; // passed all possible matching regions
}
}
-
- if (hiddenColumns.size() == 0)
- {
- hiddenColumns = null;
- }
- cursor.resetCursor(hiddenColumns);
} finally
{
LOCK.writeLock().unlock();
if (hiddenColumns != null)
{
int regionindex = cursor.findRegionForColumn(adjres - 1);
- if (hiddenColumns.get(regionindex)[1] == adjres - 1)
+ if (regionindex < hiddenColumns.size()
+ && hiddenColumns.get(regionindex)[1] == adjres - 1)
{
reveal = hiddenColumns.get(regionindex);
}
else
{
regionindex = cursor.findRegionForColumn(adjres + 1);
- if (hiddenColumns.get(regionindex)[0] == adjres + 1)
+ if (regionindex < hiddenColumns.size()
+ && hiddenColumns.get(regionindex)[0] == adjres + 1)
{
reveal = hiddenColumns.get(regionindex);
}
/**
* Set the cursor to a position
*
- * @param first
- * absolute position of first hidden column
- * @param last
- * absolute position of last hidden column
- * @param index
- * index of last visited region
- * @param hiddenCount
- * number of hidden columns before last visited region
+ * @param hiddenCols
*/
protected void resetCursor(List<int[]> hiddenCols)
{
synchronized (this)
{
+ hiddenColumns = hiddenCols;
if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
{
- hiddenColumns = hiddenCols;
firstColumn = hiddenColumns.get(0)[0];
regionIndex = 0;
hiddenSoFar = 0;
}
}
+ /**
+ * Delete the region the cursor is currently at. Avoids having to reset the
+ * cursor just because we deleted a region.
+ *
+ * @param hiddenCols
+ */
+ protected void updateForDeletedRegion(List<int[]> hiddenCols)
+ {
+
+ if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
+ {
+ // if there is a region to the right of the current region,
+ // nothing changes; otherwise
+ // we deleted the last region (index=hiddenCols.size()-1)
+ // or the index was at the end of the alignment (index=hiddenCols.size())
+ if (regionIndex >= hiddenColumns.size() - 1)
+ {
+ // deleted last region, index is now end of alignment
+ regionIndex = hiddenCols.size();
+ }
+ }
+
+ hiddenColumns = hiddenCols;
+ }
+
protected void updateCursor(int index, int hiddenCount)
{
synchronized (this)