if (av.getShowHiddenMarkers())
{
int widthx = 1 + endx - startx;
- for (int i = 0; i < hidden.getHiddenRegions().size(); i++)
+ List<Integer> positions = hidden.findHiddenRegionPositions();
+ for (int pos : positions)
{
- res = hidden.findHiddenRegionPosition(i) - startx;
+ res = pos - startx;
if (res < 0 || res > widthx)
{
import java.awt.Image;
import java.awt.Panel;
import java.beans.PropertyChangeEvent;
+import java.util.List;
public class SeqCanvas extends Panel implements ViewportListenerI
{
HiddenColumns hidden = av.getAlignment().getHiddenColumns();
g.setColor(Color.blue);
int res;
- for (int i = 0; i < hidden.getHiddenRegions()
- .size(); i++)
+ List<Integer> positions = hidden.findHiddenRegionPositions();
+ for (int pos : positions)
{
- res = hidden.findHiddenRegionPosition(i)
- - startRes;
+ res = pos - startRes;
if (res < 0 || res > endx - startRes)
{
}
/**
- * Use this method to determine where the next hiddenRegion starts
+ * Use this method to determine the set of hiddenRegion start positions
*
- * @param hiddenRegion
- * index of hidden region (counts from 0)
- * @return column number in visible view
+ * @return list of column number in visible view where hidden regions start
*/
- public int findHiddenRegionPosition(int hiddenRegion)
+ public List<Integer> findHiddenRegionPositions()
{
try
{
lock.readLock().lock();
- int result = 0;
- if (hiddenColumns != null)
+ List<Integer> positions = new ArrayList<>(
+ hiddenColumns.size());
+
+ positions.add(hiddenColumns.elementAt(0)[0]);
+ for (int i = 1; i < hiddenColumns.size(); ++i)
{
- int index = 0;
- int gaps = 0;
- do
+
+ int result = 0;
+ if (hiddenColumns != null)
{
- int[] region = hiddenColumns.elementAt(index);
- if (hiddenRegion == 0)
+ int index = 0;
+ int gaps = 0;
+ do
{
- return region[0];
- }
-
- gaps += region[1] + 1 - region[0];
- result = region[1] + 1;
- index++;
- } while (index <= hiddenRegion);
+ int[] region = hiddenColumns.elementAt(index);
+ gaps += region[1] + 1 - region[0];
+ result = region[1] + 1;
+ index++;
+ } while (index <= i);
- result -= gaps;
+ result -= gaps;
+ }
+ positions.add(result);
}
- return result;
+ return positions;
}
finally
{
if (av.getShowHiddenMarkers())
{
- for (int i = 0; i < hidden.getHiddenRegions()
- .size(); i++)
+ List<Integer> positions = hidden.findHiddenRegionPositions();
+ for (int pos : positions)
{
- res = hidden.findHiddenRegionPosition(i)
- - startx;
+ res = pos - startx;
if (res < 0 || res > widthx)
{
import java.awt.Shape;
import java.awt.image.BufferedImage;
import java.beans.PropertyChangeEvent;
+import java.util.List;
import javax.swing.JComponent;
g.setColor(Color.blue);
int res;
HiddenColumns hidden = av.getAlignment().getHiddenColumns();
- for (int i = 0; i < hidden.getHiddenRegions().size(); i++)
+ List<Integer> positions = hidden.findHiddenRegionPositions();
+ for (int pos : positions)
{
- res = hidden.findHiddenRegionPosition(i) - startRes;
+ res = pos - startRes;
if (res < 0 || res > endx - startRes)
{
assertEquals(toMark, fromMark);
}
}
+
+ @Test(groups = { "Functional" })
+ public void testFindHiddenRegionPositions()
+ {
+ HiddenColumns hc = new HiddenColumns();
+ hc.hideColumns(3, 7);
+ hc.hideColumns(10, 10);
+ hc.hideColumns(14, 15);
+
+ List<Integer> positions = hc.findHiddenRegionPositions();
+ assertEquals(3, positions.size());
+ assertEquals(3, positions.get(0).intValue());
+ assertEquals(5, positions.get(1).intValue());
+ assertEquals(8, positions.get(2).intValue());
+ }
}