JAL-1066 basic gui and functionality for per-sequence colour by annotation
[jalview.git] / src / jalview / gui / AnnotationColourChooser.java
index 7fb868f..5b69534 100755 (executable)
@@ -54,11 +54,8 @@ public class AnnotationColourChooser extends JPanel
     if (av.getAlignment().getGroups() != null)
     {
       oldgroupColours = new Hashtable();
-      Vector allGroups = ap.av.getAlignment().getGroups();
-      SequenceGroup sg;
-      for (int g = 0; g < allGroups.size(); g++)
+      for (SequenceGroup sg:ap.av.getAlignment().getGroups())
       {
-        sg = (SequenceGroup) allGroups.get(g);
         if (sg.cs != null)
         {
           oldgroupColours.put(sg, sg.cs);
@@ -108,8 +105,8 @@ public class AnnotationColourChooser extends JPanel
        minColour.setBackground(acg.getMinColour());
         maxColour.setBackground(acg.getMaxColour());
       }
+      seqAssociated.setSelected(acg.isSeqAssociated());
     }
-
     adjusting = true;
     Vector list = new Vector();
     int index = 1;
@@ -159,7 +156,8 @@ public class AnnotationColourChooser extends JPanel
     adjusting = false;
 
     changeColour();
-    validate();
+    frame.invalidate();
+    frame.pack();
 
   }
 
@@ -290,6 +288,19 @@ public class AnnotationColourChooser extends JPanel
         thresholdIsMin_actionPerformed(actionEvent);
       }
     });
+    seqAssociated.setBackground(Color.white);
+    seqAssociated.setFont(JvSwingUtils.getLabelFont());
+    seqAssociated.setText("Per-sequence only");
+    seqAssociated.addActionListener(new ActionListener()
+    {
+      
+      @Override
+      public void actionPerformed(ActionEvent arg0)
+      {
+        seqAssociated_actionPerformed(arg0);
+      }
+    });
+    
     this.setLayout(borderLayout1);
     jPanel2.setLayout(new MigLayout("","[left][center][right]","[][][]"));
     jPanel1.setBackground(Color.white);
@@ -304,7 +315,7 @@ public class AnnotationColourChooser extends JPanel
     colpanel.add(minColour);
     colpanel.add(maxColour);
     jPanel2.add(colpanel, "wrap");
-    
+    jPanel2.add(seqAssociated, "wrap");
     jPanel2.add(threshold);
     jPanel2.add(defColours,"skip 1, wrap");
     jPanel2.add(thresholdIsMin);
@@ -312,6 +323,12 @@ public class AnnotationColourChooser extends JPanel
     jPanel2.add(thresholdValue, "grow");
     this.add(jPanel1, java.awt.BorderLayout.SOUTH);
     this.add(jPanel2, java.awt.BorderLayout.CENTER);
+    this.validate();
+  }
+
+  protected void seqAssociated_actionPerformed(ActionEvent arg0)
+  {
+    changeColour();
   }
 
   protected void resetColours_actionPerformed(ActionEvent arg0)
@@ -345,6 +362,8 @@ public class AnnotationColourChooser extends JPanel
   JCheckBox currentColours = new JCheckBox();
 
   JCheckBox thresholdIsMin = new JCheckBox();
+  
+  JCheckBox seqAssociated = new JCheckBox();
 
   public void minColour_actionPerformed()
   {
@@ -439,6 +458,7 @@ public class AnnotationColourChooser extends JPanel
               minColour.getBackground(), maxColour.getBackground(),
               aboveThreshold);
     }
+    acg.setSeqAssociated(seqAssociated.isSelected());
 
     if (currentAnnotation.graphMin == 0f
             && currentAnnotation.graphMax == 0f)
@@ -452,12 +472,9 @@ public class AnnotationColourChooser extends JPanel
 
     if (av.getAlignment().getGroups() != null)
     {
-      Vector allGroups = ap.av.getAlignment().getGroups();
-      SequenceGroup sg;
-      for (int g = 0; g < allGroups.size(); g++)
+      
+      for (SequenceGroup sg:ap.av.getAlignment().getGroups())
       {
-        sg = (SequenceGroup) allGroups.get(g);
-
         if (sg.cs == null)
         {
           continue;
@@ -467,16 +484,20 @@ public class AnnotationColourChooser extends JPanel
         {
           sg.cs = new AnnotationColourGradient(currentAnnotation, sg.cs,
                   aboveThreshold);
+          ((AnnotationColourGradient)sg.cs).setSeqAssociated(seqAssociated.isSelected());
+
         }
         else
         {
           sg.cs = new AnnotationColourGradient(currentAnnotation,
                   minColour.getBackground(), maxColour.getBackground(),
                   aboveThreshold);
+          ((AnnotationColourGradient)sg.cs).setSeqAssociated(seqAssociated.isSelected());
         }
 
       }
     }
+    ap.alignmentChanged();
     // ensure all associated views (overviews, structures, etc) are notified of updated colours.
     ap.paintAlignment(true);
   }
@@ -510,11 +531,9 @@ public class AnnotationColourChooser extends JPanel
     av.setGlobalColourScheme(oldcs);
     if (av.getAlignment().getGroups() != null)
     {
-      Vector allGroups = ap.av.getAlignment().getGroups();
-      SequenceGroup sg;
-      for (int g = 0; g < allGroups.size(); g++)
+      
+      for (SequenceGroup sg:ap.av.getAlignment().getGroups())
       {
-        sg = (SequenceGroup) allGroups.get(g);
         sg.cs = (ColourSchemeI) oldgroupColours.get(sg);
       }
     }