JAL-2629 adjust parameter min and max to better suit HMMER ranges
[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 = String.format("%2.3f", value);
603       if (value < 0.001)
604       {
605         string = String.format("%3.3e", value);
606       }
607       return string;
608     }
609
610     public void updateControls(ParameterI parm)
611     {
612       adjusting = true;
613       boolean init = (choicebox == null && valueField == null);
614       if (init)
615       {
616         if (choice)
617         {
618           choicebox = new JComboBox();
619           choicebox.addActionListener(this);
620           controlPanel.add(choicebox, BorderLayout.CENTER);
621         }
622         else
623         {
624           slider = new JSlider();
625           slider.addChangeListener(this);
626           valueField = new JTextField();
627           valueField.addActionListener(this);
628           valueField.addKeyListener(new KeyListener()
629           {
630
631             @Override
632             public void keyTyped(KeyEvent e)
633             {
634             }
635
636             @Override
637             public void keyReleased(KeyEvent e)
638             {
639               if (e.isActionKey())
640               {
641                 if (valueField.getText().trim().length() > 0)
642                 {
643                   actionPerformed(null);
644                 }
645               }
646             }
647
648             @Override
649             public void keyPressed(KeyEvent e)
650             {
651             }
652           });
653           valueField.setPreferredSize(new Dimension(60, 25));
654           controlPanel.add(slider, BorderLayout.WEST);
655           controlPanel.add(valueField, BorderLayout.EAST);
656
657         }
658       }
659
660       if (parm != null)
661       {
662         if (choice)
663         {
664           if (init)
665           {
666             List vals = parm.getPossibleValues();
667             for (Object val : vals)
668             {
669               choicebox.addItem(val);
670             }
671           }
672
673           if (parm.getValue() != null)
674           {
675             choicebox.setSelectedItem(parm.getValue());
676           }
677         }
678         else
679         {
680           if (parm instanceof LogarithmicParameter)
681           {
682             Double base = ((LogarithmicParameter) parm).getBase();
683             Double value = Math.pow(base,
684                     Double.parseDouble(parm.getValue()));
685             valueField.setText(formatDouble(value));
686           }
687           else
688           {
689             valueField.setText(parm.getValue());
690           }
691         }
692       }
693       lastVal = updateSliderFromValueField();
694       adjusting = false;
695     }
696
697     public Object updateSliderFromValueField()
698     {
699       int iVal;
700       float fVal;
701       double dVal;
702       if (validator != null)
703       {
704         if (integ)
705         {
706           iVal = 0;
707           try
708           {
709             valueField.setText(valueField.getText().trim());
710             iVal = Integer.valueOf(valueField.getText());
711             if (validator.getMin() != null
712                     && validator.getMin().intValue() > iVal)
713             {
714               iVal = validator.getMin().intValue();
715               // TODO: provide visual indication that hard limit was reached for
716               // this parameter
717             }
718             if (validator.getMax() != null
719                     && validator.getMax().intValue() < iVal)
720             {
721               iVal = validator.getMax().intValue();
722               // TODO: provide visual indication that hard limit was reached for
723               // this parameter
724             }
725           } catch (Exception e)
726           {
727           }
728           ;
729           // update value field to reflect any bound checking we performed.
730           valueField.setText("" + iVal);
731           if (validator.getMin() != null && validator.getMax() != null)
732           {
733             slider.getModel().setRangeProperties(iVal, 1,
734                     validator.getMin().intValue(),
735                     validator.getMax().intValue() + 1, true);
736           }
737           else
738           {
739             slider.setVisible(false);
740           }
741           return new int[] { iVal };
742         }
743         else if (isLogarithmic)
744         {
745           double eValue;
746           dVal = 0d;
747           try
748           {
749             valueField.setText(valueField.getText().trim());
750             eValue = Double.valueOf(valueField.getText());
751
752             dVal = Math.log(eValue) / Math
753                     .log(((LogarithmicParameter) parameter).getBase());
754
755             if (validator.getMin() != null
756                     && validator.getMin().doubleValue() > dVal)
757             {
758               dVal = validator.getMin().doubleValue();
759               // TODO: provide visual indication that hard limit was reached for
760               // this parameter
761               // update value field to reflect any bound checking we performed.
762               valueField.setText("" + formatDouble(eValue));
763             }
764             if (validator.getMax() != null
765                     && validator.getMax().doubleValue() < dVal)
766             {
767               dVal = validator.getMax().doubleValue();
768               // TODO: provide visual indication that hard limit was reached for
769               // this parameter
770               // update value field to reflect any bound checking we performed.
771               valueField.setText("" + formatDouble(eValue));
772             }
773           } catch (Exception e)
774           {
775           }
776           ;
777           if (validator.getMin() != null && validator.getMax() != null)
778           {
779             slider.getModel().setRangeProperties((int) (dVal), 1,
780                     (int) (validator.getMin().doubleValue()),
781                     1 + (int) (validator.getMax().doubleValue()),
782                     true);
783           }
784           else
785           {
786             slider.setVisible(false);
787           }
788           return new double[] { dVal };
789         }
790         else
791         {
792           fVal = 0f;
793           try
794           {
795             valueField.setText(valueField.getText().trim());
796             fVal = Float.valueOf(valueField.getText());
797             if (validator.getMin() != null
798                     && validator.getMin().floatValue() > fVal)
799             {
800               fVal = validator.getMin().floatValue();
801               // TODO: provide visual indication that hard limit was reached for
802               // this parameter
803               // update value field to reflect any bound checking we performed.
804               valueField.setText("" + fVal);
805             }
806             if (validator.getMax() != null
807                     && validator.getMax().floatValue() < fVal)
808             {
809               fVal = validator.getMax().floatValue();
810               // TODO: provide visual indication that hard limit was reached for
811               // this parameter
812               // update value field to reflect any bound checking we performed.
813               valueField.setText("" + fVal);
814             }
815           } catch (Exception e)
816           {
817           }
818           ;
819           if (validator.getMin() != null && validator.getMax() != null)
820           {
821             slider.getModel().setRangeProperties((int) (fVal * 1000f), 1,
822                     (int) (validator.getMin().floatValue() * 1000f),
823                     1 + (int) (validator.getMax().floatValue() * 1000f),
824                     true);
825           }
826           else
827           {
828             slider.setVisible(false);
829           }
830           return new float[] { fVal };
831         }
832       }
833       else
834       {
835         if (!choice)
836         {
837           slider.setVisible(false);
838           return new String[] { valueField.getText().trim() };
839         }
840         else
841         {
842           return new String[] { (String) choicebox.getSelectedItem() };
843         }
844       }
845
846     }
847   }
848
849   public static final int PARAM_WIDTH = 340;
850
851   public static final int PARAM_HEIGHT = 150;
852
853   public static final int PARAM_CLOSEDHEIGHT = 80;
854
855   public OptsAndParamsPage(OptsParametersContainerI paramContainer)
856   {
857     this(paramContainer, false);
858   }
859
860   public OptsAndParamsPage(OptsParametersContainerI paramContainer,
861           boolean compact)
862   {
863     poparent = paramContainer;
864     this.compact = compact;
865   }
866
867   public static void showUrlPopUp(JComponent invoker, final String finfo,
868           int x, int y)
869   {
870
871     JPopupMenu mnu = new JPopupMenu();
872     JMenuItem mitem = new JMenuItem(
873             MessageManager.formatMessage("label.view_params", new String[]
874             { finfo }));
875     mitem.addActionListener(new ActionListener()
876     {
877
878       @Override
879       public void actionPerformed(ActionEvent e)
880       {
881         Desktop.showUrl(finfo);
882
883       }
884     });
885     mnu.add(mitem);
886     mnu.show(invoker, x, y);
887   }
888
889   URL linkImageURL = getClass().getResource("/images/link.gif");
890
891   Map<String, OptionBox> optSet = new java.util.LinkedHashMap<>();
892
893   Map<String, ParamBox> paramSet = new java.util.LinkedHashMap<>();
894
895   public Map<String, OptionBox> getOptSet()
896   {
897     return optSet;
898   }
899
900   public void setOptSet(Map<String, OptionBox> optSet)
901   {
902     this.optSet = optSet;
903   }
904
905   public Map<String, ParamBox> getParamSet()
906   {
907     return paramSet;
908   }
909
910   public void setParamSet(Map<String, ParamBox> paramSet)
911   {
912     this.paramSet = paramSet;
913   }
914
915   OptsParametersContainerI poparent;
916
917   OptionBox addOption(OptionI opt)
918   {
919     OptionBox cb = optSet.get(opt.getName());
920     if (cb == null)
921     {
922       cb = new OptionBox(opt);
923       optSet.put(opt.getName(), cb);
924       // jobOptions.add(cb, FlowLayout.LEFT);
925     }
926     return cb;
927   }
928
929   ParamBox addParameter(ParameterI arg)
930   {
931     ParamBox pb = paramSet.get(arg.getName());
932     if (pb == null)
933     {
934       pb = new ParamBox(poparent, arg);
935       paramSet.put(arg.getName(), pb);
936       // paramList.add(pb);
937     }
938     pb.init();
939     // take the defaults from the parameter
940     pb.updateControls(arg);
941     return pb;
942   }
943
944   void selectOption(OptionI option, String string)
945   {
946     OptionBox cb = optSet.get(option.getName());
947     if (cb == null)
948     {
949       cb = addOption(option);
950     }
951     cb.enabled.setSelected(string != null); // initial state for an option.
952     if (string != null)
953     {
954       if (option.getPossibleValues().contains(string))
955       {
956         cb.val.setSelectedItem(string);
957       }
958       else
959       {
960         throw new Error(MessageManager.formatMessage(
961                 "error.invalid_value_for_option", new String[]
962                 { string, option.getName() }));
963       }
964
965     }
966     if (option.isRequired() && !cb.enabled.isSelected())
967     {
968       // TODO: indicate paramset is not valid.. option needs to be selected!
969     }
970     cb.setInitialValue();
971   }
972
973   void setParameter(ParameterI arg)
974   {
975     ParamBox pb = paramSet.get(arg.getName());
976     if (pb == null)
977     {
978       addParameter(arg);
979     }
980     else
981     {
982       pb.updateControls(arg);
983     }
984
985   }
986
987   /**
988    * recover options and parameters from GUI
989    * 
990    * @return
991    */
992   public List<ArgumentI> getCurrentSettings()
993   {
994     List<ArgumentI> argSet = new ArrayList<>();
995     for (OptionBox opts : getOptSet().values())
996     {
997       OptionI opt = opts.getOptionIfEnabled();
998       if (opt != null)
999       {
1000         argSet.add(opt);
1001       }
1002     }
1003     for (ParamBox parambox : getParamSet().values())
1004     {
1005       ParameterI parm = parambox.getParameter();
1006       if (parm != null)
1007       {
1008         argSet.add(parm);
1009       }
1010     }
1011
1012     return argSet;
1013   }
1014
1015 }