Clover icon

jalviewX

  1. Project Clover database Wed Oct 31 2018 15:13:58 GMT
  2. Package jalview.gui

File OptsAndParamsPage.java

 

Coverage histogram

../../img/srcFileCovDistChart0.png
56% of files have more coverage

Code metrics

130
266
46
3
928
748
128
0.48
5.78
15.33
2.78

Classes

Class Line # Actions
OptsAndParamsPage 72 49 23 80
0.00%
OptsAndParamsPage.OptionBox 79 55 34 100
0.00%
OptsAndParamsPage.ParamBox 273 162 71 262
0.00%
 

Contributing tests

No tests hitting this source file were found.

Source view

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