import java.awt.Rectangle;
import java.util.ArrayList;
import java.util.Hashtable;
-import java.util.List;
import java.util.Set;
import java.util.Vector;
import jalview.datamodel.Alignment;
import jalview.datamodel.AlignmentI;
import jalview.datamodel.ColumnSelection;
-import jalview.datamodel.HiddenSequences;
import jalview.datamodel.PDBEntry;
import jalview.datamodel.SearchResults;
import jalview.datamodel.Sequence;
import jalview.structure.SelectionSource;
import jalview.structure.StructureSelectionManager;
import jalview.structure.VamsasSource;
-import jalview.util.Comparison;
-import jalview.util.MappingUtils;
import jalview.util.MessageManager;
import jalview.viewmodel.AlignmentViewport;
import jalview.ws.params.AutoCalcSetting;
public class AlignViewport extends AlignmentViewport implements
SelectionSource, AlignViewportI, CommandListener
{
- int startRes;
-
- int endRes;
-
- int startSeq;
-
- int endSeq;
-
Font font;
NJTree currentTree = null;
return sq;
}
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getStartRes()
- {
- return startRes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEndRes()
- {
- return endRes;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getStartSeq()
- {
- return startSeq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param res
- * DOCUMENT ME!
- */
- public void setStartRes(int res)
- {
- this.startRes = res;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param seq
- * DOCUMENT ME!
- */
- public void setStartSeq(int seq)
- {
- this.startSeq = seq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param res
- * DOCUMENT ME!
- */
- public void setEndRes(int res)
- {
- if (res > (alignment.getWidth() - 1))
- {
- // log.System.out.println(" Corrected res from " + res + " to maximum " +
- // (alignment.getWidth()-1));
- res = alignment.getWidth() - 1;
- }
-
- if (res < 0)
- {
- res = 0;
- }
-
- this.endRes = res;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @param seq
- * DOCUMENT ME!
- */
- public void setEndSeq(int seq)
- {
- if (seq > alignment.getHeight())
- {
- seq = alignment.getHeight();
- }
-
- if (seq < 0)
- {
- seq = 0;
- }
-
- this.endSeq = seq;
- }
-
- /**
- * DOCUMENT ME!
- *
- * @return DOCUMENT ME!
- */
- public int getEndSeq()
- {
- return endSeq;
- }
-
boolean validCharWidth;
/**
return false;
}
- /**
- * when set, view will scroll to show the highlighted position
- */
- public boolean followHighlight = true;
-
- /**
- * @return true if view should scroll to show the highlighted region of a
- * sequence
- * @return
- */
- public boolean getFollowHighlight()
- {
- return followHighlight;
- }
-
public boolean followSelection = true;
/**
/**
* If this viewport has a (Protein/cDNA) complement, then scroll the
* complementary alignment to match this one.
- *
- * @param horizontal
- * true for horizontal scroll event, false for vertical
*/
- public void scrollComplementaryAlignment(boolean horizontal)
+ public void scrollComplementaryAlignment()
{
/*
- * If no complement, or it is not following scrolling, do nothing.
+ * Populate a SearchResults object with the mapped location to scroll to. If
+ * there is no complement, or it is not following highlights, or no mapping
+ * is found, the result will be empty.
*/
- // TODO pull up followHighlight to AlignmentViewport/AlignViewportI
- final AlignViewport codingComplement = (AlignViewport) getCodingComplement();
- if (codingComplement == null || !codingComplement.followHighlight)
- {
- return;
- }
- boolean iAmProtein = !getAlignment().isNucleotide();
- AlignmentI proteinAlignment = iAmProtein ? getAlignment()
- : codingComplement.getAlignment();
- if (proteinAlignment == null)
+ SearchResults sr = new SearchResults();
+ int seqOffset = findComplementScrollTarget(sr);
+ if (!sr.isEmpty())
{
- return;
- }
- final Set<AlignedCodonFrame> mappings = proteinAlignment
- .getCodonFrames();
-
- /*
- * Heuristic: find the first mapped sequence (if any) with a non-gapped
- * residue in the middle column of the visible region. Scroll the
- * complementary alignment to line up the corresponding residue.
- */
- int seqOffset = 0;
- SequenceI sequence = null;
- int middleColumn = getStartRes() + (getEndRes() - getStartRes()) / 2;
- final HiddenSequences hiddenSequences = getAlignment()
- .getHiddenSequences();
- for (int seqNo = getStartSeq(); seqNo < getEndSeq(); seqNo++, seqOffset++)
- {
- sequence = getAlignment().getSequenceAt(seqNo);
- if (hiddenSequences != null && hiddenSequences.isHidden(sequence))
- {
- continue;
- }
- if (Comparison.isGap(sequence.getCharAt(middleColumn)))
- {
- continue;
- }
- List<AlignedCodonFrame> seqMappings = MappingUtils
- .findMappingsForSequence(sequence, mappings);
- if (!seqMappings.isEmpty())
- {
- break;
- }
- }
-
- if (sequence == null)
- {
- /*
- * No ungapped mapped sequence in middle column - do nothing
- */
- return;
+ // TODO would like next line without cast but needs more refactoring...
+ final AlignmentPanel complementPanel = ((AlignViewport) getCodingComplement()).getAlignPanel();
+ complementPanel.setFollowingComplementScroll(true);
+ complementPanel.scrollToCentre(sr, seqOffset);
}
- SearchResults sr = MappingUtils.buildSearchResults(sequence,
- sequence.findPosition(middleColumn), mappings);
- codingComplement.getAlignPanel().scrollAsComplement(sr, seqOffset,
- horizontal);
}
}