From: Jim Procter Date: Mon, 17 Oct 2022 16:56:51 +0000 (+0100) Subject: JAL-2349 JAL-3855 column selection highlighting X-Git-Tag: Release_2_11_3_0~23^2~39 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=47a6e772d30202cfb73fe296fea6c8474bc2b8bb;p=jalview.git JAL-2349 JAL-3855 column selection highlighting --- diff --git a/src/jalview/datamodel/ColumnSelection.java b/src/jalview/datamodel/ColumnSelection.java index 6f14e21..140a366 100644 --- a/src/jalview/datamodel/ColumnSelection.java +++ b/src/jalview/datamodel/ColumnSelection.java @@ -20,15 +20,15 @@ */ package jalview.datamodel; -import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; -import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; - import java.util.ArrayList; import java.util.BitSet; import java.util.Collections; import java.util.List; import java.util.regex.PatternSyntaxException; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter; +import jalview.viewmodel.annotationfilter.AnnotationFilterParameter.SearchableAnnotationField; + /** * Data class holding the selected columns and hidden column ranges for a view. * Ranges are base 1. @@ -354,6 +354,22 @@ public class ColumnSelection } /** + * + */ + public boolean intersects(int from, int to) + { + // TODO: do this in a more efficient bitwise way + for (int f = from; f <= to; f++) + { + if (selection.isSelected(f)) + { + return true; + } + } + return false; + } + + /** * Answers true if no columns are selected, else false */ public boolean isEmpty() diff --git a/src/jalview/renderer/ContactMapRenderer.java b/src/jalview/renderer/ContactMapRenderer.java index 11c51e9..f5c4c31 100644 --- a/src/jalview/renderer/ContactMapRenderer.java +++ b/src/jalview/renderer/ContactMapRenderer.java @@ -50,12 +50,12 @@ public class ContactMapRenderer implements AnnotationRowRendererI { column = hiddenColumns.visibleToAbsoluteColumn(column); } - // // TODO: highlight columns selected - // boolean colsel = false; - // if (columnSelection != null) - // { - // colsel = columnSelection.contains(column); - // } + // TODO: highlight columns selected + boolean colsel = false; + if (columnSelection != null) + { + colsel = columnSelection.contains(column); + } if (column > aaMax) { @@ -107,16 +107,36 @@ public class ContactMapRenderer implements AnnotationRowRendererI // TODO show maximum colour for range - sort of done // also need a 'getMaxPosForRange(start,end)' to accurately render - Color col = getColorForRange(min, max, contacts, cstart, cend); - + Color col; + boolean rowsel = false; + if (!colsel && columnSelection != null) + { + if (_aa.sequenceRef == null) + { + rowsel = columnSelection.intersects(cstart, cend); + } + else + { + // TODO check we have correctly mapped cstart to local sequence + // numbering + int s = _aa.sequenceRef.findIndex(cstart); + int e = _aa.sequenceRef.findIndex(cend); + if (s > 0 && s < _aa.sequenceRef.getLength()) + { + rowsel = columnSelection.intersects(s, e); + } + } + } // TODO: show selected region - // if (colsel || columnSelection!=null && - // columnSelection.intersects(cstart,cend)) - // { - // g.setColor(col.brighter()); - // } - // else + if (colsel || rowsel) { + + col = getSelectedColorForRange(min, max, contacts, cstart, cend); + g.setColor(col); + } + else + { + col = getColorForRange(min, max, contacts, cstart, cend); g.setColor(col); } if (pixels_step > 1) @@ -134,7 +154,8 @@ public class ContactMapRenderer implements AnnotationRowRendererI } // Shading parameters - Color minColor = Color.white, maxColor = Color.magenta; + Color minColor = Color.white, maxColor = Color.green.darker().darker(), + selMaxColor = Color.magenta.darker(); Color shadeFor(float min, float max, float value) { @@ -150,4 +171,13 @@ public class ContactMapRenderer implements AnnotationRowRendererI return shadeFor(min, max, (float) cr.getMean()); } + public Color getSelectedColorForRange(float min, float max, + ContactListI cl, int i, int j) + { + ContactRange cr = cl.getRangeFor(i, j); + // average for moment - probably more interested in maxIntProj though + return jalview.util.ColorUtils.getGraduatedColour((float) cr.getMean(), + 0, minColor, max, selMaxColor); + } + }