gg.setColor(Color.black);
int scalestartx = (startx / 10) * 10;
+ int widthx = 1 + endx - startx;
FontMetrics fm = gg.getFontMetrics(av.getFont());
int y = avcharHeight - fm.getDescent();
res = av.getColumnSelection().findHiddenRegionPosition(i)
- startx;
- if (res < 0 || res > endx - scalestartx)
+ if (res < 0 || res > widthx)
{
continue;
}
* at 0). NOTE 1: The av limits are set in setFont in this class and in the
* adjustment listener in SeqPanel when the scrollbars move.
*/
+ @Override
public void update(Graphics g)
{
paint(g);
g1.translate(-screenY * avcharWidth, 0);
screenY += blockEnd - blockStart + 1;
blockStart = hideEnd + 1;
+
+ if (screenY > (endRes - startRes))
+ {
+ // already rendered last block
+ return;
+ }
}
}
if (screenY <= (endRes - startRes))
{
+ // remaining visible region to render
blockEnd = blockStart + (endRes - startRes) - screenY;
g1.translate(screenY * avcharWidth, 0);
draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
{
return selected.get(0) ? 0 : selected.nextSetBit(0);
}
+
+ /**
+ * @return a series of selection intervals along the range
+ */
+ public List<int[]> getRanges()
+ {
+ List<int[]> rlist = new ArrayList<int[]>();
+ if (selected.isEmpty())
+ {
+ return rlist;
+ }
+ int next = selected.nextSetBit(0), clear = -1;
+ while (next != -1)
+ {
+ clear = selected.nextClearBit(next);
+ rlist.add(new int[] { next, clear - 1 });
+ next = selected.nextSetBit(clear);
+ }
+ return rlist;
+ }
}
IntList selected = new IntList();
}
/**
+ * @return list of int arrays containing start and end column position for
+ * runs of selected columns ordered from right to left.
+ */
+ public List<int[]> getSelectedRanges()
+ {
+ return selected.getRanges();
+ }
+
+ /**
*
* @param col
* index to search for in column selection
/**
* Use this method to determine where the next hiddenRegion starts
+ *
+ * @param hiddenRegion
+ * index of hidden region (counts from 0)
+ * @return column number in visible view
*/
public int findHiddenRegionPosition(int hiddenRegion)
{
gaps += region[1] + 1 - region[0];
result = region[1] + 1;
index++;
- } while (index < hiddenRegion + 1);
+ } while (index <= hiddenRegion);
result -= gaps;
}
public void hideSelectedColumns()
{
- while (!selected.isEmpty())
- {
- int column = selected.elementAt(0);
- hideColumns(column);
+ synchronized (selected) {
+ for (int[] selregions:selected.getRanges())
+ {
+ hideColumns(selregions[0], selregions[1]);
+ }
+ selected.clear();
}
}
gg.setColor(Color.black);
int scalestartx = (startx / 10) * 10;
+ int widthx = 1 + endx - startx;
FontMetrics fm = gg.getFontMetrics(av.getFont());
int y = avCharHeight - fm.getDescent();
for (int i = 0; i < av.getColumnSelection().getHiddenColumns()
.size(); i++)
{
-
res = av.getColumnSelection().findHiddenRegionPosition(i)
- startx;
- if (res < 0 || res > endx - scalestartx)
+ if (res < 0 || res > widthx)
{
continue;
}
*/
// Set this to false to force a full panel paint
+ @Override
public void paintComponent(Graphics g)
{
updateViewport();
g1.translate(-screenY * charWidth, 0);
screenY += blockEnd - blockStart + 1;
blockStart = hideEnd + 1;
+
+ if (screenY > (endRes - startRes))
+ {
+ // already rendered last block
+ return;
+ }
}
if (screenY <= (endRes - startRes))
{
+ // remaining visible region to render
blockEnd = blockStart + (endRes - startRes) - screenY;
g1.translate(screenY * charWidth, 0);
draw(g1, blockStart, blockEnd, startSeq, endSeq, offset);
}
/**
+ * Test the method that gets runs of selected columns ordered by column. If
+ * this fails, HideSelectedColumns may also fail
+ */
+ @Test(groups = { "Functional" })
+ public void testgetSelectedRanges()
+ {
+ ColumnSelection cs = new ColumnSelection();
+ int[] sel = { 2, 3, 4, 7, 8, 9, 20, 21, 22 };
+ for (int col : sel)
+ {
+ cs.addElement(col);
+ }
+ List<int[]> range;
+ range = cs.getSelectedRanges();
+ assertEquals(3, range.size());
+ assertEquals("[2, 4]", Arrays.toString(range.get(0)));
+ assertEquals("[7, 9]", Arrays.toString(range.get(1)));
+ assertEquals("[20, 22]", Arrays.toString(range.get(2)));
+ cs.addElement(0);
+ cs.addElement(1);
+ range = cs.getSelectedRanges();
+ assertEquals(3, range.size());
+ assertEquals("[0, 4]", Arrays.toString(range.get(0)));
+ }
+
+ /**
* Test the method that reveals a range of hidden columns given the start
* column of the range
*/