check that mouse is over sequence if unaligned
authoramwaterhouse <Andrew Waterhouse>
Thu, 10 Feb 2005 13:23:09 +0000 (13:23 +0000)
committeramwaterhouse <Andrew Waterhouse>
Thu, 10 Feb 2005 13:23:09 +0000 (13:23 +0000)
src/jalview/gui/SeqPanel.java

index 83dceef..35c5aef 100755 (executable)
@@ -170,6 +170,9 @@ public class SeqPanel extends JPanel
       return;\r
 \r
     SequenceI sequence = av.getAlignment().getSequenceAt(seq);\r
+    if(res>sequence.getLength())\r
+      return;\r
+\r
     Object obj = ResidueProperties.aa2Triplet.get( sequence.getCharAt(res)+"" ) ;\r
     String aa = "";\r
     if(obj!=null)\r
@@ -181,7 +184,8 @@ public class SeqPanel extends JPanel
 \r
     ap.alignFrame.statusBar.setText(text.toString());\r
 \r
-    if(av.showSequenceFeatures)\r
+    // use aa to see if the mouse pointer is on a\r
+    if(  av.showSequenceFeatures)\r
     {\r
       Vector features = sequence.getSequenceFeatures();\r
       Enumeration e = features.elements();\r
@@ -213,6 +217,9 @@ public class SeqPanel extends JPanel
   public void doMouseDragged(MouseEvent evt) {\r
     // If we're dragging we're editing\r
 \r
+    if(lastres==-1)\r
+      return;\r
+\r
     int x = evt.getX();\r
 \r
     int res = x/av.getCharWidth() + av.getStartRes();\r
@@ -361,24 +368,25 @@ public class SeqPanel extends JPanel
     int seq = evt.getY()/av.getCharHeight() + av.getStartSeq();\r
     oldSeq = seq;\r
 \r
+    SequenceI sequence = (Sequence) av.getAlignment().getSequenceAt(seq);\r
+    if(res>sequence.getLength())\r
+      return;\r
+\r
     stretchGroup = av.getRubberbandGroup();\r
 \r
     if(stretchGroup == null)\r
      {\r
-       stretchGroup = av.alignment.findGroup( (Sequence) av.getAlignment().\r
-                                             getSequenceAt(seq));\r
+       stretchGroup = av.alignment.findGroup( sequence );\r
        av.setRubberbandGroup( stretchGroup );\r
      }\r
 \r
-    else if(!stretchGroup.sequences.contains((Sequence)av.getAlignment().getSequenceAt(seq))\r
+    else if(!stretchGroup.sequences.contains(sequence)\r
             || stretchGroup.getStartRes()>res\r
             || stretchGroup.getEndRes()<res)\r
      {\r
        stretchGroup = null;\r
 \r
-       SequenceGroup[] allGroups = av.alignment.findAllGroups( (Sequence) av.\r
-           getAlignment().\r
-           getSequenceAt(seq));\r
+       SequenceGroup[] allGroups = av.alignment.findAllGroups( sequence );\r
 \r
        if (allGroups != null)\r
          for (int i = 0; i < allGroups.length; i++)\r
@@ -397,7 +405,7 @@ public class SeqPanel extends JPanel
       SequenceGroup sg = new SequenceGroup();\r
       sg.setStartRes(res);\r
       sg.setEndRes(res);\r
-      sg.addSequence( (Sequence)av.getAlignment().getSequenceAt(seq) );\r
+      sg.addSequence( sequence );\r
       av.setRubberbandGroup( sg );\r
       stretchGroup = sg;\r
 \r
@@ -442,6 +450,8 @@ public class SeqPanel extends JPanel
 \r
   public void doMouseReleasedDefineMode(MouseEvent evt)\r
   {\r
+    if(stretchGroup==null)\r
+      return;\r
 \r
     if(stretchGroup.cs instanceof ClustalxColourScheme)\r
     {\r
@@ -495,6 +505,8 @@ public class SeqPanel extends JPanel
     int res = evt.getX()/av.getCharWidth() + av.getStartRes();\r
     int y = evt.getY()/av.getCharHeight() + av.getStartSeq();\r
 \r
+    if(stretchGroup==null)\r
+      return;\r
 \r
     if(stretchGroup.getEndRes()==res)\r
       // Edit end res position of selected group\r