fix feature creation for selected region beyond end of sequence bug: https://mantis...
authorjprocter <Jim Procter>
Mon, 3 Aug 2009 16:38:09 +0000 (16:38 +0000)
committerjprocter <Jim Procter>
Mon, 3 Aug 2009 16:38:09 +0000 (16:38 +0000)
src/jalview/appletgui/APopupMenu.java
src/jalview/gui/PopupMenu.java

index 6a177b5..0226349 100755 (executable)
@@ -556,19 +556,28 @@ public class APopupMenu extends java.awt.PopupMenu implements
       {
         return;
       }
-
-      int gSize = sg.getSize();
-      SequenceI[] seqs = new SequenceI[gSize];
-      SequenceFeature[] features = new SequenceFeature[gSize];
-
+      int rsize=0,gSize = sg.getSize();
+      SequenceI[] rseqs,seqs = new SequenceI[gSize];
+      SequenceFeature[] tfeatures,features = new SequenceFeature[gSize];
+      
       for (int i = 0; i < gSize; i++)
       {
-        seqs[i] = sg.getSequenceAt(i);
         int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
         int end = sg.findEndRes(sg.getSequenceAt(i));
-        features[i] = new SequenceFeature(null, null, null, start, end,
+        if (start<=end)
+        {
+          seqs[rsize] = sg.getSequenceAt(i);
+          features[rsize] = new SequenceFeature(null, null, null, start, end,
                 "Jalview");
+          rsize++;
+        }
       }
+      rseqs = new SequenceI[rsize];
+      tfeatures = new SequenceFeature[rsize];
+      System.arraycopy(seqs,0,rseqs, 0, rsize);
+      System.arraycopy(features, 0, tfeatures, 0, rsize);
+      features = tfeatures;
+      seqs = rseqs;
 
       if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
               features, true, ap))
index a1a8715..bd55d50 100755 (executable)
@@ -1532,20 +1532,28 @@ public class PopupMenu extends JPopupMenu
     {
       return;
     }
-
-    int gSize = sg.getSize();
-    SequenceI[] seqs = new SequenceI[gSize];
-    SequenceFeature[] features = new SequenceFeature[gSize];
-
+    int rsize=0,gSize = sg.getSize();
+    SequenceI[] rseqs,seqs = new SequenceI[gSize];
+    SequenceFeature[] tfeatures,features = new SequenceFeature[gSize];
+    
     for (int i = 0; i < gSize; i++)
     {
-      seqs[i] = sg.getSequenceAt(i).getDatasetSequence();
       int start = sg.getSequenceAt(i).findPosition(sg.getStartRes());
       int end = sg.findEndRes(sg.getSequenceAt(i));
-      features[i] = new SequenceFeature(null, null, null, start, end,
+      if (start<=end)
+      {
+        seqs[rsize] = sg.getSequenceAt(i).getDatasetSequence();
+        features[rsize] = new SequenceFeature(null, null, null, start, end,
               "Jalview");
+        rsize++;
+      }
     }
-
+    rseqs = new SequenceI[rsize];
+    tfeatures = new SequenceFeature[rsize];
+    System.arraycopy(seqs,0,rseqs, 0, rsize);
+    System.arraycopy(features, 0, tfeatures, 0, rsize);
+    features = tfeatures;
+    seqs = rseqs;
     if (ap.seqPanel.seqCanvas.getFeatureRenderer().amendFeatures(seqs,
             features, true, ap))
     {