JAL-2050 hide introns also when fetching Ensembl xrefs for Uniprot
[jalview.git] / src / jalview / controller / AlignViewController.java
index be84bbf..24439ca 100644 (file)
@@ -37,7 +37,6 @@ import jalview.io.FeaturesFile;
 import jalview.util.MessageManager;
 
 import java.awt.Color;
-import java.util.ArrayList;
 import java.util.BitSet;
 import java.util.List;
 
@@ -239,6 +238,7 @@ public class AlignViewController implements AlignViewControllerI
     ColumnSelection cs = viewport.getColumnSelection();
     if (bs.cardinality() > 0 || invert)
     {
+      boolean changed = false;
       if (cs == null)
       {
         cs = new ColumnSelection();
@@ -247,6 +247,7 @@ public class AlignViewController implements AlignViewControllerI
       {
         if (!extendCurrent)
         {
+          changed = !cs.isEmpty();
           cs.clear();
         }
       }
@@ -258,6 +259,7 @@ public class AlignViewController implements AlignViewControllerI
         {
           if (ibs < 0 || i < ibs)
           {
+            changed = true;
             if (toggle && cs.contains(i))
             {
               cs.removeElement(i++);
@@ -279,6 +281,7 @@ public class AlignViewController implements AlignViewControllerI
         for (int i = bs.nextSetBit(alStart); i >= alStart; i = bs
                 .nextSetBit(i + 1))
         {
+          changed = true;
           if (toggle && cs.contains(i))
           {
             cs.removeElement(i);
@@ -289,18 +292,21 @@ public class AlignViewController implements AlignViewControllerI
           }
         }
       }
-      viewport.setColumnSelection(cs);
-      alignPanel.paintAlignment(true);
-      avcg.setStatus(MessageManager.formatMessage(
-              "label.view_controller_toggled_marked",
-              new String[] {
-                  (toggle ? MessageManager.getString("label.toggled")
-                          : MessageManager.getString("label.marked")),
-                  (invert ? (Integer.valueOf((alw - alStart)
-                          - bs.cardinality()).toString()) : (Integer
-                          .valueOf(bs.cardinality()).toString())),
-                  featureType, Integer.valueOf(nseq).toString() }));
-      return true;
+      if (changed)
+      {
+        viewport.setColumnSelection(cs);
+        alignPanel.paintAlignment(true);
+        avcg.setStatus(MessageManager.formatMessage(
+                "label.view_controller_toggled_marked",
+                new String[] {
+                    (toggle ? MessageManager.getString("label.toggled")
+                            : MessageManager.getString("label.marked")),
+                    (invert ? (Integer.valueOf((alw - alStart)
+                            - bs.cardinality()).toString()) : (Integer
+                            .valueOf(bs.cardinality()).toString())),
+                    featureType, Integer.valueOf(nseq).toString() }));
+        return true;
+      }
     }
     else
     {
@@ -312,51 +318,28 @@ public class AlignViewController implements AlignViewControllerI
         cs.clear();
         alignPanel.paintAlignment(true);
       }
-      return false;
     }
+    return false;
   }
 
   @Override
-  public void sortAlignmentByFeatureDensity(String[] typ)
+  public void sortAlignmentByFeatureDensity(List<String> typ)
   {
     sortBy(typ, "Sort by Density", AlignmentSorter.FEATURE_DENSITY);
   }
 
-  protected void sortBy(String[] typ, String methodText, final String method)
+  protected void sortBy(List<String> typ, String methodText,
+          final String method)
   {
     FeatureRenderer fr = alignPanel.getFeatureRenderer();
-    if (typ == null)
+    if (typ == null && fr != null)
     {
-      typ = fr == null ? null : fr.getDisplayedFeatureTypes();
+      typ = fr.getDisplayedFeatureTypes();
     }
-    String gps[] = null;
-    gps = fr == null ? null : fr.getDisplayedFeatureGroups();
-    if (typ != null)
+    List<String> gps = null;
+    if (fr != null)
     {
-      List<String> types = new ArrayList<String>();
-      for (String displayed : typ)
-      {
-        if (displayed != null)
-        {
-          types.add(displayed);
-        }
-      }
-      typ = new String[types.size()];
-      types.toArray(typ);
-    }
-    if (gps != null)
-    {
-      List<String> grps = new ArrayList<String>();
-
-      for (int i = 0; i < gps.length; i++)
-      {
-        if (gps[i] != null)
-        {
-          grps.add(gps[i]);
-        }
-      }
-      gps = new String[grps.size()];
-      grps.toArray(gps);
+      gps = fr.getDisplayedFeatureGroups();
     }
     AlignmentI al = viewport.getAlignment();
 
@@ -381,7 +364,7 @@ public class AlignViewController implements AlignViewControllerI
   }
 
   @Override
-  public void sortAlignmentByFeatureScore(String[] typ)
+  public void sortAlignmentByFeatureScore(List<String> typ)
   {
     sortBy(typ, "Sort by Feature Score", AlignmentSorter.FEATURE_SCORE);
   }