1 package jalview.datamodel;
5 public class HiddenColumnsCursor
7 // absolute position of first hidden column
8 private int firstColumn;
10 // absolute position of last hidden column
11 private int lastColumn;
13 // index of last visited region
14 private int regionIndex;
16 // number of hidden columns before last visited region
17 private int hiddenSoFar;
19 // flag to indicate if current cursor settings are valid
20 private boolean isValid;
22 private List<int[]> hiddenColumns;
24 protected HiddenColumnsCursor()
30 * Set the cursor to a position
33 * absolute position of first hidden column
35 * absolute position of last hidden column
37 * index of last visited region
39 * number of hidden columns before last visited region
41 protected void resetCursor(// int first, int last, int index, int hiddenCount,
42 List<int[]> hiddenCols)
45 if ((hiddenCols != null) && (!hiddenCols.isEmpty()))
47 hiddenColumns = hiddenCols;
48 firstColumn = hiddenColumns.get(0)[0];
49 lastColumn = hiddenColumns.get(hiddenColumns.size() - 1)[1];
55 protected void updateCursor(int index, int hiddenCount)
58 hiddenSoFar = hiddenCount;
62 * Get the index of the region that column is within (if column is hidden) or
63 * which is to the right of column (if column is visible). If no hidden
64 * columns are to the right, will return size of hiddenColumns. If hidden
65 * columns is empty returns -1.
68 * absolute position of a column in the alignment
69 * @return region index
71 protected int findRegionForColumn(int column)
73 if (hiddenColumns == null)
78 if ((hiddenColumns.get(regionIndex)[0] <= column)
79 && (hiddenColumns.get(regionIndex)[1] >= column))
84 else if (column < firstColumn)
88 else if (column > lastColumn)
90 return hiddenColumns.size();
92 else if (column > hiddenColumns.get(regionIndex)[1])
94 // iterate from where we are now, if we're lucky we'll be close by
95 // (but still better than iterating from 0)
96 while ((regionIndex < hiddenColumns.size())
97 && (hiddenColumns.get(regionIndex)[0] <= column))
99 int[] region = hiddenColumns.get(regionIndex);
100 hiddenSoFar += region[1] - region[0] + 1;
105 else // (column < hiddenColumns.get(regionIndex)[0])
108 while ((regionIndex >= 0)
109 && (hiddenColumns.get(regionIndex)[0] > column))
111 int[] region = hiddenColumns.get(regionIndex);
112 hiddenSoFar -= lastHidden;
113 lastHidden = region[1] - region[0] + 1;
116 hiddenSoFar -= lastHidden;
121 protected int getHiddenOffset(int column)
123 if (hiddenColumns == null)
128 if (column < firstColumn)
132 else if ((regionIndex < hiddenColumns.size())
133 && (hiddenColumns.get(regionIndex)[0] <= column
137 // iterate from where we are now, if we're lucky we'll be close by
138 // (but still better than iterating from 0)
139 while ((regionIndex < hiddenColumns.size())
140 && (hiddenColumns.get(regionIndex)[0] <= column
143 int[] region = hiddenColumns.get(regionIndex);
144 hiddenSoFar += region[1] - region[0] + 1;
148 else if (regionIndex < hiddenColumns.size())
150 int lastHidden = hiddenColumns.get(regionIndex)[1]
151 - hiddenColumns.get(regionIndex)[0] + 1;
153 while ((regionIndex >= 0)
154 && (hiddenColumns.get(regionIndex)[0] <= column + hiddenSoFar
157 int[] region = hiddenColumns.get(regionIndex);
158 hiddenSoFar -= lastHidden;
159 lastHidden = region[1] - region[0] + 1;
165 int result = hiddenSoFar;
166 if ((regionIndex >= 0) && (regionIndex < hiddenColumns.size())
167 && (hiddenColumns.get(regionIndex)[0] <= column + hiddenSoFar)
168 && (hiddenColumns.get(regionIndex)[1] >= column + hiddenSoFar))
170 int[] region = hiddenColumns.get(regionIndex);
171 result += region[1] - region[0] + 1;
177 /* public int findVisiblePositionFromAbsolute(int column)
182 public int findAbsolutePositionFromVisible(int column)