X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fdatamodel%2FHiddenColumnsCursor.java;h=89c4f99efdb2efd7e64eaeda961d492ab4e08dc1;hb=ecdbc96815298ac853543640881ef8d2384b48a1;hp=3501fce77c2ba26b2d4173f26256cf09edaab89e;hpb=9e064d395de4746f14106c1c296bc94696a6190e;p=jalview.git diff --git a/src/jalview/datamodel/HiddenColumnsCursor.java b/src/jalview/datamodel/HiddenColumnsCursor.java index 3501fce..89c4f99 100644 --- a/src/jalview/datamodel/HiddenColumnsCursor.java +++ b/src/jalview/datamodel/HiddenColumnsCursor.java @@ -118,68 +118,10 @@ public class HiddenColumnsCursor * @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 @@ -189,13 +131,37 @@ public class HiddenColumnsCursor * 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(); @@ -205,38 +171,47 @@ public class HiddenColumnsCursor 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; } + }