Merge branch 'feature/JAL-3127_seqidChainshading' into merge/JAL-3127
[jalview.git] / src / jalview / gui / AnnotationColourChooser.java
index 8500888..60ad75d 100644 (file)
@@ -69,13 +69,17 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
   private JCheckBox thresholdIsMin = new JCheckBox();
 
+  protected static final int MIN_WIDTH = 500;
+
+  protected static final int MIN_HEIGHT = 240;
+
   public AnnotationColourChooser(AlignViewport av, final AlignmentPanel ap)
   {
     super(av, ap);
     oldcs = av.getGlobalColourScheme();
     if (av.getAlignment().getGroups() != null)
     {
-      oldgroupColours = new Hashtable<SequenceGroup, ColourSchemeI>();
+      oldgroupColours = new Hashtable<>();
       for (SequenceGroup sg : ap.av.getAlignment().getGroups())
       {
         if (sg.getColourScheme() != null)
@@ -90,7 +94,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     Desktop.addInternalFrame(frame,
             MessageManager.getString("label.colour_by_annotation"), 520,
             215);
-
+    frame.setMinimumSize(new Dimension(MIN_WIDTH, MIN_HEIGHT));
     addSliderChangeListener();
     addSliderMouseListeners();
 
@@ -106,8 +110,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     if (oldcs instanceof AnnotationColourGradient)
     {
       AnnotationColourGradient acg = (AnnotationColourGradient) oldcs;
-      useOriginalColours.setSelected(acg.isPredefinedColours()
-              || acg.getBaseColour() != null);
+      useOriginalColours.setSelected(
+              acg.isPredefinedColours() || acg.getBaseColour() != null);
       if (!acg.isPredefinedColours() && acg.getBaseColour() == null)
       {
         minColour.setBackground(acg.getMinColour());
@@ -116,9 +120,9 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       seqAssociated.setSelected(acg.isSeqAssociated());
 
     }
-    Vector<String> annotItems = getAnnotationItems(seqAssociated
-            .isSelected());
-    annotations = new JComboBox<String>(annotItems);
+    Vector<String> annotItems = getAnnotationItems(
+            seqAssociated.isSelected());
+    annotations = new JComboBox<>(annotItems);
 
     populateThresholdComboBox(threshold);
 
@@ -139,9 +143,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter
         getThreshold().setSelectedIndex(2);
         break;
       default:
-        throw new Error(
-                MessageManager
-                        .getString("error.implementation_error_dont_know_about_threshold_setting"));
+        throw new Error(MessageManager.getString(
+                "error.implementation_error_dont_know_about_threshold_setting"));
       }
       thresholdIsMin.setSelected(acg.isThresholdIsMinMax());
       thresholdValue.setText("" + acg.getAnnotationThreshold());
@@ -208,8 +211,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
     useOriginalColours.setFont(JvSwingUtils.getLabelFont());
     useOriginalColours.setOpaque(false);
-    useOriginalColours.setText(MessageManager
-            .getString("label.use_original_colours"));
+    useOriginalColours.setText(
+            MessageManager.getString("label.use_original_colours"));
     useOriginalColours.addActionListener(new ActionListener()
     {
       @Override
@@ -220,8 +223,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     });
     thresholdIsMin.setBackground(Color.white);
     thresholdIsMin.setFont(JvSwingUtils.getLabelFont());
-    thresholdIsMin.setText(MessageManager
-            .getString("label.threshold_minmax"));
+    thresholdIsMin
+            .setText(MessageManager.getString("label.threshold_minmax"));
     thresholdIsMin.addActionListener(new ActionListener()
     {
       @Override
@@ -232,8 +235,8 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     });
     seqAssociated.setBackground(Color.white);
     seqAssociated.setFont(JvSwingUtils.getLabelFont());
-    seqAssociated.setText(MessageManager
-            .getString("label.per_sequence_only"));
+    seqAssociated
+            .setText(MessageManager.getString("label.per_sequence_only"));
     seqAssociated.addActionListener(new ActionListener()
     {
 
@@ -279,10 +282,10 @@ public class AnnotationColourChooser extends AnnotationRowFilter
 
   private void setDefaultMinMax()
   {
-    minColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN",
-            Color.orange));
-    maxColour.setBackground(Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX",
-            Color.red));
+    minColour.setBackground(
+            Cache.getDefaultColour("ANNOTATIONCOLOUR_MIN", Color.orange));
+    maxColour.setBackground(
+            Cache.getDefaultColour("ANNOTATIONCOLOUR_MAX", Color.red));
   }
 
   public void minColour_actionPerformed()
@@ -314,7 +317,7 @@ public class AnnotationColourChooser extends AnnotationRowFilter
   @Override
   public void reset()
   {
-    av.setGlobalColourScheme(oldcs);
+    this.ap.alignFrame.changeColour(oldcs);
     if (av.getAlignment().getGroups() != null)
     {
 
@@ -330,15 +333,15 @@ public class AnnotationColourChooser extends AnnotationRowFilter
   {
     if (slider.isEnabled())
     {
-      if (useOriginalColours.isSelected()
-              && !(av.getGlobalColourScheme() instanceof AnnotationColourGradient))
+      if (useOriginalColours.isSelected() && !(av
+              .getGlobalColourScheme() instanceof AnnotationColourGradient))
       {
         updateView();
       }
       getCurrentAnnotation().threshold.value = slider.getValue() / 1000f;
       propagateSeqAssociatedThreshold(updateAllAnnotation,
               getCurrentAnnotation());
-      ap.paintAlignment(false);
+      ap.paintAlignment(false, false);
     }
   }
 
@@ -364,11 +367,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       return;
     }
 
-    setCurrentAnnotation(av.getAlignment().getAlignmentAnnotation()[annmap[annotations
-            .getSelectedIndex()]]);
+    setCurrentAnnotation(
+            av.getAlignment().getAlignmentAnnotation()[annmap[annotations
+                    .getSelectedIndex()]]);
 
-    int selectedThresholdItem = getSelectedThresholdItem(getThreshold()
-            .getSelectedIndex());
+    int selectedThresholdItem = getSelectedThresholdItem(
+            getThreshold().getSelectedIndex());
 
     slider.setEnabled(true);
     thresholdValue.setEnabled(true);
@@ -384,11 +388,10 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     else if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD
             && getCurrentAnnotation().threshold == null)
     {
-      getCurrentAnnotation()
-              .setThreshold(
-                      new GraphLine(
-                              (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin) / 2f,
-                              "Threshold", Color.black));
+      getCurrentAnnotation().setThreshold(new GraphLine(
+              (getCurrentAnnotation().graphMax
+                      - getCurrentAnnotation().graphMin) / 2f,
+              "Threshold", Color.black));
     }
 
     if (selectedThresholdItem != AnnotationColourGradient.NO_THRESHOLD)
@@ -397,9 +400,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter
       float range = getCurrentAnnotation().graphMax * ONETHOUSAND
               - getCurrentAnnotation().graphMin * ONETHOUSAND;
 
-      slider.setMinimum((int) (getCurrentAnnotation().graphMin * ONETHOUSAND));
-      slider.setMaximum((int) (getCurrentAnnotation().graphMax * ONETHOUSAND));
-      slider.setValue((int) (getCurrentAnnotation().threshold.value * ONETHOUSAND));
+      slider.setMinimum(
+              (int) (getCurrentAnnotation().graphMin * ONETHOUSAND));
+      slider.setMaximum(
+              (int) (getCurrentAnnotation().graphMax * ONETHOUSAND));
+      slider.setValue(
+              (int) (getCurrentAnnotation().threshold.value * ONETHOUSAND));
       thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
       slider.setMajorTickSpacing((int) (range / 10f));
       slider.setEnabled(true);
@@ -409,14 +415,12 @@ public class AnnotationColourChooser extends AnnotationRowFilter
     colorAlignmentContaining(getCurrentAnnotation(), selectedThresholdItem);
 
     ap.alignmentChanged();
-    // ensure all associated views (overviews, structures, etc) are notified of
-    // updated colours.
-    ap.paintAlignment(true);
   }
 
-  protected boolean colorAlignmentContaining(AlignmentAnnotation currentAnn, int selectedThresholdOption)
+  protected void colorAlignmentContaining(AlignmentAnnotation currentAnn,
+          int selectedThresholdOption)
   {
-  
+
     AnnotationColourGradient acg = null;
     if (useOriginalColours.isSelected())
     {
@@ -430,44 +434,35 @@ public class AnnotationColourChooser extends AnnotationRowFilter
               selectedThresholdOption);
     }
     acg.setSeqAssociated(seqAssociated.isSelected());
-  
+
     if (currentAnn.graphMin == 0f && currentAnn.graphMax == 0f)
     {
       acg.setPredefinedColours(true);
     }
-  
+
     acg.setThresholdIsMinMax(thresholdIsMin.isSelected());
-  
-    av.setGlobalColourScheme(acg);
-  
+
+    this.ap.alignFrame.changeColour(acg);
+
     if (av.getAlignment().getGroups() != null)
     {
-  
+
       for (SequenceGroup sg : ap.av.getAlignment().getGroups())
       {
         if (sg.cs == null)
         {
           continue;
         }
-  
-        if (useOriginalColours.isSelected())
-        {
-          sg.setColourScheme(new AnnotationColourGradient(currentAnn, sg
-                  .getColourScheme(), selectedThresholdOption));
-          ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
-                  .isSelected());
-        }
-        else
-        {
-          sg.setColourScheme(new AnnotationColourGradient(currentAnn,
-                  minColour.getBackground(), maxColour.getBackground(),
-                  selectedThresholdOption));
-          ((AnnotationColourGradient) sg.cs).setSeqAssociated(seqAssociated
-                  .isSelected());
-        }
+        sg.setColourScheme(
+                acg.getInstance(av, sg));
       }
     }
-    return false;
   }
 
+  @Override
+  protected void sliderDragReleased()
+  {
+    super.sliderDragReleased();
+    ap.paintAlignment(true, true);
+  }
 }