selection sending and receiving, autoscrolling to highlighted position
[jalview.git] / src / jalview / gui / SeqPanel.java
index 63a57f8..939ba45 100755 (executable)
@@ -36,7 +36,7 @@ import jalview.structure.*;
  * @version $Revision$
  */
 public class SeqPanel extends JPanel implements MouseListener,
-        MouseMotionListener, MouseWheelListener, SequenceListener
+        MouseMotionListener, MouseWheelListener, SequenceListener, SelectionListener
 
 {
   /** DOCUMENT ME!! */
@@ -124,6 +124,7 @@ public class SeqPanel extends JPanel implements MouseListener,
       addMouseWheelListener(this);
       ssm = StructureSelectionManager.getStructureSelectionManager();
       ssm.addStructureViewerListener(this);
+      ssm.addSelectionListener(this);
     }
   }
 
@@ -455,6 +456,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     }
 
     ap.paintAlignment(false);
+    av.sendSelection();
   }
 
   void insertGapAtCursor(boolean group)
@@ -605,6 +607,10 @@ public class SeqPanel extends JPanel implements MouseListener,
 
   public void highlightSequence(SearchResults results)
   {
+    if (av.followHighlight)
+    {
+      ap.scrollToPosition(results, false);
+    }
     seqCanvas.highlightSearchResults(results);
   }
 
@@ -1531,6 +1537,7 @@ public class SeqPanel extends JPanel implements MouseListener,
       sg.setEndRes(res);
       sg.addSequence(sequence, false);
       av.setSelectionGroup(sg);
+      
       stretchGroup = sg;
 
       if (av.getConservationSelected())
@@ -1608,7 +1615,7 @@ public class SeqPanel extends JPanel implements MouseListener,
     changeEndRes = false;
     changeStartRes = false;
     stretchGroup = null;
-
+    av.sendSelection();
   }
 
   /**
@@ -1808,4 +1815,50 @@ public class SeqPanel extends JPanel implements MouseListener,
       }
     }
   }
+  /**
+   * 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);
+    }
+  }
 }