From: gmungoc Date: Tue, 23 May 2017 11:55:08 +0000 (+0100) Subject: JAL-2547 don't show features in tooltip over a gap X-Git-Tag: Release_2_10_2~3^2~65^2 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=refs%2Fheads%2Fbug%2FJAL-2547tooltipOnGap;p=jalview.git JAL-2547 don't show features in tooltip over a gap --- diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index d46cc34..b89c435 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -39,6 +39,7 @@ import jalview.structure.SelectionSource; import jalview.structure.SequenceListener; import jalview.structure.StructureSelectionManager; import jalview.structure.VamsasSource; +import jalview.util.Comparison; import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; @@ -772,10 +773,10 @@ public class SeqPanel extends Panel implements MouseMotionListener, @Override public void mouseMoved(MouseEvent evt) { - int res = findRes(evt); + final int column = findRes(evt); int seq = findSeq(evt); - if (seq >= av.getAlignment().getHeight() || seq < 0 || res < 0) + if (seq >= av.getAlignment().getHeight() || seq < 0 || column < 0) { if (tooltip != null) { @@ -785,7 +786,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } SequenceI sequence = av.getAlignment().getSequenceAt(seq); - if (res > sequence.getLength()) + if (column > sequence.getLength()) { if (tooltip != null) { @@ -794,10 +795,12 @@ public class SeqPanel extends Panel implements MouseMotionListener, return; } - int respos = sequence.findPosition(res); - if (ssm != null) + final char ch = sequence.getCharAt(column); + int respos = Comparison.isGap(ch) ? -1 : sequence.findPosition(column); + + if (ssm != null && respos != -1) { - mouseOverSequence(sequence, res, respos); + mouseOverSequence(sequence, column, respos); } StringBuilder text = new StringBuilder(); @@ -805,30 +808,31 @@ public class SeqPanel extends Panel implements MouseMotionListener, .append(" ID: ").append(sequence.getName()); String obj = null; - final String ch = String.valueOf(sequence.getCharAt(res)); - if (av.getAlignment().isNucleotide()) + if (respos != -1) { - obj = ResidueProperties.nucleotideName.get(ch); - if (obj != null) + if (av.getAlignment().isNucleotide()) { - text.append(" Nucleotide: ").append(obj); + obj = ResidueProperties.nucleotideName.get(ch); + if (obj != null) + { + text.append(" Nucleotide: ").append(obj); + } + } + else + { + obj = (ch == 'x' || ch == 'X') ? "X" : ResidueProperties.aa2Triplet + .get(String.valueOf(ch)); + if (obj != null) + { + text.append(" Residue: ").append(obj); + } } - } - else - { - obj = "X".equalsIgnoreCase(ch) ? "X" : ResidueProperties.aa2Triplet - .get(ch); if (obj != null) { - text.append(" Residue: ").append(obj); + text.append(" (").append(Integer.toString(respos)).append(")"); } } - if (obj != null) - { - text.append(" (").append(Integer.toString(respos)).append(")"); - } - ap.alignFrame.statusBar.setText(text.toString()); StringBuilder tooltipText = new StringBuilder(); @@ -837,7 +841,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, { for (int g = 0; g < groups.length; g++) { - if (groups[g].getStartRes() <= res && groups[g].getEndRes() >= res) + if (groups[g].getStartRes() <= column && groups[g].getEndRes() >= column) { if (!groups[g].getName().startsWith("JTreeGroup") && !groups[g].getName().startsWith("JGroup")) @@ -853,33 +857,38 @@ public class SeqPanel extends Panel implements MouseMotionListener, } } - // use aa to see if the mouse pointer is on a - SequenceFeature[] allFeatures = findFeaturesAtRes(sequence, - sequence.findPosition(res)); - - int index = 0; - while (index < allFeatures.length) + /* + * add feature details to tooltip if over one or more features + */ + if (respos != -1) { - SequenceFeature sf = allFeatures[index]; - - tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end); + SequenceFeature[] allFeatures = findFeaturesAtRes(sequence, + sequence.findPosition(column)); - if (sf.getDescription() != null) + int index = 0; + while (index < allFeatures.length) { - tooltipText.append(" " + sf.getDescription()); - } + SequenceFeature sf = allFeatures[index]; - if (sf.getValue("status") != null) - { - String status = sf.getValue("status").toString(); - if (status.length() > 0) + tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end); + + if (sf.getDescription() != null) { - tooltipText.append(" (" + sf.getValue("status") + ")"); + tooltipText.append(" " + sf.getDescription()); } - } - tooltipText.append("\n"); - index++; + if (sf.getValue("status") != null) + { + String status = sf.getValue("status").toString(); + if (status.length() > 0) + { + tooltipText.append(" (" + sf.getValue("status") + ")"); + } + } + tooltipText.append("\n"); + + index++; + } } if (tooltip == null) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index 7dfac5e..2884c50 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -788,7 +788,7 @@ public class SeqPanel extends JPanel implements MouseListener, } } - if (av.isShowSequenceFeatures()) + if (av.isShowSequenceFeatures() && pos != -1) { List features = ap.getFeatureRenderer() .findFeaturesAtRes(sequence.getDatasetSequence(), pos); @@ -861,7 +861,8 @@ public class SeqPanel extends JPanel implements MouseListener, /** * Sets the status message in alignment panel, showing the sequence number * (index) and id, residue and residue position for the given sequence and - * column position. Returns the calculated residue position in the sequence. + * column position. Returns the calculated residue position in the sequence, + * or -1 for a gapped column position. * * @param sequence * aligned sequence object @@ -907,9 +908,9 @@ public class SeqPanel extends JPanel implements MouseListener, } int pos = -1; - pos = sequence.findPosition(column); if (residue != null) { + pos = sequence.findPosition(column); text.append(" (").append(Integer.toString(pos)).append(")"); } ap.alignFrame.statusBar.setText(text.toString());