/*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8.2)
- * Copyright (C) 2014 The Jalview Authors
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* This file is part of Jalview.
*
*/
package jalview.appletgui;
+import java.awt.BorderLayout;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Panel;
+import java.awt.Point;
+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;
+
import jalview.api.AlignViewportI;
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;
import jalview.util.MappingUtils;
import jalview.util.MessageManager;
-import java.awt.BorderLayout;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Panel;
-import java.awt.Point;
-import java.awt.event.InputEvent;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.util.Vector;
-
public class SeqPanel extends Panel implements MouseMotionListener,
MouseListener, SequenceListener, SelectionListener
{
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<Match> 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)
ap.alignFrame.repaint();
}
}
+ setStatusMessage(results);
seqCanvas.highlightSearchResults(results);
}
}
else
{
- obj = "X".equalsIgnoreCase(ch) ? "STOP"
+ obj = "X".equalsIgnoreCase(ch) ? "X"
: ResidueProperties.aa2Triplet.get(ch);
if (obj != null)
{
SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
sequence.findPosition(res));
- Vector links = null;
+ Vector<String> links = null;
if (allFeatures != null)
{
for (int i = 0; i < allFeatures.length; i++)
{
if (links == null)
{
- links = new Vector();
+ links = new Vector<String>();
}
for (int j = 0; j < allFeatures[i].links.size(); j++)
{
av.setColumnSelection(cs);
av.isColSelChanged(true);
- firePropertyChange("alignment", null, av.getAlignment().getSequences());
- // PaintRefresher.Refresh(this, av.getSequenceSetId());
+ ap.scalePanelHolder.repaint();
+ ap.repaint();
return true;
}