JAL-2629 update spike branch to latest
[jalview.git] / src / jalview / gui / OptsAndParamsPage.java
index fcb293c..dcd07ef 100644 (file)
@@ -101,7 +101,7 @@ public class OptsAndParamsPage
   public class OptionBox extends JPanel
           implements MouseListener, ActionListener
   {
-    JCheckBox enabled = new JCheckBox();
+    JCheckBox enabled;
 
     final URL finfo;
 
@@ -113,14 +113,13 @@ public class OptsAndParamsPage
 
     OptionI option;
 
-    JLabel optlabel = new JLabel();
-
-    JComboBox<String> val = new JComboBox<>();
+    JComboBox<String> val;
 
     public OptionBox(OptionI opt)
     {
       option = opt;
       setLayout(new FlowLayout(FlowLayout.LEFT));
+      enabled = new JCheckBox();
       enabled.setSelected(opt.isRequired()); // TODO: lock required options
       enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
       enabled.setText("");
@@ -149,6 +148,9 @@ public class OptsAndParamsPage
         }
       }
       add(enabled);
+
+      // todo combo or radio buttons?
+      val = new JComboBox<>();
       for (String str : opt.getPossibleValues())
       {
         val.addItem(str);
@@ -314,6 +316,8 @@ public class OptsAndParamsPage
 
     boolean isIntegerParameter;
 
+    boolean isStringParameter;
+
     boolean adjusting;
 
     JComboBox<String> choicebox;
@@ -358,12 +362,15 @@ public class OptsAndParamsPage
       {
         ValueType type = validator.getType();
         isIntegerParameter = type == ValueType.Integer;
+        isStringParameter = type == ValueType.String;
 
         /*
          * ensure slider has an integer range corresponding to
          * the min-max range of the parameter
          */
-        if (validator.getMin() != null && !isIntegerParameter)
+        if (validator.getMin() != null && validator.getMax() != null
+        // && !isIntegerParameter
+                && !isStringParameter)
         {
           double min = validator.getMin().doubleValue();
           double max = validator.getMax().doubleValue();
@@ -376,10 +383,10 @@ public class OptsAndParamsPage
           // todo scaleMin, scaleMax could also be final fields
         }
       }
-      else
-      {
-        isChoiceParameter = parameter.getPossibleValues() != null;
-      }
+
+      List<String> possibleValues = parameter.getPossibleValues();
+      isChoiceParameter = possibleValues != null
+              && !possibleValues.isEmpty();
 
       if (compact)
       {
@@ -545,13 +552,23 @@ public class OptsAndParamsPage
      */
     private void checkIfModified()
     {
-      Object newValue = updateSliderFromValueField();
-      boolean modified = true;
-      if (newValue.getClass() == lastVal.getClass())
+      if (!adjusting)
       {
-        modified = !newValue.equals(lastVal);
+        try
+        {
+          adjusting = true;
+          Object newValue = updateSliderFromValueField();
+          boolean modified = true;
+          if (newValue.getClass() == lastVal.getClass())
+          {
+            modified = !newValue.equals(lastVal);
+          }
+          pmdialogbox.argSetModified(this, modified);
+        } finally
+        {
+          adjusting = false;
+        }
       }
-      pmdialogbox.argSetModified(this, modified);
     }
 
     @Override
@@ -625,8 +642,13 @@ public class OptsAndParamsPage
     @Override
     public void stateChanged(ChangeEvent e)
     {
-      if (!adjusting)
+      if (adjusting)
       {
+        return;
+      }
+      try
+      {
+        adjusting = true;
         if (!isLogarithmicParameter)
         {
           /*
@@ -644,6 +666,9 @@ public class OptsAndParamsPage
           valueField.setText(formatDouble(value));
         }
         checkIfModified();
+      } finally
+      {
+        adjusting = false;
       }
     }
 
@@ -696,7 +721,9 @@ public class OptsAndParamsPage
             @Override
             public void keyReleased(KeyEvent e)
             {
-              if (e.isActionKey())
+              int keyCode = e.getKeyCode();
+              if (e.isActionKey() && keyCode != KeyEvent.VK_LEFT
+                      && keyCode != KeyEvent.VK_RIGHT)
               {
                 if (valueField.getText().trim().length() > 0)
                 {
@@ -752,7 +779,7 @@ public class OptsAndParamsPage
      */
     Object updateSliderFromValueField()
     {
-      if (validator == null)
+      if (validator == null || isStringParameter)
       {
         if (isChoiceParameter)
         {