JAL-2490 performant findFeaturesAtRes
authorgmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 May 2017 15:59:19 +0000 (16:59 +0100)
committergmungoc <g.m.carstairs@dundee.ac.uk>
Fri, 12 May 2017 15:59:19 +0000 (16:59 +0100)
src/jalview/appletgui/SeqPanel.java

index 60c53dd..44ce755 100644 (file)
@@ -52,6 +52,7 @@ import java.awt.event.InputEvent;
 import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.MouseMotionListener;
+import java.util.List;
 import java.util.Vector;
 
 public class SeqPanel extends Panel implements MouseMotionListener,
@@ -557,20 +558,20 @@ public class SeqPanel extends Panel implements MouseMotionListener,
         av.setSelectionGroup(null);
       }
 
-      SequenceFeature[] features = findFeaturesAtRes(sequence,
+      List<SequenceFeature> features = findFeaturesAtRes(sequence,
               sequence.findPosition(findRes(evt)));
 
-      if (features != null && features.length > 0)
+      if (!features.isEmpty())
       {
         SearchResultsI highlight = new SearchResults();
-        highlight.addResult(sequence, features[0].getBegin(),
-                features[0].getEnd());
+        highlight.addResult(sequence, features.get(0).getBegin(), features
+                .get(0).getEnd());
         seqCanvas.highlightSearchResults(highlight);
-      }
-      if (features != null && features.length > 0)
-      {
+        SequenceFeature[] featuresArray = features
+                .toArray(new SequenceFeature[features.size()]);
         seqCanvas.getFeatureRenderer().amendFeatures(
-                new SequenceI[] { sequence }, features, false, ap, null);
+                new SequenceI[] { sequence }, featuresArray, false, ap,
+                null);
 
         seqCanvas.highlightSearchResults(null);
       }
@@ -848,13 +849,13 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
 
     // use aa to see if the mouse pointer is on a
-    SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
+    List<SequenceFeature> allFeatures = findFeaturesAtRes(sequence,
             sequence.findPosition(res));
 
     int index = 0;
-    while (index < allFeatures.length)
+    while (index < allFeatures.size())
     {
-      SequenceFeature sf = allFeatures[index];
+      SequenceFeature sf = allFeatures.get(index);
 
       tooltipText.append(sf.getType() + " " + sf.begin + ":" + sf.end);
 
@@ -886,40 +887,9 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     }
   }
 
-  SequenceFeature[] findFeaturesAtRes(SequenceI sequence, int res)
+  List<SequenceFeature> findFeaturesAtRes(SequenceI sequence, int res)
   {
-    Vector tmp = new Vector();
-    SequenceFeature[] features = sequence.getSequenceFeatures();
-    if (features != null)
-    {
-      for (int i = 0; i < features.length; i++)
-      {
-        if (av.getFeaturesDisplayed() == null
-                || !av.getFeaturesDisplayed().isVisible(
-                        features[i].getType()))
-        {
-          continue;
-        }
-
-        if (features[i].featureGroup != null
-                && !seqCanvas.fr.checkGroupVisibility(
-                        features[i].featureGroup, false))
-        {
-          continue;
-        }
-
-        if ((features[i].getBegin() <= res)
-                && (features[i].getEnd() >= res))
-        {
-          tmp.addElement(features[i]);
-        }
-      }
-    }
-
-    features = new SequenceFeature[tmp.size()];
-    tmp.copyInto(features);
-
-    return features;
+    return seqCanvas.getFeatureRenderer().findFeaturesAtRes(sequence, res);
   }
 
   Tooltip tooltip;
@@ -1441,25 +1411,20 @@ public class SeqPanel extends Panel implements MouseMotionListener,
     // DETECT RIGHT MOUSE BUTTON IN AWT
     if ((evt.getModifiers() & InputEvent.BUTTON3_MASK) == InputEvent.BUTTON3_MASK)
     {
-      SequenceFeature[] allFeatures = findFeaturesAtRes(sequence,
+      List<SequenceFeature> allFeatures = findFeaturesAtRes(sequence,
               sequence.findPosition(res));
 
       Vector<String> links = null;
-      if (allFeatures != null)
+      for (int i = 0; i < allFeatures.size(); i++)
       {
-        for (int i = 0; i < allFeatures.length; i++)
+        SequenceFeature sf = allFeatures.get(i);
+        if (sf.links != null)
         {
-          if (allFeatures[i].links != null)
+          if (links == null)
           {
-            if (links == null)
-            {
-              links = new Vector<String>();
-            }
-            for (int j = 0; j < allFeatures[i].links.size(); j++)
-            {
-              links.addElement(allFeatures[i].links.elementAt(j));
-            }
+            links = new Vector<String>();
           }
+          links.addAll(sf.links);
         }
       }
       APopupMenu popup = new APopupMenu(ap, null, links);