From: gmungoc Date: Fri, 12 May 2017 15:59:19 +0000 (+0100) Subject: JAL-2490 performant findFeaturesAtRes X-Git-Tag: Release_2_10_3b1~282 X-Git-Url: http://source.jalview.org/gitweb/?a=commitdiff_plain;h=6323f1a33650360f131f25cf2797e5600ceee49f;p=jalview.git JAL-2490 performant findFeaturesAtRes --- diff --git a/src/jalview/appletgui/SeqPanel.java b/src/jalview/appletgui/SeqPanel.java index 60c53dd..44ce755 100644 --- a/src/jalview/appletgui/SeqPanel.java +++ b/src/jalview/appletgui/SeqPanel.java @@ -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 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 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 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 allFeatures = findFeaturesAtRes(sequence, sequence.findPosition(res)); Vector 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(); - } - for (int j = 0; j < allFeatures[i].links.size(); j++) - { - links.addElement(allFeatures[i].links.elementAt(j)); - } + links = new Vector(); } + links.addAll(sf.links); } } APopupMenu popup = new APopupMenu(ap, null, links);