JAL-3210 Improvements to eclipse detection. New src tree and SwingJS updated from...
[jalview.git] / src / jalview / gui / AnnotationColourChooser.java
index 153f70c..a48553e 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,9 +63,9 @@ 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();
 
@@ -174,7 +174,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       {
         if (minColour.isEnabled())
         {
-          minColour_actionPerformed();
+          showColourChooser(minColour, "label.select_colour_minimum_value");
         }
       }
     });
@@ -189,7 +189,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       {
         if (maxColour.isEnabled())
         {
-          maxColour_actionPerformed();
+          showColourChooser(maxColour, "label.select_colour_maximum_value");
         }
       }
     });
@@ -283,41 +283,32 @@ public class AnnotationColourChooser extends AnnotationRowFilter
   private void setDefaultMinMax()
   {
     minColour.setBackground(
-            Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
+            Cache.getDefaultColour(Preferences.ANNOTATIONCOLOUR_MIN, Color.orange));
     maxColour.setBackground(
-            Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
+            Cache.getDefaultColour(Preferences.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 +433,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
     acg.setThresholdIsMinMax(thresholdIsMin.isSelected());
 
-    av.setGlobalColourScheme(acg);
+    this.ap.alignFrame.changeColour(acg);
 
     if (av.getAlignment().getGroups() != null)
     {
@@ -454,9 +445,15 @@ public class AnnotationColourChooser extends AnnotationRowFilter
           continue;
         }
         sg.setColourScheme(
-                acg.getInstance(sg, ap.av.getHiddenRepSequences()));
+                acg.getInstance(av, sg));
       }
     }
   }
 
+  @Override
+  protected void sliderDragReleased()
+  {
+    super.sliderDragReleased();
+    ap.paintAlignment(true, true);
+  }
 }