JAL-2738 copy to spikes/mungo
[jalview.git] / src / jalview / appletgui / AnnotationColumnChooser.java
index 2acb568..b4c1d54 100644 (file)
@@ -46,7 +46,7 @@ import java.awt.event.MouseEvent;
 import java.awt.event.MouseListener;
 import java.awt.event.TextEvent;
 import java.awt.event.TextListener;
-import java.util.Iterator;
+import java.util.ArrayList;
 import java.util.Vector;
 
 //import javax.swing.JPanel;
@@ -142,7 +142,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     }
     setOldHiddenColumns(av.getAlignment().getHiddenColumns());
     adjusting = true;
-    Vector<String> list = new Vector<String>();
+    Vector<String> list = new Vector<>();
     int index = 1;
     for (int i = 0; i < anns.length; i++)
     {
@@ -172,16 +172,12 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     // restore Object state from the previous session if one exists
     if (lastChooser != null)
     {
-      currentSearchPanel = lastChooser
-              .getCurrentSearchPanel();
+      currentSearchPanel = lastChooser.getCurrentSearchPanel();
       currentStructureFilterPanel = lastChooser
               .getCurrentStructureFilterPanel();
-      annotations.select(lastChooser
-              .getAnnotations().getSelectedIndex());
-      threshold.select(lastChooser
-              .getThreshold().getSelectedIndex());
-      actionOption = lastChooser
-              .getActionOption();
+      annotations.select(lastChooser.getAnnotations().getSelectedIndex());
+      threshold.select(lastChooser.getThreshold().getSelectedIndex());
+      actionOption = lastChooser.getActionOption();
       percentThreshold.setState(lastChooser.percentThreshold.getState());
     }
 
@@ -295,21 +291,21 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
 
       if (av.getAnnotationColumnSelectionState() != null)
       {
-        HiddenColumns oldHidden = av
-                .getAnnotationColumnSelectionState()
+        HiddenColumns oldHidden = av.getAnnotationColumnSelectionState()
                 .getOldHiddenColumns();
-        if (oldHidden != null && oldHidden.getListOfCols() != null
-                && !oldHidden.getListOfCols().isEmpty())
+        if (oldHidden != null)
         {
-          for (Iterator<int[]> itr = oldHidden.getListOfCols()
-                  .iterator(); itr.hasNext();)
+          ArrayList<int[]> regions = oldHidden.getHiddenColumnsCopy();
+          for (int[] positions : regions)
           {
-            int positions[] = itr.next();
             av.hideColumns(positions[0], positions[1]);
           }
         }
+        // TODO not clear why we need to hide all the columns (above) if we are
+        // going to copy the hidden columns over wholesale anyway
         av.getAlignment().setHiddenColumns(oldHidden);
       }
+      av.sendSelection();
       ap.paintAlignment(true);
     }
 
@@ -398,11 +394,11 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     }
 
     AnnotationFilterParameter filterParams = new AnnotationFilterParameter();
-    setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[getAnnotations()
-            .getSelectedIndex()]);
+    setCurrentAnnotation(av.getAlignment()
+            .getAlignmentAnnotation()[getAnnotations().getSelectedIndex()]);
 
-    int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
-            .getSelectedIndex());
+    int selectedThresholdItem = getSelectedThresholdItem(
+            getThreshold().getSelectedIndex());
 
     slider.setEnabled(true);
     thresholdValue.setEnabled(true);
@@ -420,20 +416,20 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     {
       if (getCurrentAnnotation().threshold == null)
       {
-        getCurrentAnnotation()
-                .setThreshold(
-                        new jalview.datamodel.GraphLine(
-                                (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
-                                "Threshold", Color.black));
+        getCurrentAnnotation().setThreshold(new jalview.datamodel.GraphLine(
+                (getCurrentAnnotation().graphMax
+                        - getCurrentAnnotation().graphMin) / 2f,
+                "Threshold", Color.black));
       }
 
       adjusting = true;
-      float range = getCurrentAnnotation().graphMax * 1000
-              - getCurrentAnnotation().graphMin * 1000;
+      // float range = getCurrentAnnotation().graphMax * 1000
+      // - getCurrentAnnotation().graphMin * 1000;
 
       slider.setMinimum((int) (getCurrentAnnotation().graphMin * 1000));
       slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
-      slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
+      slider.setValue(
+              (int) (getCurrentAnnotation().threshold.value * 1000));
       setThresholdValueText();
       // slider.setMajorTickSpacing((int) (range / 10f));
       slider.setEnabled(true);
@@ -442,22 +438,22 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       adjusting = false;
 
       // build filter params
-      filterParams
-              .setThresholdType(AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
-      if (getCurrentAnnotation().graph != AlignmentAnnotation.NO_GRAPH)
+      filterParams.setThresholdType(
+              AnnotationFilterParameter.ThresholdType.NO_THRESHOLD);
+      if (getCurrentAnnotation().isQuantitative())
       {
         filterParams
                 .setThresholdValue(getCurrentAnnotation().threshold.value);
 
         if (selectedThresholdItem == AnnotationColourGradient.ABOVE_THRESHOLD)
         {
-          filterParams
-                  .setThresholdType(AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
+          filterParams.setThresholdType(
+                  AnnotationFilterParameter.ThresholdType.ABOVE_THRESHOLD);
         }
         else if (selectedThresholdItem == AnnotationColourGradient.BELOW_THRESHOLD)
         {
-          filterParams
-                  .setThresholdType(AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
+          filterParams.setThresholdType(
+                  AnnotationFilterParameter.ThresholdType.BELOW_THRESHOLD);
         }
       }
     }
@@ -488,13 +484,13 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
         filterParams.setRegexString(currentSearchPanel.searchBox.getText());
         if (currentSearchPanel.displayName.getState())
         {
-          filterParams
-                  .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
+          filterParams.addRegexSearchField(
+                  AnnotationFilterParameter.SearchableAnnotationField.DISPLAY_STRING);
         }
         if (currentSearchPanel.description.getState())
         {
-          filterParams
-                  .addRegexSearchField(AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
+          filterParams.addRegexSearchField(
+                  AnnotationFilterParameter.SearchableAnnotationField.DESCRIPTION);
         }
       }
       else
@@ -504,10 +500,13 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
       }
     }
 
+    // show hidden columns here, before changing the column selection in
+    // filterAnnotations, because showing hidden columns has the side effect of
+    // adding them to the selection
+    av.showAllHiddenColumns();
     av.getColumnSelection().filterAnnotations(
             getCurrentAnnotation().annotations, filterParams);
 
-    av.showAllHiddenColumns();
     if (getActionOption() == ACTION_OPTION_HIDE)
     {
       av.hideSelectedColumns();
@@ -515,6 +514,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
 
     filterParams = null;
     av.setAnnotationColumnSelectionState(this);
+    av.sendSelection();
     ap.paintAlignment(true);
   }
 
@@ -598,7 +598,7 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
   {
     String currentView = AnnotationColumnChooser.NO_GRAPH_VIEW;
     if (av.getAlignment().getAlignmentAnnotation()[getAnnotations()
-            .getSelectedIndex()].graph != AlignmentAnnotation.NO_GRAPH)
+            .getSelectedIndex()].isQuantitative())
     {
       currentView = AnnotationColumnChooser.GRAPH_VIEW;
     }
@@ -637,7 +637,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
 
     public void syncState()
     {
-      if (aColChooser.getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
+      if (aColChooser
+              .getActionOption() == AnnotationColumnChooser.ACTION_OPTION_HIDE)
       {
         furtherAction.select("Hide");
       }
@@ -665,8 +666,8 @@ public class AnnotationColumnChooser extends AnnotationRowFilter implements
     }
   }
 
-  public class StructureFilterPanel extends TitledPanel implements
-          ItemListener
+  public class StructureFilterPanel extends TitledPanel
+          implements ItemListener
   {
     private AnnotationColumnChooser aColChooser;