From: James Procter Date: Thu, 25 May 2023 16:37:52 +0000 (+0100) Subject: JAL-4134 popup menu and annotation row property to control display of display of... X-Git-Tag: Release_2_11_3_0~14^2~3^2^2~11 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=21bc271040ba677787c7863d8332ccd7e8dd0956;p=jalview.git JAL-4134 popup menu and annotation row property to control display of display of column group colouring on matrix --- diff --git a/src/jalview/datamodel/AlignmentAnnotation.java b/src/jalview/datamodel/AlignmentAnnotation.java index b5987f4..de98c64 100755 --- a/src/jalview/datamodel/AlignmentAnnotation.java +++ b/src/jalview/datamodel/AlignmentAnnotation.java @@ -308,6 +308,11 @@ public class AlignmentAnnotation public static final int CONTACT_MAP = 4; + /** + * property that when set to non-empty string disables display of column groups defined on the contact matrix + */ + public static final String CONTACT_MAP_NOGROUPS = "CMNOGRPS"; + public boolean belowAlignment = true; public SequenceGroup groupRef = null; @@ -1745,5 +1750,23 @@ public class AlignmentAnnotation } return aa; } + + /** + * convenience method to check for the 'CONTACT_MAP_NOGROUPS' property for this alignment annotation row + * @return true if no CONTACT_MAP_NOGROUPS property is found, or it is set to "" + */ + public boolean isShowGroupsForContactMatrix() + { + return getProperty(AlignmentAnnotation.CONTACT_MAP_NOGROUPS)==null || "".equals(getProperty(AlignmentAnnotation.CONTACT_MAP_NOGROUPS)); + } + /** + * set the 'CONTACT_MAP_NOGROUPS' property for this alignment annotation row + * @see isShowGroupsForContactMatrix + */ + public void setShowGroupsForContactMatrix(boolean showGroups) + { + setProperty(AlignmentAnnotation.CONTACT_MAP_NOGROUPS, showGroups ? "" : "nogroups"); + } + } diff --git a/src/jalview/gui/AlignViewport.java b/src/jalview/gui/AlignViewport.java index 3b7420f..53dec93 100644 --- a/src/jalview/gui/AlignViewport.java +++ b/src/jalview/gui/AlignViewport.java @@ -45,6 +45,7 @@ import jalview.bin.Console; import jalview.commands.CommandI; import jalview.datamodel.AlignedCodonFrame; import jalview.datamodel.Alignment; +import jalview.datamodel.AlignmentAnnotation; import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.ContactMatrixI; @@ -1161,4 +1162,5 @@ public class AlignViewport extends AlignmentViewport { this.viewName = viewName; } + } diff --git a/src/jalview/gui/AnnotationLabels.java b/src/jalview/gui/AnnotationLabels.java index e3cc36e..f4c37fd 100755 --- a/src/jalview/gui/AnnotationLabels.java +++ b/src/jalview/gui/AnnotationLabels.java @@ -432,6 +432,25 @@ public class AnnotationLabels extends JPanel { pop.addSeparator(); + if (cm.hasGroups()) + { + JCheckBoxMenuItem chitem = new JCheckBoxMenuItem("Show Groups on Matrix"); + boolean showGroups = aa[selectedRow].isShowGroupsForContactMatrix(); + final AlignmentAnnotation sel_row=aa[selectedRow]; + chitem.setState(showGroups); + chitem.addActionListener(new ActionListener() + { + + @Override + public void actionPerformed(ActionEvent e) + { + sel_row.setShowGroupsForContactMatrix(chitem.getState()); + ap.getAnnotationPanel() + .paint(ap.getAnnotationPanel().getGraphics()); + } + }); + pop.add(chitem); + } if (cm.hasTree()) { item = new JMenuItem("Show Tree for Matrix"); diff --git a/src/jalview/renderer/ContactMapRenderer.java b/src/jalview/renderer/ContactMapRenderer.java index a8f6c1b..8f38d02 100644 --- a/src/jalview/renderer/ContactMapRenderer.java +++ b/src/jalview/renderer/ContactMapRenderer.java @@ -102,7 +102,7 @@ public abstract class ContactMapRenderer implements AnnotationRowRendererI HiddenColumns hiddenColumns, ColumnSelection columnSelection, AlignmentAnnotation _aa, Annotation[] aa_annotations, int sRes, int eRes, float min, float max, int y) - { + { if (sRes > aa_annotations.length) { return; @@ -114,7 +114,7 @@ public abstract class ContactMapRenderer implements AnnotationRowRendererI g.setColor(shade.no_data); g.drawLine(x, y2, (eRes - sRes) * charWidth, y2); - + boolean showGroups = _aa.isShowGroupsForContactMatrix(); int column; int aaMax = aa_annotations.length - 1; ContactMatrixI cm = viewport.getContactMatrix(_aa); @@ -204,7 +204,7 @@ public abstract class ContactMapRenderer implements AnnotationRowRendererI { col = shade.hidden; } - if (gpcol != null && gpcol != Color.white) + if (showGroups && gpcol != null && gpcol != Color.white) { // todo - could overlay group as a transparent rectangle ? col = new Color( diff --git a/test/jalview/datamodel/AlignmentAnnotationTests.java b/test/jalview/datamodel/AlignmentAnnotationTests.java index 2f46eca..4615204 100644 --- a/test/jalview/datamodel/AlignmentAnnotationTests.java +++ b/test/jalview/datamodel/AlignmentAnnotationTests.java @@ -20,7 +20,9 @@ */ package jalview.datamodel; +import static org.testng.Assert.assertFalse; import static org.testng.Assert.assertNull; +import static org.testng.Assert.assertTrue; import static org.testng.AssertJUnit.assertEquals; import jalview.analysis.AlignSeq; @@ -426,4 +428,23 @@ public class AlignmentAnnotationTests assertNull(ann.annotations[0]); assertNull(ann.annotations[4]); } + /** + * test the contact matrix nogroups property methods + */ + @Test(groups= {"Functional"}) + public void test_contactMatrixGroups() + { + AlignmentAnnotation aa = new AlignmentAnnotation("foo","foo desc",null); + assertTrue(aa.isShowGroupsForContactMatrix()); + aa.setShowGroupsForContactMatrix(false); + assertFalse(aa.isShowGroupsForContactMatrix()); + AlignmentAnnotation copy = new AlignmentAnnotation(aa); + assertFalse(copy.isShowGroupsForContactMatrix()); + aa.setShowGroupsForContactMatrix(true); + assertTrue(aa.isShowGroupsForContactMatrix()); + // copy should not be updated + assertFalse(copy.isShowGroupsForContactMatrix()); + + + } }