JAL-3853 JAL-1870 toggle to enable/disable posterior probability transparency when...
[jalview.git] / src / jalview / gui / AnnotationColourChooser.java
index 9626309..33708ae 100644 (file)
@@ -24,6 +24,7 @@ import jalview.bin.Cache;
 import jalview.datamodel.AlignmentAnnotation;
 import jalview.datamodel.GraphLine;
 import jalview.datamodel.SequenceGroup;
+import jalview.gui.JalviewColourChooser.ColourChooserListener;
 import jalview.schemes.AnnotationColourGradient;
 import jalview.schemes.ColourSchemeI;
 import jalview.util.MessageManager;
@@ -42,7 +43,6 @@ import java.util.Vector;
 import javax.swing.BorderFactory;
 import javax.swing.JButton;
 import javax.swing.JCheckBox;
-import javax.swing.JColorChooser;
 import javax.swing.JComboBox;
 import javax.swing.JInternalFrame;
 import javax.swing.JLayeredPane;
@@ -63,11 +63,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
   private JCheckBox useOriginalColours = new JCheckBox();
 
-  private JPanel minColour = new JPanel();
+  JPanel minColour = new JPanel();
 
-  private JPanel maxColour = new JPanel();
+  JPanel maxColour = new JPanel();
 
   private JCheckBox thresholdIsMin = new JCheckBox();
+  private JCheckBox transparency = new JCheckBox();
 
   protected static final int MIN_WIDTH = 500;
 
@@ -174,7 +175,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       {
         if (minColour.isEnabled())
         {
-          minColour_actionPerformed();
+          showColourChooser(minColour, "label.select_colour_minimum_value");
         }
       }
     });
@@ -189,7 +190,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       {
         if (maxColour.isEnabled())
         {
-          maxColour_actionPerformed();
+          showColourChooser(maxColour, "label.select_colour_maximum_value");
         }
       }
     });
@@ -247,6 +248,19 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       }
     });
 
+    transparency.setBackground(Color.white);
+    transparency.setFont(JvSwingUtils.getLabelFont());
+    transparency
+            .setText(MessageManager.getString("Use Transparency"));
+    transparency.addActionListener(new ActionListener()
+    {
+
+      @Override
+      public void actionPerformed(ActionEvent arg0)
+      {
+        transparency_actionPerformed();
+      }
+    });
     this.setLayout(new BorderLayout());
     JPanel jPanel1 = new JPanel();
     JPanel jPanel2 = new JPanel();
@@ -259,6 +273,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     jPanel2.add(annotations, "grow, wrap");
     jPanel2.add(seqAssociated);
     jPanel2.add(useOriginalColours);
+    jPanel2.add(transparency);
     JPanel colpanel = new JPanel(new FlowLayout());
     colpanel.setBackground(Color.white);
     colpanel.add(minColour);
@@ -274,6 +289,10 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     this.validate();
   }
 
+  protected void transparency_actionPerformed()
+  {
+    updateView();
+  }
   protected void resetColours_actionPerformed()
   {
     setDefaultMinMax();
@@ -288,36 +307,27 @@ public class AnnotationColourChooser extends AnnotationRowFilter
             Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
   }
 
-  public void minColour_actionPerformed()
+  protected void showColourChooser(JPanel colourPanel, String titleKey)
   {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_colour_minimum_value"),
-            minColour.getBackground());
-    if (col != null)
+    String ttl = MessageManager.getString(titleKey);
+    ColourChooserListener listener = new ColourChooserListener()
     {
-      minColour.setBackground(col);
-    }
-    minColour.repaint();
-    updateView();
-  }
-
-  public void maxColour_actionPerformed()
-  {
-    Color col = JColorChooser.showDialog(this,
-            MessageManager.getString("label.select_colour_maximum_value"),
-            maxColour.getBackground());
-    if (col != null)
-    {
-      maxColour.setBackground(col);
-    }
-    maxColour.repaint();
-    updateView();
+      @Override
+      public void colourSelected(Color c)
+      {
+        colourPanel.setBackground(c);
+        colourPanel.repaint();
+        updateView();
+      }
+    };
+    JalviewColourChooser.showColourChooser(Desktop.getDesktopPane(), ttl,
+            colourPanel.getBackground(), listener);
   }
 
   @Override
   public void reset()
   {
-    av.setGlobalColourScheme(oldcs);
+    this.ap.alignFrame.changeColour(oldcs);
     if (av.getAlignment().getGroups() != null)
     {
 
@@ -442,7 +452,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
     acg.setThresholdIsMinMax(thresholdIsMin.isSelected());
 
-    av.setGlobalColourScheme(acg);
+    acg.setPositionToTransparency(transparency.isSelected());
+    
+    this.ap.alignFrame.changeColour(acg);
 
     if (av.getAlignment().getGroups() != null)
     {
@@ -454,7 +466,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
           continue;
         }
         sg.setColourScheme(
-                acg.getInstance(av, sg, ap.av.getHiddenRepSequences()));
+                acg.getInstance(av, sg));
       }
     }
   }
@@ -465,5 +477,4 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     super.sliderDragReleased();
     ap.paintAlignment(true, true);
   }
-
 }