import jalview.datamodel.*;
import jalview.jbgui.*;
import jalview.schemes.*;
+import jalview.structure.SelectionSource;
/**
* DOCUMENT ME!
}
}
});
-
fontChanged();
adjustAnnotationHeight();
*/
public void highlightSearchResults(SearchResults results)
{
+ scrollToPosition(results);
seqPanel.seqCanvas.highlightSearchResults(results);
-
+ }
+ /**
+ * scroll the view to show the position of the highlighted
+ * region in results (if any) and redraw the overview
+ * @param results
+ */
+ public boolean scrollToPosition(SearchResults results) {
+ return scrollToPosition(results, true);
+ }
+ /**
+ * scroll the view to show the position of the highlighted
+ * region in results (if any)
+ * @param results
+ * @param redrawOverview - when set, the overview will be recalculated (takes longer)
+ * @return false if results were not found
+ */
+ public boolean scrollToPosition(SearchResults results, boolean redrawOverview) {
+ // TODO: properly locate search results in view when large numbers of hidden columns exist before highlighted region
// do we need to scroll the panel?
- if (results != null)
+ if (results != null && results.getSize()>0)
{
- SequenceI seq = results.getResultSequence(0);
- int seqIndex = av.alignment.findIndex(seq);
- int start = seq.findIndex(results.getResultStart(0)) - 1;
- int end = seq.findIndex(results.getResultEnd(0)) - 1;
-
+ int seqIndex = av.alignment.findIndex(results);
+ if (seqIndex==-1)
+ {
+ return false;
+ }
+ SequenceI seq = av.alignment.getSequenceAt(seqIndex);
+
+ int [] r = results.getResults(seq, seq.getStart(), seq.getEnd());
+ if (r==null)
+ {
+ return false;
+ }
+ int start = r[0];
+ int end = r[1];
+ if (start<0)
+ {
+ return false;
+ }
+ if (end==seq.getEnd())
+ {
+ return false;
+ }
if (!av.wrapAlignment)
{
- if ((av.getStartRes() > end)
- || (av.getEndRes() < start)
- || ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex)))
+ if ((av.getStartRes() >= start)
+ || (av.getEndRes() <= end))
{
- setScrollValues(start, seqIndex);
+ setScrollValues(start-1, seqIndex);
+ } else if ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))
+ {
+ setScrollValues(av.getStartRes(), seqIndex);
}
}
else
scrollToWrappedVisible(start);
}
}
-
- paintAlignment(true);
+ if (!redrawOverview && overviewPanel!=null)
+ {
+ overviewPanel.setBoxPosition();
+ }
+ paintAlignment(!redrawOverview);
+ return true;
}
void scrollToWrappedVisible(int res)
{
int cwidth = seqPanel.seqCanvas
.getWrappedCanvasWidth(seqPanel.seqCanvas.getWidth());
- if (res <= av.getStartRes() || res >= (av.getStartRes() + cwidth))
+ if (res < av.getStartRes() || res >= (av.getStartRes()+cwidth))
{
- vscroll.setValue(res / cwidth);
+ vscroll.setValue((res / cwidth));
av.startRes = vscroll.getValue() * cwidth;
}
+
}
/**
*/
public void setScrollValues(int x, int y)
{
-
+ if (av==null || av.alignment==null)
+ {
+ return;
+ }
int width = av.alignment.getWidth();
int height = av.alignment.getHeight();