From: gmungoc Date: Wed, 28 Nov 2018 15:22:28 +0000 (+0000) Subject: JAL-3164 redraw complement overview on hide columns X-Git-Tag: Release_2_11_0~17^2~90^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=06476b6d02ef690bf684905cba39eb7b5db7525b;p=jalview.git JAL-3164 redraw complement overview on hide columns --- diff --git a/src/jalview/datamodel/Alignment.java b/src/jalview/datamodel/Alignment.java index 3ba35b6..3e0856a 100755 --- a/src/jalview/datamodel/Alignment.java +++ b/src/jalview/datamodel/Alignment.java @@ -1922,9 +1922,12 @@ public class Alignment implements AlignmentI } @Override - public void setHiddenColumns(HiddenColumns cols) + public boolean setHiddenColumns(HiddenColumns cols) { + boolean changed = cols == null ? hiddenCols != null + : !cols.equals(hiddenCols); hiddenCols = cols; + return changed; } @Override diff --git a/src/jalview/datamodel/AlignmentI.java b/src/jalview/datamodel/AlignmentI.java index 5fb16d6..9c73873 100755 --- a/src/jalview/datamodel/AlignmentI.java +++ b/src/jalview/datamodel/AlignmentI.java @@ -581,11 +581,13 @@ public interface AlignmentI extends AnnotatedCollectionI AlignedCodonFrame getMapping(SequenceI mapFrom, SequenceI mapTo); /** - * Set the hidden columns collection on the alignment + * Set the hidden columns collection on the alignment. Answers true if the + * hidden column selection changed, else false. * * @param cols + * @return */ - public void setHiddenColumns(HiddenColumns cols); + public boolean setHiddenColumns(HiddenColumns cols); /** * Set the first sequence as representative and hide its insertions. Typically diff --git a/src/jalview/datamodel/HiddenColumns.java b/src/jalview/datamodel/HiddenColumns.java index a7e93da..2d43f02 100644 --- a/src/jalview/datamodel/HiddenColumns.java +++ b/src/jalview/datamodel/HiddenColumns.java @@ -469,6 +469,10 @@ public class HiddenColumns } } + /** + * Answers true if obj is an instance of HiddenColumns, and holds the same + * array of start-end column ranges as this, else answers false + */ @Override public boolean equals(Object obj) { diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 8b2e7bc..2d3eb10 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -2280,7 +2280,7 @@ public class SeqPanel extends JPanel HiddenColumns hs = new HiddenColumns(); MappingUtils.mapColumnSelection(colsel, hidden, sourceAv, av, cs, hs); av.setColumnSelection(cs); - av.getAlignment().setHiddenColumns(hs); + boolean hiddenChanged = av.getAlignment().setHiddenColumns(hs); // lastly, update any dependent dialogs if (ap.getCalculationDialog() != null) @@ -2288,7 +2288,11 @@ public class SeqPanel extends JPanel ap.getCalculationDialog().validateCalcTypes(); } - PaintRefresher.Refresh(this, av.getSequenceSetId()); + /* + * repaint alignment, and also Overview or Structure + * if hidden column selection has changed + */ + ap.paintAlignment(hiddenChanged, hiddenChanged); return true; } diff --git a/test/jalview/datamodel/AlignmentTest.java b/test/jalview/datamodel/AlignmentTest.java index 1d1ebd6..8aed114 100644 --- a/test/jalview/datamodel/AlignmentTest.java +++ b/test/jalview/datamodel/AlignmentTest.java @@ -1484,4 +1484,52 @@ public class AlignmentTest assertEquals(".JKLMNO", seq2.getSequenceAsString()); assertEquals(".PQR...", seq3.getSequenceAsString()); } + + /** + * Test for setHiddenColumns, to check it returns true if the hidden columns + * have changed, else false + */ + @Test(groups = { "Functional" }) + public void testSetHiddenColumns() + { + AlignmentI al = new Alignment(new SequenceI[] {}); + assertFalse(al.getHiddenColumns().hasHiddenColumns()); + + HiddenColumns hc = new HiddenColumns(); + assertFalse(al.setHiddenColumns(hc)); // no change + assertSame(hc, al.getHiddenColumns()); + + hc.hideColumns(2, 4); + assertTrue(al.getHiddenColumns().hasHiddenColumns()); + + /* + * set a different object but with the same columns hidden + */ + HiddenColumns hc2 = new HiddenColumns(); + hc2.hideColumns(2, 4); + assertFalse(al.setHiddenColumns(hc2)); // no change + assertSame(hc2, al.getHiddenColumns()); + + assertTrue(al.setHiddenColumns(null)); + assertNull(al.getHiddenColumns()); + assertTrue(al.setHiddenColumns(hc)); + assertSame(hc, al.getHiddenColumns()); + + al.getHiddenColumns().hideColumns(10, 12); + hc2.hideColumns(10, 12); + assertFalse(al.setHiddenColumns(hc2)); // no change + + /* + * hide columns 15-16 then 17-18 in hc + * hide columns 15-18 in hc2 + * these are not now 'equal' objects even though they + * represent the same set of columns + */ + assertSame(hc2, al.getHiddenColumns()); + hc.hideColumns(15, 16); + hc.hideColumns(17, 18); + hc2.hideColumns(15, 18); + assertFalse(hc.equals(hc2)); + assertTrue(al.setHiddenColumns(hc)); // 'changed' + } }