From: gmungoc Date: Tue, 17 Jan 2017 15:01:01 +0000 (+0000) Subject: JAL-2370 fix bug when hiding a range including two or more hidden ranges X-Git-Tag: Release_2_10_3b1~370 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=b4be31307e3a1e6d3dbb43bd14dfd012be6a3dfd;p=jalview.git JAL-2370 fix bug when hiding a range including two or more hidden ranges --- diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index d651c0b..c467f4a 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -866,6 +866,24 @@ public class ColumnSelection */ region[0] = Math.min(region[0], start); region[1] = Math.max(region[1], end); + + /* + * also update or remove any subsequent ranges + * that are overlapped + */ + while (i < hiddenColumns.size() - 1) + { + int[] nextRegion = hiddenColumns.get(i + 1); + if (nextRegion[0] > end + 1) + { + /* + * gap to next hidden range - no more to update + */ + break; + } + region[1] = Math.max(nextRegion[1], end); + hiddenColumns.remove(i + 1); + } return; } } diff --git a/src/jalview/gui/ScalePanel.java b/src/jalview/gui/ScalePanel.java index 0aa2459..00d465a 100755 --- a/src/jalview/gui/ScalePanel.java +++ b/src/jalview/gui/ScalePanel.java @@ -424,6 +424,9 @@ public class ScalePanel extends JPanel implements MouseMotionListener, { } + /** + * Creates a tooltip when the mouse is over a hidden columns marker + */ @Override public void mouseMoved(MouseEvent evt) { @@ -448,11 +451,11 @@ public class ScalePanel extends JPanel implements MouseMotionListener, ToolTipManager.sharedInstance().registerComponent(this); this.setToolTipText(MessageManager .getString("label.reveal_hidden_columns")); - break; + repaint(); + return; } } } - repaint(); } /** diff --git a/test/jalview/datamodel/ColumnSelectionTest.java b/test/jalview/datamodel/ColumnSelectionTest.java index a9ad4c2..4faa482 100644 --- a/test/jalview/datamodel/ColumnSelectionTest.java +++ b/test/jalview/datamodel/ColumnSelectionTest.java @@ -205,12 +205,11 @@ public class ColumnSelectionTest assertEquals("[5, 5]", Arrays.toString(hidden.get(1))); // hiding column 4 expands [3, 3] to [3, 4] - // not fancy enough to coalesce this into [3, 5] though + // and merges to [5, 5] to make [3, 5] cs.hideColumns(4); hidden = cs.getHiddenColumns(); - assertEquals(2, hidden.size()); - assertEquals("[3, 4]", Arrays.toString(hidden.get(0))); - assertEquals("[5, 5]", Arrays.toString(hidden.get(1))); + assertEquals(1, hidden.size()); + assertEquals("[3, 5]", Arrays.toString(hidden.get(0))); // clear hidden columns (note they are added to selected) cs.revealAllHiddenColumns(); @@ -761,4 +760,59 @@ public class ColumnSelectionTest assertEquals("[5, 7]", Arrays.toString(cs2.getHiddenColumns().get(0))); assertEquals("[10, 11]", Arrays.toString(cs2.getHiddenColumns().get(1))); } + + /** + * Test for the case when a hidden range encloses more one already hidden + * range + */ + @Test(groups = { "Functional" }) + public void testHideColumns_subsumingHidden() + { + /* + * JAL-2370 bug scenario: + * two hidden ranges subsumed by a third + */ + ColumnSelection cs = new ColumnSelection(); + cs.hideColumns(49, 59); + cs.hideColumns(69, 79); + List hidden = cs.getHiddenColumns(); + assertEquals(2, hidden.size()); + assertEquals("[49, 59]", Arrays.toString(hidden.get(0))); + assertEquals("[69, 79]", Arrays.toString(hidden.get(1))); + + cs.hideColumns(48, 80); + hidden = cs.getHiddenColumns(); + assertEquals(1, hidden.size()); + assertEquals("[48, 80]", Arrays.toString(hidden.get(0))); + + /* + * another...joining hidden ranges + */ + cs = new ColumnSelection(); + cs.hideColumns(10, 20); + cs.hideColumns(30, 40); + cs.hideColumns(50, 60); + // hiding 21-49 should merge to one range + cs.hideColumns(21, 49); + hidden = cs.getHiddenColumns(); + assertEquals(1, hidden.size()); + assertEquals("[10, 60]", Arrays.toString(hidden.get(0))); + + /* + * another...lef overlap, subsumption, right overlap, + * no overlap of existing hidden ranges + */ + cs = new ColumnSelection(); + cs.hideColumns(10, 20); + cs.hideColumns(10, 20); + cs.hideColumns(30, 35); + cs.hideColumns(40, 50); + cs.hideColumns(60, 70); + + cs.hideColumns(15, 45); + hidden = cs.getHiddenColumns(); + assertEquals(2, hidden.size()); + assertEquals("[10, 50]", Arrays.toString(hidden.get(0))); + assertEquals("[60, 70]", Arrays.toString(hidden.get(1))); + } }