From 1c251a57c7b2fb70dabceb480d0170363357558f Mon Sep 17 00:00:00 2001 From: kiramt Date: Wed, 7 Jun 2017 10:58:04 +0100 Subject: [PATCH] JAL-2591 updated HiddenColumns::findHiddenRegionPositions + test --- src/jalview/appletgui/ScalePanel.java | 5 +-- src/jalview/appletgui/SeqCanvas.java | 8 ++--- src/jalview/datamodel/HiddenColumns.java | 44 +++++++++++++------------ src/jalview/gui/ScalePanel.java | 7 ++-- src/jalview/gui/SeqCanvas.java | 6 ++-- test/jalview/datamodel/HiddenColumnsTest.java | 15 +++++++++ 6 files changed, 52 insertions(+), 33 deletions(-) diff --git a/src/jalview/appletgui/ScalePanel.java b/src/jalview/appletgui/ScalePanel.java index 7ead681..5bb0f75 100755 --- a/src/jalview/appletgui/ScalePanel.java +++ b/src/jalview/appletgui/ScalePanel.java @@ -449,10 +449,11 @@ public class ScalePanel extends Panel implements MouseMotionListener, if (av.getShowHiddenMarkers()) { int widthx = 1 + endx - startx; - for (int i = 0; i < hidden.getHiddenRegions().size(); i++) + List positions = hidden.findHiddenRegionPositions(); + for (int pos : positions) { - res = hidden.findHiddenRegionPosition(i) - startx; + res = pos - startx; if (res < 0 || res > widthx) { diff --git a/src/jalview/appletgui/SeqCanvas.java b/src/jalview/appletgui/SeqCanvas.java index b96c491..94f1caa 100755 --- a/src/jalview/appletgui/SeqCanvas.java +++ b/src/jalview/appletgui/SeqCanvas.java @@ -37,6 +37,7 @@ import java.awt.Graphics; import java.awt.Image; import java.awt.Panel; import java.beans.PropertyChangeEvent; +import java.util.List; public class SeqCanvas extends Panel implements ViewportListenerI { @@ -487,11 +488,10 @@ 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 positions = hidden.findHiddenRegionPositions(); + for (int pos : positions) { - res = hidden.findHiddenRegionPosition(i) - - startRes; + res = pos - startRes; if (res < 0 || res > endx - startRes) { diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index 9722c0a..1e1a58b 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -273,39 +273,41 @@ public class HiddenColumns implements Iterable } /** - * 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 findHiddenRegionPositions() { try { lock.readLock().lock(); - int result = 0; - if (hiddenColumns != null) + List 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 { diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 81befd8..dcaafcd 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -497,11 +497,10 @@ public class ScalePanel extends JPanel implements MouseMotionListener, if (av.getShowHiddenMarkers()) { - for (int i = 0; i < hidden.getHiddenRegions() - .size(); i++) + List positions = hidden.findHiddenRegionPositions(); + for (int pos : positions) { - res = hidden.findHiddenRegionPosition(i) - - startx; + res = pos - startx; if (res < 0 || res > widthx) { diff --git a/src/jalview/gui/SeqCanvas.java b/src/jalview/gui/SeqCanvas.java index 6f3ff58..4114385 100755 --- a/src/jalview/gui/SeqCanvas.java +++ b/src/jalview/gui/SeqCanvas.java @@ -40,6 +40,7 @@ import java.awt.RenderingHints; import java.awt.Shape; import java.awt.image.BufferedImage; import java.beans.PropertyChangeEvent; +import java.util.List; import javax.swing.JComponent; @@ -562,9 +563,10 @@ public class SeqCanvas extends JComponent implements ViewportListenerI g.setColor(Color.blue); int res; HiddenColumns hidden = av.getAlignment().getHiddenColumns(); - for (int i = 0; i < hidden.getHiddenRegions().size(); i++) + List positions = hidden.findHiddenRegionPositions(); + for (int pos : positions) { - res = hidden.findHiddenRegionPosition(i) - startRes; + res = pos - startRes; if (res < 0 || res > endx - startRes) { diff --git a/test/jalview/datamodel/HiddenColumnsTest.java b/test/jalview/datamodel/HiddenColumnsTest.java index 10808d6..b9becf3 100644 --- a/test/jalview/datamodel/HiddenColumnsTest.java +++ b/test/jalview/datamodel/HiddenColumnsTest.java @@ -585,4 +585,19 @@ public class HiddenColumnsTest 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 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()); + } } -- 1.7.10.2