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 void scrollToPosition(SearchResults results) {
+ 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)
+ */
+ public void scrollToPosition(SearchResults results, boolean redrawOverview) {
// 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;
+ }
+ SequenceI seq = av.alignment.getSequenceAt(seqIndex);
+ int [] r = results.getResults(seq, seq.getStart(), seq.getEnd());
+ if (r==null)
+ {
+ return;
+ }
+ int start = r[0];
+ int end = r[1];
+ if (start<0)
+ {
+ return;
+ }
+ if (end==seq.getEnd())
+ {
+ return;
+ }
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-1, seqIndex);
+ } else if ((av.getStartSeq() > seqIndex) || (av.getEndSeq() < seqIndex))
{
- setScrollValues(start, seqIndex);
+ setScrollValues(av.getStartRes(), seqIndex);
}
}
else
scrollToWrappedVisible(start);
}
}
-
- paintAlignment(true);
+ if (!redrawOverview && overviewPanel!=null)
+ {
+ overviewPanel.setBoxPosition();
+ }
+ paintAlignment(!redrawOverview);
}
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();
* @version $Revision$
*/
public class SeqPanel extends JPanel implements MouseListener,
- MouseMotionListener, MouseWheelListener, SequenceListener
+ MouseMotionListener, MouseWheelListener, SequenceListener, SelectionListener
{
/** DOCUMENT ME!! */
addMouseWheelListener(this);
ssm = StructureSelectionManager.getStructureSelectionManager();
ssm.addStructureViewerListener(this);
+ ssm.addSelectionListener(this);
}
}
}
ap.paintAlignment(false);
+ av.sendSelection();
}
void insertGapAtCursor(boolean group)
public void highlightSequence(SearchResults results)
{
+ if (av.followHighlight)
+ {
+ ap.scrollToPosition(results, false);
+ }
seqCanvas.highlightSearchResults(results);
}
sg.setEndRes(res);
sg.addSequence(sequence, false);
av.setSelectionGroup(sg);
+
stretchGroup = sg;
if (av.getConservationSelected())
changeEndRes = false;
changeStartRes = false;
stretchGroup = null;
-
+ av.sendSelection();
}
/**
}
}
}
+ /**
+ * modify current selection according to a received message.
+ */
+ public void selection(SequenceGroup seqsel, ColumnSelection colsel,
+ SelectionSource source)
+ {
+ // TODO: fix this hack - source of messages is align viewport, but SeqPanel handles selection messages...
+ if (av==source)
+ {
+ return;
+ }
+ // do we want to thread this ? (contention with seqsel and colsel locks, I suspect)
+ boolean repaint=false;
+ if (av.followSelection)
+ {
+ if (av.selectionGroup==null || !av.isSelectionGroupChanged())
+ {
+ SequenceGroup sgroup = (seqsel!=null) ? seqsel.intersect(av.alignment, (av.hasHiddenRows) ? av.hiddenRepSequences : null)
+ : null;
+ if (sgroup!=null && sgroup.getSize()>0)
+ {
+ av.setSelectionGroup(sgroup);
+ } else {
+ av.setSelectionGroup(null);
+ }
+ repaint = av.isSelectionGroupChanged();
+ }
+ if (av.colSel==null || !av.isColSelChanged())
+ {
+ // Check to see if the current selection is from a previous message
+ if (colsel==null || colsel.size()==0)
+ {
+ av.colSel.clear();
+ } else {
+ av.colSel = new ColumnSelection(colsel);
+ }
+ repaint |= av.isColSelChanged();
+ }
+ }
+ if (repaint)
+ {
+ // probably finessing with multiple redraws here
+ PaintRefresher.Refresh(this, av.getSequenceSetId());
+ // ap.paintAlignment(false);
+ }
+ }
}