patch for JAL-1172 ensure option's default value is set in widget so it gets saved...
authorjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 19 Jun 2012 16:25:05 +0000 (17:25 +0100)
committerjprocter <jprocter@compbio.dundee.ac.uk>
Tue, 19 Jun 2012 16:25:05 +0000 (17:25 +0100)
src/jalview/gui/OptsAndParamsPage.java

index cca9cee..05c8e1d 100644 (file)
@@ -125,14 +125,14 @@ public class OptsAndParamsPage
         }
       }
       add(enabled, BorderLayout.NORTH);
+      for (Object str : opt.getPossibleValues())
+      {
+        val.addItem((String) str);
+      }
+      val.setSelectedItem((String) opt.getValue());
       if (opt.getPossibleValues().size() > 1)
       {
         setLayout(new GridLayout(1, 2));
-        for (Object str : opt.getPossibleValues())
-        {
-          val.addItem((String) str);
-        }
-        val.setSelectedItem((String) opt.getValue());
         val.addActionListener(this);
         add(val, BorderLayout.SOUTH);
       }
@@ -169,7 +169,7 @@ public class OptsAndParamsPage
       }
       else
       {
-        notmod &= initVal == null;
+        notmod &= (initVal!=null) ? initVal.equals(val.getSelectedItem()) : val.getSelectedItem()!=initVal;
       }
       poparent.argSetModified(this, !notmod);
     }
@@ -181,10 +181,19 @@ public class OptsAndParamsPage
         return null;
       }
       OptionI opt = option.copy();
-
+      if (opt.getPossibleValues()!=null && opt.getPossibleValues().size()==1)
+      {
+        // Hack to make sure the default value for an enabled option with only one value is actually returned
+        opt.setValue(opt.getPossibleValues().get(0));
+      }
       if (val.getSelectedItem() != null)
       {
         opt.setValue((String) val.getSelectedItem());
+      } else {
+        if (option.getValue()!=null)
+        {
+          opt.setValue(option.getValue());
+        }
       }
       return opt;
     }
@@ -241,7 +250,7 @@ public class OptsAndParamsPage
       }
       else
       {
-        initVal = (initEnabled) ? option.getValue() : null;
+        initVal = (initEnabled) ? (String)val.getSelectedItem() : null;
       }
     }