JAL-1824 updated caching procedure for pdb entries. Also refactored getPDBEntry metho...
[jalview.git] / src / jalview / gui / SeqPanel.java
index afd3242..e34a864 100644 (file)
  */
 package jalview.gui;
 
+import java.awt.BorderLayout;
+import java.awt.Color;
+import java.awt.Font;
+import java.awt.FontMetrics;
+import java.awt.Point;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.awt.event.MouseMotionListener;
+import java.awt.event.MouseWheelEvent;
+import java.awt.event.MouseWheelListener;
+import java.util.List;
+import java.util.Vector;
+
+import javax.swing.JOptionPane;
+import javax.swing.JPanel;
+import javax.swing.ToolTipManager;
+
 import jalview.api.AlignViewportI;
 import jalview.commands.EditCommand;
 import jalview.commands.EditCommand.Action;
@@ -43,23 +60,6 @@ import jalview.util.MappingUtils;
 import jalview.util.MessageManager;
 import jalview.viewmodel.AlignmentViewport;
 
-import java.awt.BorderLayout;
-import java.awt.Color;
-import java.awt.Font;
-import java.awt.FontMetrics;
-import java.awt.Point;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
-import java.awt.event.MouseMotionListener;
-import java.awt.event.MouseWheelEvent;
-import java.awt.event.MouseWheelListener;
-import java.util.List;
-import java.util.Vector;
-
-import javax.swing.JOptionPane;
-import javax.swing.JPanel;
-import javax.swing.ToolTipManager;
-
 /**
  * DOCUMENT ME!
  * 
@@ -167,6 +167,13 @@ public class SeqPanel extends JPanel implements MouseListener,
 
   int wrappedBlock = -1;
 
+  /**
+   * Returns the aligned sequence position (base 0) at the mouse position, or
+   * the closest visible one
+   * 
+   * @param evt
+   * @return
+   */
   int findRes(MouseEvent evt)
   {
     int res = 0;
@@ -203,13 +210,18 @@ public class SeqPanel extends JPanel implements MouseListener,
     }
     else
     {
-      if (x > seqCanvas.getWidth() + seqCanvas.getWidth())
+      if (x > seqCanvas.getX() + seqCanvas.getWidth())
       {
         // make sure we calculate relative to visible alignment, rather than
         // right-hand gutter
         x = seqCanvas.getX() + seqCanvas.getWidth();
       }
       res = (x / av.getCharWidth()) + av.getStartRes();
+      if (res > av.getEndRes())
+      {
+        // moused off right
+        res = av.getEndRes();
+      }
     }
 
     if (av.hasHiddenColumns())
@@ -647,8 +659,15 @@ public class SeqPanel extends JPanel implements MouseListener,
   @Override
   public void highlightSequence(SearchResults results)
   {
-    if (av.followHighlight)
+    if (av.isFollowHighlight())
     {
+      /*
+       * if scrollToPosition requires a scroll adjustment, this flag prevents
+       * another scroll event being propagated back to the originator
+       * 
+       * @see AlignmentPanel#adjustmentValueChanged
+       */
+      ap.setFollowingComplementScroll(true);
       if (ap.scrollToPosition(results, false))
       {
         seqCanvas.revalidate();