JAL-2629 add basic parameter adjustment to hmmsearch/align
[jalview.git] / src / jalview / gui / OptsAndParamsPage.java
1 /*
2  * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
3  * Copyright (C) $$Year-Rel$$ The Jalview Authors
4  * 
5  * This file is part of Jalview.
6  * 
7  * Jalview is free software: you can redistribute it and/or
8  * modify it under the terms of the GNU General Public License 
9  * as published by the Free Software Foundation, either version 3
10  * of the License, or (at your option) any later version.
11  *  
12  * Jalview is distributed in the hope that it will be useful, but 
13  * WITHOUT ANY WARRANTY; without even the implied warranty 
14  * of MERCHANTABILITY or FITNESS FOR A PARTICULAR 
15  * PURPOSE.  See the GNU General Public License for more details.
16  * 
17  * You should have received a copy of the GNU General Public License
18  * along with Jalview.  If not, see <http://www.gnu.org/licenses/>.
19  * The Jalview Authors are detailed in the 'AUTHORS' file.
20  */
21 package jalview.gui;
22
23 import jalview.util.MessageManager;
24 import jalview.ws.params.ArgumentI;
25 import jalview.ws.params.OptionI;
26 import jalview.ws.params.ParameterI;
27 import jalview.ws.params.ValueConstrainI;
28 import jalview.ws.params.ValueConstrainI.ValueType;
29 import jalview.ws.params.simple.LogarithmicParameter;
30
31 import java.awt.BorderLayout;
32 import java.awt.Component;
33 import java.awt.Dimension;
34 import java.awt.Font;
35 import java.awt.GridLayout;
36 import java.awt.Rectangle;
37 import java.awt.event.ActionEvent;
38 import java.awt.event.ActionListener;
39 import java.awt.event.KeyEvent;
40 import java.awt.event.KeyListener;
41 import java.awt.event.MouseEvent;
42 import java.awt.event.MouseListener;
43 import java.net.URL;
44 import java.util.ArrayList;
45 import java.util.List;
46 import java.util.Map;
47
48 import javax.swing.JButton;
49 import javax.swing.JCheckBox;
50 import javax.swing.JComboBox;
51 import javax.swing.JComponent;
52 import javax.swing.JLabel;
53 import javax.swing.JMenuItem;
54 import javax.swing.JPanel;
55 import javax.swing.JPopupMenu;
56 import javax.swing.JScrollPane;
57 import javax.swing.JSlider;
58 import javax.swing.JTextArea;
59 import javax.swing.JTextField;
60 import javax.swing.border.TitledBorder;
61 import javax.swing.event.ChangeEvent;
62 import javax.swing.event.ChangeListener;
63
64 import net.miginfocom.swing.MigLayout;
65
66 /**
67  * GUI generator/manager for options and parameters. Originally abstracted from
68  * the WsJobParameters dialog box.
69  * 
70  * @author jprocter
71  * 
72  */
73 public class OptsAndParamsPage
74 {
75   /**
76    * compact or verbose style parameters
77    */
78   boolean compact = false;
79
80   public class OptionBox extends JPanel
81           implements MouseListener, ActionListener
82   {
83     JCheckBox enabled = new JCheckBox();
84
85     final URL finfo;
86
87     boolean hasLink = false;
88
89     boolean initEnabled = false;
90
91     String initVal = null;
92
93     OptionI option;
94
95     JLabel optlabel = new JLabel();
96
97     JComboBox val = new JComboBox();
98
99     public OptionBox(OptionI opt)
100     {
101       option = opt;
102       setLayout(new BorderLayout());
103       enabled.setSelected(opt.isRequired()); // TODO: lock required options
104       enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
105       enabled.setText("");
106       enabled.setText(opt.getName());
107       enabled.addActionListener(this);
108       finfo = option.getFurtherDetails();
109       String desc = opt.getDescription();
110       if (finfo != null)
111       {
112         hasLink = true;
113
114         enabled.setToolTipText(JvSwingUtils.wrapTooltip(true,
115                 ((desc == null || desc.trim().length() == 0)
116                         ? MessageManager.getString(
117                                 "label.opt_and_params_further_details")
118                         : desc) + "<br><img src=\"" + linkImageURL
119                         + "\"/>"));
120         enabled.addMouseListener(this);
121       }
122       else
123       {
124         if (desc != null && desc.trim().length() > 0)
125         {
126           enabled.setToolTipText(
127                   JvSwingUtils.wrapTooltip(true, opt.getDescription()));
128         }
129       }
130       add(enabled, BorderLayout.NORTH);
131       for (Object str : opt.getPossibleValues())
132       {
133         val.addItem(str);
134       }
135       val.setSelectedItem(opt.getValue());
136       if (opt.getPossibleValues().size() > 1)
137       {
138         setLayout(new GridLayout(1, 2));
139         val.addActionListener(this);
140         add(val, BorderLayout.SOUTH);
141       }
142       // TODO: add actionListeners for popup (to open further info),
143       // and to update list of parameters if an option is enabled
144       // that takes a value. JBPNote: is this TODO still valid ?
145       setInitialValue();
146     }
147
148     @Override
149     public void actionPerformed(ActionEvent e)
150     {
151       if (e.getSource() != enabled)
152       {
153         enabled.setSelected(true);
154       }
155       checkIfModified();
156     }
157
158     private void checkIfModified()
159     {
160       boolean notmod = (initEnabled == enabled.isSelected());
161       if (enabled.isSelected())
162       {
163         if (initVal != null)
164         {
165           notmod &= initVal.equals(val.getSelectedItem());
166         }
167         else
168         {
169           // compare against default service setting
170           notmod &= option.getValue() == null
171                   || option.getValue().equals(val.getSelectedItem());
172         }
173       }
174       else
175       {
176         notmod &= (initVal != null) ? initVal.equals(val.getSelectedItem())
177                 : val.getSelectedItem() != initVal;
178       }
179       poparent.argSetModified(this, !notmod);
180     }
181
182     public OptionI getOptionIfEnabled()
183     {
184       if (!enabled.isSelected())
185       {
186         return null;
187       }
188       OptionI opt = option.copy();
189       if (opt.getPossibleValues() != null
190               && opt.getPossibleValues().size() == 1)
191       {
192         // Hack to make sure the default value for an enabled option with only
193         // one value is actually returned
194         opt.setValue(opt.getPossibleValues().get(0));
195       }
196       if (val.getSelectedItem() != null)
197       {
198         opt.setValue((String) val.getSelectedItem());
199       }
200       else
201       {
202         if (option.getValue() != null)
203         {
204           opt.setValue(option.getValue());
205         }
206       }
207       return opt;
208     }
209
210     @Override
211     public void mouseClicked(MouseEvent e)
212     {
213       if (e.isPopupTrigger()) // for Windows
214       {
215         showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
216       }
217     }
218
219     @Override
220     public void mouseEntered(MouseEvent e)
221     {
222       // TODO Auto-generated method stub
223
224     }
225
226     @Override
227     public void mouseExited(MouseEvent e)
228     {
229       // TODO Auto-generated method stub
230
231     }
232
233     @Override
234     public void mousePressed(MouseEvent e)
235     {
236       if (e.isPopupTrigger()) // Mac
237       {
238         showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
239       }
240     }
241
242     @Override
243     public void mouseReleased(MouseEvent e)
244     {
245     }
246
247     public void resetToDefault(boolean setDefaultParams)
248     {
249       enabled.setSelected(false);
250       if (option.isRequired()
251               || (setDefaultParams && option.getValue() != null))
252       {
253         // Apply default value
254         selectOption(option, option.getValue());
255       }
256     }
257
258     public void setInitialValue()
259     {
260       initEnabled = enabled.isSelected();
261       if (option.getPossibleValues() != null
262               && option.getPossibleValues().size() > 1)
263       {
264         initVal = (String) val.getSelectedItem();
265       }
266       else
267       {
268         initVal = (initEnabled) ? (String) val.getSelectedItem() : null;
269       }
270     }
271
272   }
273
274   public class ParamBox extends JPanel
275           implements ChangeListener, ActionListener, MouseListener
276   {
277
278     boolean isLogarithmic;
279
280     boolean adjusting = false;
281
282     boolean choice = false;
283
284     JComboBox choicebox;
285
286     JPanel controlPanel = new JPanel();
287
288     boolean descisvisible = false;
289
290     JScrollPane descPanel = new JScrollPane();
291
292     final URL finfo;
293
294     boolean integ = false;
295
296     Object lastVal;
297
298     ParameterI parameter;
299
300     final OptsParametersContainerI pmdialogbox;
301
302     JPanel settingPanel = new JPanel();
303
304     JButton showDesc = new JButton();
305
306     JSlider slider = null;
307
308     JTextArea string = new JTextArea();
309
310     ValueConstrainI validator = null;
311
312     JTextField valueField = null;
313
314     public ParamBox(final OptsParametersContainerI pmlayout,
315             ParameterI parm)
316     {
317       pmdialogbox = pmlayout;
318       finfo = parm.getFurtherDetails();
319       validator = parm.getValidValue();
320       parameter = parm;
321       if (validator != null)
322       {
323         integ = validator.getType() == ValueType.Integer;
324       }
325       else
326       {
327         if (parameter.getPossibleValues() != null)
328         {
329           choice = true;
330         }
331       }
332       if (parm instanceof LogarithmicParameter)
333       {
334         isLogarithmic = true;
335       }
336
337       if (!compact)
338       {
339         makeExpanderParam(parm);
340       }
341       else
342       {
343         makeCompactParam(parm);
344
345       }
346     }
347
348     private void makeCompactParam(ParameterI parm)
349     {
350       setLayout(new MigLayout("", "[][grow]"));
351
352       String ttipText = null;
353
354       controlPanel.setLayout(new BorderLayout());
355
356       if (parm.getDescription() != null
357               && parm.getDescription().trim().length() > 0)
358       {
359         // Only create description boxes if there actually is a description.
360         ttipText = (JvSwingUtils.wrapTooltip(true,
361                 parm.getDescription() + (finfo != null ? "<br><img src=\""
362                         + linkImageURL + "\"/>"
363                         + MessageManager.getString(
364                                 "label.opt_and_params_further_details")
365                         : "")));
366       }
367
368       JvSwingUtils.mgAddtoLayout(this, ttipText, new JLabel(parm.getName()),
369               controlPanel, "");
370       updateControls(parm);
371       validate();
372     }
373
374     private void makeExpanderParam(ParameterI parm)
375     {
376       setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
377       setBorder(new TitledBorder(parm.getName()));
378       setLayout(null);
379       showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
380       showDesc.setText("+");
381       string.setFont(new Font("Verdana", Font.PLAIN, 11));
382       string.setBackground(getBackground());
383
384       string.setEditable(false);
385       descPanel.getViewport().setView(string);
386
387       descPanel.setVisible(false);
388
389       JPanel firstrow = new JPanel();
390       firstrow.setLayout(null);
391       controlPanel.setLayout(new BorderLayout());
392       controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
393               PARAM_CLOSEDHEIGHT - 50));
394       firstrow.add(controlPanel);
395       firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
396               PARAM_CLOSEDHEIGHT - 30));
397
398       final ParamBox me = this;
399
400       if (parm.getDescription() != null
401               && parm.getDescription().trim().length() > 0)
402       {
403         // Only create description boxes if there actually is a description.
404         if (finfo != null)
405         {
406           showDesc.setToolTipText(JvSwingUtils.wrapTooltip(true,
407                   MessageManager.formatMessage(
408                           "label.opt_and_params_show_brief_desc_image_link",
409                           new String[]
410                           { linkImageURL.toExternalForm() })));
411           showDesc.addMouseListener(this);
412         }
413         else
414         {
415           showDesc.setToolTipText(
416                   JvSwingUtils.wrapTooltip(true, MessageManager.getString(
417                           "label.opt_and_params_show_brief_desc")));
418         }
419         showDesc.addActionListener(new ActionListener()
420         {
421
422           @Override
423           public void actionPerformed(ActionEvent e)
424           {
425             descisvisible = !descisvisible;
426             descPanel.setVisible(descisvisible);
427             descPanel.getVerticalScrollBar().setValue(0);
428             me.setPreferredSize(new Dimension(PARAM_WIDTH,
429                     (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
430             me.validate();
431             pmdialogbox.refreshParamLayout();
432           }
433         });
434         string.setWrapStyleWord(true);
435         string.setLineWrap(true);
436         string.setColumns(32);
437         string.setText(parm.getDescription());
438         showDesc.setBounds(new Rectangle(10, 10, 16, 16));
439         firstrow.add(showDesc);
440       }
441       add(firstrow);
442       validator = parm.getValidValue();
443       parameter = parm;
444       if (validator != null)
445       {
446         integ = validator.getType() == ValueType.Integer;
447       }
448       else
449       {
450         if (parameter.getPossibleValues() != null)
451         {
452           choice = true;
453         }
454       }
455       updateControls(parm);
456       descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
457               PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
458       add(descPanel);
459       validate();
460     }
461
462     @Override
463     public void actionPerformed(ActionEvent e)
464     {
465       if (adjusting)
466       {
467         return;
468       }
469       if (!choice)
470       {
471         updateSliderFromValueField();
472       }
473       checkIfModified();
474     }
475
476     private void checkIfModified()
477     {
478       Object cstate = updateSliderFromValueField();
479       boolean notmod = false;
480       if (cstate.getClass() == lastVal.getClass())
481       {
482         if (cstate instanceof int[])
483         {
484           notmod = (((int[]) cstate)[0] == ((int[]) lastVal)[0]);
485         }
486         else if (cstate instanceof float[])
487         {
488           notmod = (((float[]) cstate)[0] == ((float[]) lastVal)[0]);
489         }
490         else if (cstate instanceof String[])
491         {
492           notmod = (((String[]) cstate)[0].equals(((String[]) lastVal)[0]));
493         }
494       }
495       pmdialogbox.argSetModified(this, !notmod);
496     }
497
498     @Override
499     public int getBaseline(int width, int height)
500     {
501       return 0;
502     }
503
504     // from
505     // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
506     // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
507     @Override
508     public Component.BaselineResizeBehavior getBaselineResizeBehavior()
509     {
510       return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
511     }
512
513     public int getBoxHeight()
514     {
515       return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
516     }
517
518     public ParameterI getParameter()
519     {
520       ParameterI prm = parameter.copy();
521       if (choice)
522       {
523         prm.setValue((String) choicebox.getSelectedItem());
524       }
525       else
526       {
527         prm.setValue(valueField.getText());
528       }
529       return prm;
530     }
531
532     public void init()
533     {
534       // reset the widget's initial value.
535       lastVal = null;
536     }
537
538     @Override
539     public void mouseClicked(MouseEvent e)
540     {
541       if (e.isPopupTrigger()) // for Windows
542       {
543         showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
544       }
545     }
546
547     @Override
548     public void mouseEntered(MouseEvent e)
549     {
550       // TODO Auto-generated method stub
551
552     }
553
554     @Override
555     public void mouseExited(MouseEvent e)
556     {
557       // TODO Auto-generated method stub
558
559     }
560
561     @Override
562     public void mousePressed(MouseEvent e)
563     {
564       if (e.isPopupTrigger()) // for Mac
565       {
566         showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
567       }
568     }
569
570     @Override
571     public void mouseReleased(MouseEvent e)
572     {
573       // TODO Auto-generated method stub
574
575     }
576
577     @Override
578     public void stateChanged(ChangeEvent e)
579     {
580       if (!adjusting)
581       {
582         if (!isLogarithmic)
583         {
584           valueField.setText("" + ((integ) ? ("" + slider.getValue())
585                   : ("" + slider.getValue() / 1000f)));
586         }
587         else
588         {
589           Double base = ((LogarithmicParameter) parameter).getBase();
590           Double value = Math.pow(
591                   base,
592                   slider.getValue());
593           valueField.setText(formatDouble(value));
594         }
595         checkIfModified();
596       }
597
598     }
599
600     public String formatDouble(Double value)
601     {
602       String string = "";
603       if (value < 0.0001)
604       {
605         string = String.format("%3.3e", value);
606       }
607       else
608       {
609         string = value.toString();
610       }
611       return string;
612     }
613
614     public void updateControls(ParameterI parm)
615     {
616       adjusting = true;
617       boolean init = (choicebox == null && valueField == null);
618       if (init)
619       {
620         if (choice)
621         {
622           choicebox = new JComboBox();
623           choicebox.addActionListener(this);
624           controlPanel.add(choicebox, BorderLayout.CENTER);
625         }
626         else
627         {
628           slider = new JSlider();
629           slider.addChangeListener(this);
630           valueField = new JTextField();
631           valueField.addActionListener(this);
632           valueField.addKeyListener(new KeyListener()
633           {
634
635             @Override
636             public void keyTyped(KeyEvent e)
637             {
638             }
639
640             @Override
641             public void keyReleased(KeyEvent e)
642             {
643               if (e.isActionKey())
644               {
645                 if (valueField.getText().trim().length() > 0)
646                 {
647                   actionPerformed(null);
648                 }
649               }
650             }
651
652             @Override
653             public void keyPressed(KeyEvent e)
654             {
655             }
656           });
657           valueField.setPreferredSize(new Dimension(60, 25));
658           controlPanel.add(slider, BorderLayout.WEST);
659           controlPanel.add(valueField, BorderLayout.EAST);
660
661         }
662       }
663
664       if (parm != null)
665       {
666         if (choice)
667         {
668           if (init)
669           {
670             List vals = parm.getPossibleValues();
671             for (Object val : vals)
672             {
673               choicebox.addItem(val);
674             }
675           }
676
677           if (parm.getValue() != null)
678           {
679             choicebox.setSelectedItem(parm.getValue());
680           }
681         }
682         else
683         {
684           valueField.setText(parm.getValue());
685         }
686       }
687       lastVal = updateSliderFromValueField();
688       adjusting = false;
689     }
690
691     public Object updateSliderFromValueField()
692     {
693       int iVal;
694       float fVal;
695       double dVal;
696       if (validator != null)
697       {
698         if (integ)
699         {
700           iVal = 0;
701           try
702           {
703             valueField.setText(valueField.getText().trim());
704             iVal = Integer.valueOf(valueField.getText());
705             if (validator.getMin() != null
706                     && validator.getMin().intValue() > iVal)
707             {
708               iVal = validator.getMin().intValue();
709               // TODO: provide visual indication that hard limit was reached for
710               // this parameter
711             }
712             if (validator.getMax() != null
713                     && validator.getMax().intValue() < iVal)
714             {
715               iVal = validator.getMax().intValue();
716               // TODO: provide visual indication that hard limit was reached for
717               // this parameter
718             }
719           } catch (Exception e)
720           {
721           }
722           ;
723           // update value field to reflect any bound checking we performed.
724           valueField.setText("" + iVal);
725           if (validator.getMin() != null && validator.getMax() != null)
726           {
727             slider.getModel().setRangeProperties(iVal, 1,
728                     validator.getMin().intValue(),
729                     validator.getMax().intValue() + 1, true);
730           }
731           else
732           {
733             slider.setVisible(false);
734           }
735           return new int[] { iVal };
736         }
737         else if (isLogarithmic)
738         {
739           double eValue;
740           dVal = 0d;
741           try
742           {
743             valueField.setText(valueField.getText().trim());
744             eValue = Double.valueOf(valueField.getText());
745
746             dVal = Math.log(eValue) / Math
747                     .log(((LogarithmicParameter) parameter).getBase());
748
749             if (validator.getMin() != null
750                     && validator.getMin().doubleValue() > dVal)
751             {
752               dVal = validator.getMin().doubleValue();
753               // TODO: provide visual indication that hard limit was reached for
754               // this parameter
755               // update value field to reflect any bound checking we performed.
756               valueField.setText("" + formatDouble(eValue));
757             }
758             if (validator.getMax() != null
759                     && validator.getMax().doubleValue() < dVal)
760             {
761               dVal = validator.getMax().doubleValue();
762               // TODO: provide visual indication that hard limit was reached for
763               // this parameter
764               // update value field to reflect any bound checking we performed.
765               valueField.setText("" + formatDouble(eValue));
766             }
767           } catch (Exception e)
768           {
769           }
770           ;
771           if (validator.getMin() != null && validator.getMax() != null)
772           {
773             slider.getModel().setRangeProperties((int) (dVal), 1,
774                     (int) (validator.getMin().doubleValue()),
775                     1 + (int) (validator.getMax().doubleValue()),
776                     true);
777           }
778           else
779           {
780             slider.setVisible(false);
781           }
782           return new double[] { dVal };
783         }
784         else
785         {
786           fVal = 0f;
787           try
788           {
789             valueField.setText(valueField.getText().trim());
790             fVal = Float.valueOf(valueField.getText());
791             if (validator.getMin() != null
792                     && validator.getMin().floatValue() > fVal)
793             {
794               fVal = validator.getMin().floatValue();
795               // TODO: provide visual indication that hard limit was reached for
796               // this parameter
797               // update value field to reflect any bound checking we performed.
798               valueField.setText("" + fVal);
799             }
800             if (validator.getMax() != null
801                     && validator.getMax().floatValue() < fVal)
802             {
803               fVal = validator.getMax().floatValue();
804               // TODO: provide visual indication that hard limit was reached for
805               // this parameter
806               // update value field to reflect any bound checking we performed.
807               valueField.setText("" + fVal);
808             }
809           } catch (Exception e)
810           {
811           }
812           ;
813           if (validator.getMin() != null && validator.getMax() != null)
814           {
815             slider.getModel().setRangeProperties((int) (fVal * 1000f), 1,
816                     (int) (validator.getMin().floatValue() * 1000f),
817                     1 + (int) (validator.getMax().floatValue() * 1000f),
818                     true);
819           }
820           else
821           {
822             slider.setVisible(false);
823           }
824           return new float[] { fVal };
825         }
826       }
827       else
828       {
829         if (!choice)
830         {
831           slider.setVisible(false);
832           return new String[] { valueField.getText().trim() };
833         }
834         else
835         {
836           return new String[] { (String) choicebox.getSelectedItem() };
837         }
838       }
839
840     }
841   }
842
843   public static final int PARAM_WIDTH = 340;
844
845   public static final int PARAM_HEIGHT = 150;
846
847   public static final int PARAM_CLOSEDHEIGHT = 80;
848
849   public OptsAndParamsPage(OptsParametersContainerI paramContainer)
850   {
851     this(paramContainer, false);
852   }
853
854   public OptsAndParamsPage(OptsParametersContainerI paramContainer,
855           boolean compact)
856   {
857     poparent = paramContainer;
858     this.compact = compact;
859   }
860
861   public static void showUrlPopUp(JComponent invoker, final String finfo,
862           int x, int y)
863   {
864
865     JPopupMenu mnu = new JPopupMenu();
866     JMenuItem mitem = new JMenuItem(
867             MessageManager.formatMessage("label.view_params", new String[]
868             { finfo }));
869     mitem.addActionListener(new ActionListener()
870     {
871
872       @Override
873       public void actionPerformed(ActionEvent e)
874       {
875         Desktop.showUrl(finfo);
876
877       }
878     });
879     mnu.add(mitem);
880     mnu.show(invoker, x, y);
881   }
882
883   URL linkImageURL = getClass().getResource("/images/link.gif");
884
885   Map<String, OptionBox> optSet = new java.util.LinkedHashMap<>();
886
887   Map<String, ParamBox> paramSet = new java.util.LinkedHashMap<>();
888
889   public Map<String, OptionBox> getOptSet()
890   {
891     return optSet;
892   }
893
894   public void setOptSet(Map<String, OptionBox> optSet)
895   {
896     this.optSet = optSet;
897   }
898
899   public Map<String, ParamBox> getParamSet()
900   {
901     return paramSet;
902   }
903
904   public void setParamSet(Map<String, ParamBox> paramSet)
905   {
906     this.paramSet = paramSet;
907   }
908
909   OptsParametersContainerI poparent;
910
911   OptionBox addOption(OptionI opt)
912   {
913     OptionBox cb = optSet.get(opt.getName());
914     if (cb == null)
915     {
916       cb = new OptionBox(opt);
917       optSet.put(opt.getName(), cb);
918       // jobOptions.add(cb, FlowLayout.LEFT);
919     }
920     return cb;
921   }
922
923   ParamBox addParameter(ParameterI arg)
924   {
925     ParamBox pb = paramSet.get(arg.getName());
926     if (pb == null)
927     {
928       pb = new ParamBox(poparent, arg);
929       paramSet.put(arg.getName(), pb);
930       // paramList.add(pb);
931     }
932     pb.init();
933     // take the defaults from the parameter
934     pb.updateControls(arg);
935     return pb;
936   }
937
938   void selectOption(OptionI option, String string)
939   {
940     OptionBox cb = optSet.get(option.getName());
941     if (cb == null)
942     {
943       cb = addOption(option);
944     }
945     cb.enabled.setSelected(string != null); // initial state for an option.
946     if (string != null)
947     {
948       if (option.getPossibleValues().contains(string))
949       {
950         cb.val.setSelectedItem(string);
951       }
952       else
953       {
954         throw new Error(MessageManager.formatMessage(
955                 "error.invalid_value_for_option", new String[]
956                 { string, option.getName() }));
957       }
958
959     }
960     if (option.isRequired() && !cb.enabled.isSelected())
961     {
962       // TODO: indicate paramset is not valid.. option needs to be selected!
963     }
964     cb.setInitialValue();
965   }
966
967   void setParameter(ParameterI arg)
968   {
969     ParamBox pb = paramSet.get(arg.getName());
970     if (pb == null)
971     {
972       addParameter(arg);
973     }
974     else
975     {
976       pb.updateControls(arg);
977     }
978
979   }
980
981   /**
982    * recover options and parameters from GUI
983    * 
984    * @return
985    */
986   public List<ArgumentI> getCurrentSettings()
987   {
988     List<ArgumentI> argSet = new ArrayList<>();
989     for (OptionBox opts : getOptSet().values())
990     {
991       OptionI opt = opts.getOptionIfEnabled();
992       if (opt != null)
993       {
994         argSet.add(opt);
995       }
996     }
997     for (ParamBox parambox : getParamSet().values())
998     {
999       ParameterI parm = parambox.getParameter();
1000       if (parm != null)
1001       {
1002         argSet.add(parm);
1003       }
1004     }
1005
1006     return argSet;
1007   }
1008
1009 }