From 16f0c7f1954c5e59f98fbf2aace6eae3229ad152 Mon Sep 17 00:00:00 2001 From: gmungoc Date: Mon, 17 Aug 2015 12:06:22 +0100 Subject: [PATCH] JAL-1800 smarter matching when following mouseover of sequence --- src/jalview/gui/SeqPanel.java | 76 ++++++++++++++++++++++++++--------------- 1 file changed, 49 insertions(+), 27 deletions(-) diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index e34a864..41c3ce1 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -20,27 +20,11 @@ */ package jalview.gui; -import java.awt.BorderLayout; -import java.awt.Color; -import java.awt.Font; -import java.awt.FontMetrics; -import java.awt.Point; -import java.awt.event.MouseEvent; -import java.awt.event.MouseListener; -import java.awt.event.MouseMotionListener; -import java.awt.event.MouseWheelEvent; -import java.awt.event.MouseWheelListener; -import java.util.List; -import java.util.Vector; - -import javax.swing.JOptionPane; -import javax.swing.JPanel; -import javax.swing.ToolTipManager; - import jalview.api.AlignViewportI; import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; +import jalview.datamodel.AlignmentI; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SearchResults; import jalview.datamodel.SearchResults.Match; @@ -60,6 +44,23 @@ import jalview.util.MappingUtils; import jalview.util.MessageManager; import jalview.viewmodel.AlignmentViewport; +import java.awt.BorderLayout; +import java.awt.Color; +import java.awt.Font; +import java.awt.FontMetrics; +import java.awt.Point; +import java.awt.event.MouseEvent; +import java.awt.event.MouseListener; +import java.awt.event.MouseMotionListener; +import java.awt.event.MouseWheelEvent; +import java.awt.event.MouseWheelListener; +import java.util.List; +import java.util.Vector; + +import javax.swing.JOptionPane; +import javax.swing.JPanel; +import javax.swing.ToolTipManager; + /** * DOCUMENT ME! * @@ -128,6 +129,8 @@ public class SeqPanel extends JPanel implements MouseListener, StructureSelectionManager ssm; + SearchResults lastSearchResults; + /** * Creates a new SeqPanel object. * @@ -656,9 +659,20 @@ public class SeqPanel extends JPanel implements MouseListener, lastMessage = tmp; } + /** + * Highlight the mapped region described by the search results object (unless + * unchanged). This supports highlight of protein while mousing over linked + * cDNA and vice versa. The status bar is also updated to show the location of + * the start of the highlighted region. + */ @Override public void highlightSequence(SearchResults results) { + if (results == null || results.equals(lastSearchResults)) { + return; + } + lastSearchResults = results; + if (av.isFollowHighlight()) { /* @@ -868,19 +882,27 @@ public class SeqPanel extends JPanel implements MouseListener, */ private void setStatusMessage(SearchResults results) { - List matches = results.getResults(); - if (!matches.isEmpty()) + AlignmentI al = this.av.getAlignment(); + int sequenceIndex = al.findIndex(results); + if (sequenceIndex == -1) + { + return; + } + SequenceI ds = al.getSequenceAt(sequenceIndex).getDatasetSequence(); + for (Match m : results.getResults()) { - Match m = matches.get(0); SequenceI seq = m.getSequence(); - int sequenceIndex = this.av.getAlignment().findIndex(seq); - /* - * Convert position in sequence (base 1) to sequence character array index - * (base 0) - */ - int start = m.getStart() - 1; - setStatusMessage(seq, start, sequenceIndex); + if (seq == ds) + { + /* + * Convert position in sequence (base 1) to sequence character array + * index (base 0) + */ + int start = m.getStart() - 1; + setStatusMessage(seq, start, sequenceIndex); + return; + } } } -- 1.7.10.2