{
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;
{
int index = cursor.findRegionForColumn(hiddenColumn);
int hiddenBeforeCol = cursor.getHiddenSoFar();
-
+
// just subtract hidden cols count - this works fine if column is
// visible
result = hiddenColumn - hiddenBeforeCol;
-
+
// now check in case column is hidden - it will be in the returned
// hidden region
if (index < hiddenColumns.size())
}
}
}
+ System.out.println(hiddenColumn + " " + result);
return result; // return the shifted position after removing hidden
// columns.
} finally
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
package jalview.datamodel;
import java.util.List;
// absolute position of first hidden column
private int firstColumn;
- // absolute position of last hidden column
- private int lastColumn;
-
// index of last visited region
private int regionIndex;
{
hiddenColumns = hiddenCols;
firstColumn = hiddenColumns.get(0)[0];
- lastColumn = hiddenColumns.get(hiddenColumns.size() - 1)[1];
regionIndex = 0;
hiddenSoFar = 0;
}
// column is before current region
else if (column < hiddenColumns.get(index)[0])
{
- while ((index > 0) && (hiddenColumns.get(index)[1] > column))
+ // column is before or in the previous region
+ if ((index > 0) && (hiddenColumns.get(index - 1)[1] >= column))
{
- index--;
- int[] region = hiddenColumns.get(index);
- hiddenCount -= region[1] - region[0] + 1;
+ while ((index > 0) && (hiddenColumns.get(index)[1] > column))
+ {
+ index--;
+ int[] region = hiddenColumns.get(index);
+ hiddenCount -= region[1] - region[0] + 1;
+ }
}
}
updateCursor(index, hiddenCount);
return index;
}
+ /**
+ * Get the number of hidden columns in regions before column i.e. excludes
+ * hidden columns in the region column is in, if any
+ *
+ * @param column
+ * index of column in visible alignment
+ * @return
+ */
protected int getHiddenOffset(int column)
{
if (hiddenColumns == null)
index++;
}
}
- else if (index < hiddenColumns.size())
+ else
{
while ((index > 0)
&& (hiddenColumns.get(index - 1)[1] >= column + hiddenCount))
--- /dev/null
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3
+ * of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see <http://www.gnu.org/licenses/>.
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
+ */
+package jalview.datamodel;
+
+import static org.testng.AssertJUnit.assertEquals;
+
+import java.util.ArrayList;
+import java.util.List;
+
+import org.testng.annotations.Test;
+
+public class HiddenColumnsCursorTest
+{
+ /**
+ * Test the method which finds the corresponding region given a column
+ */
+ @Test(groups = { "Functional" })
+ public void testFindRegionForColumn()
+ {
+ HiddenColumnsCursor cursor = new HiddenColumnsCursor();
+
+ int regionIndex = cursor.findRegionForColumn(20);
+ assertEquals(-1, regionIndex);
+
+ List<int[]> hidden = new ArrayList<>();
+ hidden.add(new int[] { 53, 76 });
+ hidden.add(new int[] { 104, 125 });
+ cursor.resetCursor(hidden);
+
+ regionIndex = cursor.findRegionForColumn(126);
+ assertEquals(2, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(125);
+ assertEquals(1, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(108);
+ assertEquals(1, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(104);
+ assertEquals(1, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(103);
+ assertEquals(1, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(77);
+ assertEquals(1, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(76);
+ assertEquals(0, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(53);
+ assertEquals(0, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(52);
+ assertEquals(0, regionIndex);
+
+ regionIndex = cursor.findRegionForColumn(0);
+ assertEquals(0, regionIndex);
+ }
+
+ /**
+ * Test the method which counts the number of hidden columns before a column
+ */
+ @Test(groups = { "Functional" })
+ public void testGetHiddenOffset()
+ {
+ HiddenColumnsCursor cursor = new HiddenColumnsCursor();
+
+ int offset = cursor.getHiddenOffset(20);
+ assertEquals(-1, offset);
+
+ List<int[]> hidden = new ArrayList<>();
+ hidden.add(new int[] { 53, 76 });
+ hidden.add(new int[] { 104, 125 });
+ cursor.resetCursor(hidden);
+
+ offset = cursor.getHiddenOffset(80);
+ assertEquals(46, offset);
+
+ offset = cursor.getHiddenOffset(79);
+ assertEquals(24, offset);
+
+ offset = cursor.getHiddenOffset(53);
+ assertEquals(24, offset);
+
+ offset = cursor.getHiddenOffset(52);
+ assertEquals(0, offset);
+
+ offset = cursor.getHiddenOffset(10);
+ assertEquals(0, offset);
+
+ offset = cursor.getHiddenOffset(0);
+ assertEquals(0, offset);
+ }
+
+}