From: gmungoc Date: Fri, 20 Feb 2015 11:51:56 +0000 (+0000) Subject: JAL-1674 update both status bars when mousing over linked sequences X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=373a0f23b37fdd3c40d3ebb4a3c9120f5773bb45;p=jalview.git JAL-1674 update both status bars when mousing over linked sequences --- diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index bea86b2..8a526ac 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -25,6 +25,7 @@ import jalview.commands.EditCommand; import jalview.commands.EditCommand.Action; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SearchResults; +import jalview.datamodel.SearchResults.Match; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -47,6 +48,7 @@ import java.awt.event.InputEvent; import java.awt.event.MouseEvent; import java.awt.event.MouseListener; import java.awt.event.MouseMotionListener; +import java.util.List; import java.util.Vector; public class SeqPanel extends Panel implements MouseMotionListener, @@ -396,41 +398,107 @@ public class SeqPanel extends Panel implements MouseMotionListener, return 1; } + /** + * Set status message in alignment panel + * + * @param sequence + * aligned sequence object + * @param res + * alignment column + * @param seq + * index of sequence in alignment + * @return position of res in sequence + */ void setStatusMessage(SequenceI sequence, int res, int seq) { - StringBuffer text = new StringBuffer("Sequence " + (seq + 1) + " ID: " - + sequence.getName()); + // TODO remove duplication of identical gui method + StringBuilder text = new StringBuilder(32); + String seqno = seq == -1 ? "" : " " + (seq + 1); + text.append("Sequence" + seqno + " ID: " + sequence.getName()); - Object obj = null; + String residue = null; + /* + * Try to translate the display character to residue name (null for gap). + */ + final String displayChar = String.valueOf(sequence.getCharAt(res)); if (av.getAlignment().isNucleotide()) { - obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) - + ""); - if (obj != null) + residue = ResidueProperties.nucleotideName.get(displayChar); + if (residue != null) { - text.append(" Nucleotide: "); + text.append(" Nucleotide: ").append(residue); } } else { - obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); - if (obj != null) - { - text.append(" Residue: "); - } - } + residue = "X".equalsIgnoreCase(displayChar) ? "X" + : ResidueProperties.aa2Triplet.get(displayChar); + if (residue != null) + { + text.append(" Residue: ").append(residue); + } + } + + int pos = -1; + if (residue != null) + { + pos = sequence.findPosition(res); + text.append(" (").append(Integer.toString(pos)).append(")"); + } + // Object obj = null; + // if (av.getAlignment().isNucleotide()) + // { + // obj = ResidueProperties.nucleotideName.get(sequence.getCharAt(res) + // + ""); + // if (obj != null) + // { + // text.append(" Nucleotide: "); + // } + // } + // else + // { + // obj = ResidueProperties.aa2Triplet.get(sequence.getCharAt(res) + ""); + // if (obj != null) + // { + // text.append(" Residue: "); + // } + // } + // + // if (obj != null) + // { + // + // if (obj != "") + // { + // text.append(obj + " (" + sequence.findPosition(res) + ")"); + // } + // } - if (obj != null) - { + ap.alignFrame.statusBar.setText(text.toString()); - if (obj != "") - { - text.append(obj + " (" + sequence.findPosition(res) + ")"); - } - } + } - ap.alignFrame.statusBar.setText(text.toString()); + /** + * Set the status bar message to highlight the first matched position in + * search results. + * + * @param results + */ + private void setStatusMessage(SearchResults results) + { + List matches = results.getResults(); + if (!matches.isEmpty()) + { + 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); + } } public void mousePressed(MouseEvent evt) @@ -681,6 +749,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, ap.alignFrame.repaint(); } } + setStatusMessage(results); seqCanvas.highlightSearchResults(results); } @@ -743,7 +812,7 @@ public class SeqPanel extends Panel implements MouseMotionListener, } else { - obj = "X".equalsIgnoreCase(ch) ? "STOP" + obj = "X".equalsIgnoreCase(ch) ? "X" : ResidueProperties.aa2Triplet.get(ch); if (obj != null) { diff --git a/src/jalview/gui/SeqPanel.java b/src/jalview/gui/SeqPanel.java index a7e4057..0c24e2e 100644 --- a/src/jalview/gui/SeqPanel.java +++ b/src/jalview/gui/SeqPanel.java @@ -26,6 +26,7 @@ import jalview.commands.EditCommand.Action; import jalview.commands.EditCommand.Edit; import jalview.datamodel.ColumnSelection; import jalview.datamodel.SearchResults; +import jalview.datamodel.SearchResults.Match; import jalview.datamodel.Sequence; import jalview.datamodel.SequenceFeature; import jalview.datamodel.SequenceGroup; @@ -653,6 +654,7 @@ public class SeqPanel extends JPanel implements MouseListener, seqCanvas.revalidate(); } } + setStatusMessage(results); seqCanvas.highlightSearchResults(results); } @@ -798,9 +800,13 @@ public class SeqPanel extends JPanel implements MouseListener, */ int setStatusMessage(SequenceI sequence, int res, int seq) { - int pos = -1; StringBuilder text = new StringBuilder(32); - text.append("Sequence " + (seq + 1) + " ID: " + sequence.getName()); + + /* + * Sequence number (if known), and sequence name. + */ + String seqno = seq == -1 ? "" : " " + (seq + 1); + text.append("Sequence" + seqno + " ID: " + sequence.getName()); String residue = null; /* @@ -817,7 +823,7 @@ public class SeqPanel extends JPanel implements MouseListener, } else { - residue = "X".equalsIgnoreCase(displayChar) ? "STOP" + residue = "X".equalsIgnoreCase(displayChar) ? "X" : ResidueProperties.aa2Triplet.get(displayChar); if (residue != null) { @@ -825,6 +831,7 @@ public class SeqPanel extends JPanel implements MouseListener, } } + int pos = -1; if (residue != null) { pos = sequence.findPosition(res); @@ -835,6 +842,30 @@ public class SeqPanel extends JPanel implements MouseListener, } /** + * Set the status bar message to highlight the first matched position in + * search results. + * + * @param results + */ + private void setStatusMessage(SearchResults results) + { + List matches = results.getResults(); + if (!matches.isEmpty()) + { + 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); + } + } + + /** * DOCUMENT ME! * * @param evt