Merge branch 'bug/JAL-3120restoreFeatureColour' into merge/JAL-3120
[jalview.git] / src / jalview / gui / FeatureTypeSettings.java
index 55bc519..82e826f 100644 (file)
@@ -242,8 +242,7 @@ public class FeatureTypeSettings extends JalviewDialog
     String title = MessageManager
             .formatMessage("label.display_settings_for", new String[]
             { theType });
-    initDialogFrame(this, true, false, title, 500, 500);
-    
+    initDialogFrame(this, true, false, title, 580, 500);
     waitForInput();
   }
 
@@ -366,7 +365,7 @@ public class FeatureTypeSettings extends JalviewDialog
                         : BELOW_THRESHOLD_OPTION);
         slider.setEnabled(true);
         slider.setValue((int) (fc.getThreshold() * scaleFactor));
-        thresholdValue.setText(String.valueOf(getRoundedSliderValue()));
+        thresholdValue.setText(String.valueOf(fc.getThreshold()));
         thresholdValue.setEnabled(true);
         thresholdIsMin.setEnabled(true);
       }
@@ -563,13 +562,20 @@ public class FeatureTypeSettings extends JalviewDialog
     maxColour.setBorder(new LineBorder(Color.black));
 
     /*
-     * default max colour to last plain colour;
-     * make min colour a pale version of max colour
+     * if not set, default max colour to last plain colour,
+     * and make min colour a pale version of max colour
      */
-    FeatureColourI fc = fr.getFeatureColours().get(featureType);
-    Color bg = fc.getColour() == null ? Color.BLACK : fc.getColour();
-    maxColour.setBackground(bg);
-    minColour.setBackground(ColorUtils.bleachColour(bg, 0.9f));
+    Color max = originalColour.getMaxColour();
+    if (max == null)
+    {
+      max = originalColour.getColour();
+      minColour.setBackground(ColorUtils.bleachColour(max, 0.9f));
+    }
+    else
+    {
+      maxColour.setBackground(max);
+      minColour.setBackground(originalColour.getMinColour());
+    }
 
     noValueCombo = new JComboBox<>();
     noValueCombo.addItem(MessageManager.getString("label.no_colour"));
@@ -652,6 +658,7 @@ public class FeatureTypeSettings extends JalviewDialog
         {
           thresholdValue
                   .setText(String.valueOf(slider.getValue() / scaleFactor));
+          thresholdValue.setBackground(Color.white); // to reset red for invalid
           sliderValueChanged();
         }
       }
@@ -747,16 +754,16 @@ public class FeatureTypeSettings extends JalviewDialog
     singleColour.setFont(JvSwingUtils.getLabelFont());
     singleColour.setBorder(BorderFactory.createLineBorder(Color.black));
     singleColour.setPreferredSize(new Dimension(40, 20));
-    if (originalColour.isGraduatedColour())
-    {
-      singleColour.setBackground(originalColour.getMaxColour());
-      singleColour.setForeground(originalColour.getMaxColour());
-    }
-    else
-    {
+    // if (originalColour.isGraduatedColour())
+    // {
+    // singleColour.setBackground(originalColour.getMaxColour());
+    // singleColour.setForeground(originalColour.getMaxColour());
+    // }
+    // else
+    // {
       singleColour.setBackground(originalColour.getColour());
       singleColour.setForeground(originalColour.getColour());
-    }
+    // }
     singleColour.addMouseListener(new MouseAdapter()
     {
       @Override
@@ -881,42 +888,9 @@ public class FeatureTypeSettings extends JalviewDialog
   private FeatureColourI makeColourFromInputs()
   {
     /*
-     * easiest case - a single colour
-     */
-    if (simpleColour.isSelected())
-    {
-      return new FeatureColour(singleColour.getBackground());
-    }
-
-    /*
-     * next easiest case - colour by Label, or attribute text
-     */
-    if (byCategory.isSelected())
-    {
-      Color c = singleColour.getBackground();
-      FeatureColourI fc = new FeatureColour(c);
-      fc.setColourByLabel(true);
-      String byWhat = (String) colourByTextCombo.getSelectedItem();
-      if (!LABEL_18N.equals(byWhat))
-      {
-        fc.setAttributeName(
-                FeatureMatcher.fromAttributeDisplayName(byWhat));
-      }
-      return fc;
-    }
-
-    /*
-     * remaining case - graduated colour by score, or attribute value
+     * min-max range is to (or from) threshold value if 
+     * 'threshold is min/max' is selected 
      */
-    Color noColour = null;
-    if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
-    {
-      noColour = minColour.getBackground();
-    }
-    else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
-    {
-      noColour = maxColour.getBackground();
-    }
 
     float thresh = 0f;
     try
@@ -926,11 +900,6 @@ public class FeatureTypeSettings extends JalviewDialog
     {
       // invalid inputs are already handled on entry
     }
-
-    /*
-     * min-max range is to (or from) threshold value if 
-     * 'threshold is min/max' is selected 
-     */
     float minValue = min;
     float maxValue = max;
     final int thresholdOption = threshold.getSelectedIndex();
@@ -944,14 +913,50 @@ public class FeatureTypeSettings extends JalviewDialog
     {
       maxValue = thresh;
     }
+    Color noColour = null;
+    if (noValueCombo.getSelectedIndex() == MIN_COLOUR_OPTION)
+    {
+      noColour = minColour.getBackground();
+    }
+    else if (noValueCombo.getSelectedIndex() == MAX_COLOUR_OPTION)
+    {
+      noColour = maxColour.getBackground();
+    }
 
     /*
-     * make the graduated colour
+     * construct a colour that 'remembers' all the options, including
+     * those not currently selected
      */
-    FeatureColourI fc = new FeatureColour(minColour.getBackground(),
-            maxColour.getBackground(), noColour, minValue, maxValue);
+    FeatureColourI fc = new FeatureColour(singleColour.getBackground(),
+            minColour.getBackground(), maxColour.getBackground(), noColour,
+            minValue, maxValue);
 
     /*
+     * easiest case - a single colour
+     */
+    if (simpleColour.isSelected())
+    {
+      ((FeatureColour) fc).setGraduatedColour(false);
+      return fc;
+    }
+
+    /*
+     * next easiest case - colour by Label, or attribute text
+     */
+    if (byCategory.isSelected())
+    {
+      fc.setColourByLabel(true);
+      String byWhat = (String) colourByTextCombo.getSelectedItem();
+      if (!LABEL_18N.equals(byWhat))
+      {
+        fc.setAttributeName(
+                FeatureMatcher.fromAttributeDisplayName(byWhat));
+      }
+      return fc;
+    }
+
+    /*
+     * remaining case - graduated colour by score, or attribute value;
      * set attribute to colour by if selected
      */
     String byWhat = (String) colourByRangeCombo.getSelectedItem();
@@ -1019,21 +1024,23 @@ public class FeatureTypeSettings extends JalviewDialog
   {
     try
     {
+      /*
+       * set 'adjusting' flag while moving the slider, so it 
+       * doesn't then in turn change the value (with rounding)
+       */
       adjusting = true;
       float f = Float.parseFloat(thresholdValue.getText());
+      f = Float.max(f,  this.min);
+      f = Float.min(f, this.max);
+      thresholdValue.setText(String.valueOf(f));
       slider.setValue((int) (f * scaleFactor));
       threshline.value = f;
       thresholdValue.setBackground(Color.white); // ok
-
-      /*
-       * force repaint of any Overview window or structure
-       */
-      ap.paintAlignment(true, true);
+      adjusting = false;
+      colourChanged(true);
     } catch (NumberFormatException ex)
     {
       thresholdValue.setBackground(Color.red); // not ok
-    } finally
-    {
       adjusting = false;
     }
   }