NPE fix
[jalview.git] / src / jalview / appletgui / SeqPanel.java
old mode 100755 (executable)
new mode 100644 (file)
index e6ed8f2..f961212
@@ -1,6 +1,6 @@
 /*
- * Jalview - A Sequence Alignment Editor and Viewer (Version 2.6)
- * Copyright (C) 2010 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7)
+ * Copyright (C) 2011 J Procter, AM Waterhouse, G Barton, M Clamp, S Searle
  * 
  * This file is part of Jalview.
  * 
@@ -91,7 +91,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
     seqCanvas.addMouseMotionListener(this);
     seqCanvas.addMouseListener(this);
-    ssm = StructureSelectionManager.getStructureSelectionManager();
+    ssm = StructureSelectionManager.getStructureSelectionManager(av.applet);
     ssm.addStructureViewerListener(this);
 
     seqCanvas.repaint();
@@ -458,7 +458,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     SequenceI sequence = av.alignment.getSequenceAt(findSeq(evt));
     if (evt.getClickCount() > 1)
     {
-      if (av.getSelectionGroup().getSize() == 1
+      if (av.getSelectionGroup()!=null && av.getSelectionGroup().getSize() == 1
               && av.getSelectionGroup().getEndRes()
                       - av.getSelectionGroup().getStartRes() < 2)
       {
@@ -639,11 +639,15 @@ public class SeqPanel extends Panel implements MouseMotionListener,
 
   public void highlightSequence(SearchResults results)
   {
-    seqCanvas.highlightSearchResults(results);
     if (av.followHighlight)
     {
-      ap.scrollToPosition(results);
+      if (ap.scrollToPosition(results, true))
+      {
+        ap.alignFrame.repaint();
+      }
     }
+    seqCanvas.highlightSearchResults(results);
+
   }
 
   public void updateColours(SequenceI seq, int index)
@@ -1683,6 +1687,7 @@ public class SeqPanel extends Panel implements MouseMotionListener,
       }
     }
   }
+
   /**
    * modify current selection according to a received message.
    */
@@ -1693,9 +1698,8 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     // handles selection messages...
     // TODO: extend config options to allow user to control if selections may be
     // shared between viewports.
-    if (av!=null && (av == source
-            || !av.followSelection
-            || (source instanceof AlignViewport && ((AlignViewport) source)
+    if (av != null
+            && (av == source || !av.followSelection || (source instanceof AlignViewport && ((AlignViewport) source)
                     .getSequenceSetId().equals(av.getSequenceSetId()))))
     {
       return;
@@ -1708,13 +1712,15 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     if (av.selectionGroup == null || !av.isSelectionGroupChanged())
     {
       SequenceGroup sgroup = null;
-      if (seqsel != null)
+      if (seqsel != null && seqsel.getSize()>0)
       {
         if (av.alignment == null)
         {
-          System.out.println("Selection message: alignviewport av SeqSetId="
-                  + av.getSequenceSetId() + " ViewId=" + av.getViewId()
-                  + " 's alignment is NULL! returning immediatly.");
+          System.out
+                  .println("Selection message: alignviewport av SeqSetId="
+                          + av.getSequenceSetId() + " ViewId="
+                          + av.getViewId()
+                          + " 's alignment is NULL! returning immediatly.");
           return;
         }
         sgroup = seqsel.intersect(av.alignment,
@@ -1768,10 +1774,42 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
     if (repaint)
     {
-      // probably finessing with multiple redraws here
-      PaintRefresher.Refresh(this, av.getSequenceSetId());
-      // ap.paintAlignment(false);
+      ap.scalePanelHolder.repaint();
+      ap.repaint();
     }
   }
 
+  /**
+   * scroll to the given row/column - or nearest visible location
+   * @param row
+   * @param column
+   */
+  public void scrollTo(int row, int column)
+  {
+    
+    row = row<0 ? ap.av.startSeq : row;
+    column = column<0 ? ap.av.startRes : column;
+    ap.scrollTo(row, row, column, true, true);
+  }
+  /**
+   * scroll to the given row - or nearest visible location
+   * @param row
+   */
+  public void scrollToRow(int row)
+  {
+    
+    row = row<0 ? ap.av.startSeq : row;
+    ap.scrollTo(row, row, ap.av.startRes, true, true);
+  }
+  /**
+   * scroll to the given column - or nearest visible location
+   * @param column
+   */
+  public void scrollToColumn(int column)
+  {
+    
+    column = column<0 ? ap.av.startRes : column;
+    ap.scrollTo(ap.av.startRes, ap.av.startRes, column, true, true);
+  }
+
 }