* left-most visible column will always be returned.
*
* @param hiddenColumn
- * int
- * @return int
+ * the column index in the full alignment including hidden columns
+ * @return the position of the column in the visible alignment
*/
public int findColumnPosition(int hiddenColumn)
{
result -= region[1] + 1 - region[0];
}
} while ((hiddenColumn > region[1]) && (index < hiddenColumns.size()));
- if (hiddenColumn > region[0] && hiddenColumn < region[1])
- {
- return region[0] + hiddenColumn - result;
+
+ if (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
+
+ return result - (hiddenColumn - region[0] + 1);
}
}
return result; // return the shifted position after removing hidden columns.
cs.hideColumns(4, 4);
assertEquals(4, cs.findColumnPosition(5));
+ // hiding column 4 moves column 4 to position 3
+ assertEquals(3, cs.findColumnPosition(4));
+
// hiding columns 1 and 2 moves column 5 to column 2
cs.hideColumns(1, 2);
assertEquals(2, cs.findColumnPosition(5));
+
+ // check with > 1 hidden column regions
+ // where some columns are in the hidden regions
+ ColumnSelection cs2 = new ColumnSelection();
+ cs2.hideColumns(5, 10);
+ cs2.hideColumns(20, 27);
+ cs2.hideColumns(40, 44);
+
+ // hiding columns 5-10 and 20-27 moves column 8 to column 4
+ assertEquals(4, cs2.findColumnPosition(8));
+
+ // and moves column 24 to 13
+ assertEquals(13, cs2.findColumnPosition(24));
+
+ // and moves column 28 to 14
+ assertEquals(14, cs2.findColumnPosition(28));
+
+ // and moves column 40 to 25
+ assertEquals(25, cs2.findColumnPosition(40));
}
/**