3 import java.awt.BorderLayout;
5 import java.awt.Component;
6 import java.awt.Dimension;
7 import java.awt.FlowLayout;
9 import java.awt.GridLayout;
10 import java.awt.Rectangle;
11 import java.awt.event.ActionEvent;
12 import java.awt.event.ActionListener;
13 import java.awt.event.ComponentEvent;
14 import java.awt.event.ComponentListener;
15 import java.awt.event.ContainerEvent;
16 import java.awt.event.ContainerListener;
17 import java.awt.event.ItemEvent;
18 import java.awt.event.ItemListener;
19 import java.awt.event.KeyEvent;
20 import java.awt.event.KeyListener;
21 import java.awt.event.MouseEvent;
22 import java.awt.event.MouseListener;
23 import java.awt.event.WindowEvent;
24 import java.awt.event.WindowListener;
25 import java.awt.event.WindowStateListener;
27 import java.util.ArrayList;
28 import java.util.EventObject;
29 import java.util.HashSet;
30 import java.util.Hashtable;
31 import java.util.Iterator;
32 import java.util.List;
34 import java.util.Vector;
36 import javax.swing.JButton;
37 import javax.swing.JCheckBox;
38 import javax.swing.JComboBox;
39 import javax.swing.JComponent;
40 import javax.swing.JDialog;
41 import javax.swing.JFrame;
42 import javax.swing.JLabel;
43 import javax.swing.JList;
44 import javax.swing.JMenuItem;
45 import javax.swing.JOptionPane;
46 import javax.swing.JPanel;
47 import javax.swing.JPopupMenu;
48 import javax.swing.JScrollPane;
49 import javax.swing.JSlider;
50 import javax.swing.JSplitPane;
51 import javax.swing.JTable;
52 import javax.swing.JTextArea;
53 import javax.swing.JTextField;
54 import javax.swing.ListSelectionModel;
55 import javax.swing.SwingConstants;
56 import javax.swing.SwingUtilities;
57 import javax.swing.border.TitledBorder;
58 import javax.swing.event.CellEditorListener;
59 import javax.swing.event.ChangeEvent;
60 import javax.swing.event.ChangeListener;
61 import javax.swing.event.DocumentEvent;
62 import javax.swing.event.DocumentListener;
63 import javax.swing.table.*;
65 import compbio.metadata.Argument;
66 import compbio.metadata.Option;
67 import compbio.metadata.Parameter;
68 import compbio.metadata.Preset;
69 import compbio.metadata.PresetManager;
70 import compbio.metadata.RunnerConfig;
71 import compbio.metadata.ValueConstrain;
72 import compbio.metadata.WrongParameterException;
73 import compbio.metadata.ValueConstrain.Type;
75 import jalview.util.jarInputStreamProvider;
76 import jalview.ws.jws2.Jws2Discoverer;
77 import jalview.ws.jws2.ParameterUtils;
78 import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
81 * job parameter editing/browsing dialog box. User can browse existing settings
82 * (user + presets + Defaults), and any changes to parameters creates a modified
83 * user parameter set. LOGIC: If the parameter set is modified, and its name is
84 * a valid, non-existant user parameter set, then a save button is shown. If the
85 * parameter set is modified and its name is a valid, extant user parameter set,
86 * then an update button is shown. If user parameter set's name is edited, and
87 * old name exists as a writable user parameter set, then rename button is
88 * shown. If current parameter set is associated with a user defined parameter
89 * set, then : if set is modifed, a 'revert' button is shown. if set is not
90 * modified, a 'delete' button is shown.
95 public class WsJobParameters extends JPanel implements ItemListener,
96 ActionListener, DocumentListener
98 private static final String SVC_DEF = "Defaults"; // this is the null
99 // parameter set as shown to
102 private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 150,
103 PARAM_CLOSEDHEIGHT = 80;
105 private static final int OPTSET_HEIGHT = 30;
107 JPanel SetNamePanel = new JPanel();
109 JPanel setDetails = new JPanel();
111 JSplitPane settingsPanel = new JSplitPane();
113 JSplitPane jobPanel = new JSplitPane();
115 JPanel jobOptions = new JPanel();
117 JScrollPane jobOptionsPane = new JScrollPane();
119 JPanel jobParameters = new JPanel();
121 JButton savmodified = new JButton();
123 JButton renmodified = new JButton();
125 JButton deletesetting = new JButton();
127 JButton revertsetting = new JButton();
129 JButton startjob = new JButton();
131 JButton canceljob = new JButton();
133 JComboBox setName = new JComboBox();
135 JTextArea setDescr = new JTextArea();
137 JScrollPane paramPane = new JScrollPane();
139 // JList paramList = new JList();
140 JPanel paramList = new JPanel();
142 RunnerConfig serviceOptions;
144 private BorderLayout jparamLayout;
146 WsJobParameters(Jws2Instance service)
151 public WsJobParameters(Jws2Instance service, Preset p)
153 this(null, service, p, null);
159 * - if null, create new JFrame outside of desktop
163 public WsJobParameters(JFrame parent, Jws2Instance service, Preset p,
164 List<Argument> jobArgset)
168 // argSetModified(false);
169 // populate parameter table
170 initForService(service, p, jobArgset);
171 // display in new JFrame attached to parent.
177 JDialog frame = null;
180 * shows a modal dialog containing the parameters.
184 public boolean showRunDialog()
187 frame = new JDialog(Desktop.instance, true);
189 frame.setTitle("Edit parameters for " + service.getActionText());
190 Rectangle deskr = Desktop.instance.getBounds();
191 frame.setBounds(new Rectangle((int) (deskr.getCenterX() - 240),
192 (int) (deskr.getCenterY() - 250), 480, 500));
193 frame.setContentPane(this);
194 // should recover defaults from user prefs.
196 settingsPanel.setDividerLocation(0.4);
197 jobPanel.setDividerLocation(0.3);
198 frame.setVisible(true);
207 protected JButton makeButton(String label, String tooltip,
208 ActionListener action)
210 JButton button = new JButton();
211 button.setText(label);
212 button.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
213 button.setForeground(Color.black);
214 button.setHorizontalAlignment(SwingConstants.CENTER);
215 button.setToolTipText(tooltip);
216 button.addActionListener(action);
220 private void jbInit()
222 savmodified = makeButton("Save", "Not implemented yet :) ",
226 public void actionPerformed(ActionEvent e)
228 savModified_actionPerformed(e);
231 renmodified = makeButton("Rename", "Not implemented yet :) ",
235 public void actionPerformed(ActionEvent e)
237 renModified_actionPerformed(e);
240 deletesetting = makeButton("Delete", "Not implemented yet :) ",
244 public void actionPerformed(ActionEvent e)
246 deleteSetting_actionPerformed(e);
249 revertsetting = makeButton("Revert", "Undo changes to parameters.",
253 public void actionPerformed(ActionEvent e)
255 revertSetting_actionPerformed(e);
259 startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
260 startjob.setText("Start");
261 startjob.setToolTipText("Start Job");
262 startjob.addActionListener(new ActionListener()
264 public void actionPerformed(ActionEvent e)
266 startjob_actionPerformed(e);
269 canceljob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
270 canceljob.setText("Cancel");
271 canceljob.setToolTipText("Cancel Job");
272 canceljob.addActionListener(new ActionListener()
274 public void actionPerformed(ActionEvent e)
276 canceljob_actionPerformed(e);
280 setDetails.setBorder(new TitledBorder("Details"));
281 setDetails.setLayout(new BorderLayout());
282 setDescr.setColumns(40);
283 setDescr.setWrapStyleWord(true);
284 setDescr.setLineWrap(true);
285 setDescr.setBackground(getBackground());
286 setDescr.setEditable(true);
287 setDescr.getDocument().addDocumentListener(this);
288 JScrollPane setDescrView = new JScrollPane();
289 // setDescrView.setPreferredSize(new Dimension(350, 200));
290 setDescrView.getViewport().setView(setDescr);
291 setName.setEditable(true);
292 setName.addItemListener(this);
293 setName.getEditor().addActionListener(this);
294 SetNamePanel.setLayout(new BorderLayout());
295 SetNamePanel.add(setName, BorderLayout.WEST);
296 // initial button visibility
297 deletesetting.setVisible(false);
298 revertsetting.setVisible(false);
299 renmodified.setVisible(false);
300 savmodified.setVisible(false);
301 JPanel setsavebuts = new JPanel();
302 setsavebuts.setLayout(new FlowLayout());
303 setsavebuts.add(revertsetting, BorderLayout.CENTER);
304 setsavebuts.add(renmodified, BorderLayout.CENTER);
305 setsavebuts.add(deletesetting, BorderLayout.CENTER);
306 setsavebuts.add(savmodified, BorderLayout.EAST);
307 SetNamePanel.add(setsavebuts, BorderLayout.EAST);
308 setDetails.add(setDescrView, BorderLayout.CENTER);
309 // setDetails.setPreferredSize(new Dimension(360, 100));
310 jobParameters.setBorder(new TitledBorder("Parameters"));
311 jobParameters.setLayout(jparamLayout = new BorderLayout());
312 paramPane.setPreferredSize(new Dimension(360, 300));
313 paramPane.getVerticalScrollBar().setUnitIncrement(20);
314 // paramPanel.setPreferredSize(new Dimension(360, 300));
315 // TODO: relayout buttons nicely
316 paramPane.getViewport().setView(paramList);
317 jobParameters.add(paramPane, BorderLayout.CENTER);
318 JPanel jobOptionsPanel = new JPanel();
319 jobOptionsPanel.setLayout(new BorderLayout());
320 jobOptionsPanel.setBorder(new TitledBorder("Options"));
321 jobOptionsPane.getViewport().setView(jobOptions);
322 jobOptionsPanel.add(jobOptionsPane, BorderLayout.CENTER);
323 settingsPanel.setLeftComponent(jobOptionsPanel);
324 settingsPanel.setRightComponent(jobParameters);
325 settingsPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
327 setLayout(new BorderLayout());
328 // setPreferredSize(new Dimension(400, 600));
329 // setSize(new Dimension(400, 600));
330 jobPanel.setLeftComponent(setDetails);
331 jobPanel.setRightComponent(settingsPanel);
332 jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
333 add(SetNamePanel, BorderLayout.NORTH);
334 add(jobPanel, BorderLayout.CENTER);
335 JPanel dialogpanel = new JPanel();
336 dialogpanel.add(startjob);
337 dialogpanel.add(canceljob);
338 add(dialogpanel, BorderLayout.SOUTH);
341 protected void revertSetting_actionPerformed(ActionEvent e)
343 // TODO Auto-generated method stub
347 protected void deleteSetting_actionPerformed(ActionEvent e)
349 String setname = (String) setName.getSelectedItem();
350 int p = setName.getSelectedIndex();
351 if (_getUserPreset(setname) != null)
353 _deleteUserPreset(setname);
356 if (p > 0 && p + 1 == setName.getItemCount())
360 setName.setSelectedIndex(p);
364 protected void renModified_actionPerformed(ActionEvent e)
366 if (curSetName == null || _getUserPreset(lastSetName) == null)
369 .println("can't rename - names unchanged or original name not a preset.");
372 _deleteUserPreset(lastSetName);
373 lastSetName = curSetName;
374 savModified_actionPerformed(e);
376 boolean setd = settingDialog;
377 settingDialog = true;
378 syncSetNamesWithStore();
379 settingDialog = setd;
382 protected void savModified_actionPerformed(ActionEvent e)
384 _storeUserPreset(lastSetName=(String) setName.getSelectedItem(), setDescr.getText(), getJobParams());
386 initArgSetModified(); // reset the modification state
389 protected void canceljob_actionPerformed(ActionEvent e)
394 frame.setVisible(false);
398 protected void startjob_actionPerformed(ActionEvent e)
403 frame.setVisible(false);
407 Jws2Instance service;
410 * list of service presets in the gui
412 Hashtable servicePresets = null;
415 * set if dialog is being set - so handlers will avoid spurious events
417 boolean settingDialog = false;
419 void initForService(Jws2Instance service, Preset p,
420 List<Argument> jobArgset)
422 settingDialog = true;
423 this.service = service;
424 // TODO: Recover window geometry prefs for this service
425 // jobPanel.setDividerLocation(proportionalLocation)
426 // settingsPanel.setDividerLocation(proportionalLocation)
427 Hashtable exnames = new Hashtable();
428 for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
430 exnames.put((String) setName.getItemAt(i), setName.getItemAt(i));
432 // Add the default entry - if not present already.
433 if (!exnames.contains(SVC_DEF))
435 setName.addItem(SVC_DEF);
436 exnames.put(SVC_DEF, SVC_DEF);
438 serviceOptions = service.getRunnerConfig();
439 // add any presets not already added.
440 String curname = (p == null ? "" : p.getName());
441 PresetManager prman = service.getPresets();
442 servicePresets = new Hashtable();
445 List prList = service.getPresets().getPresets();
448 for (Object pr : prList)
450 servicePresets.put(((Preset) pr).getName(), "preset");
451 if (!exnames.contains(((Preset) pr).getName()))
453 setName.addItem(((Preset) pr).getName());
458 updateTable(p, jobArgset);
459 initArgSetModified();
460 settingDialog = false;
464 @SuppressWarnings("unchecked")
465 private void updateTable(Preset p, List<Argument> jobArgset)
467 List<Parameter> setargs = new ArrayList<Parameter>();
468 // populate table from default parameter set.
469 List<Argument> args = serviceOptions.getArguments();
471 // split to params and required arguments
473 for (Argument arg : args)
475 Argument myarg = (Argument) arg;
476 // Ideally, Argument would implement isRequired !
477 if (myarg instanceof Parameter)
479 Parameter parm = (Parameter) myarg;
484 if (myarg instanceof Option)
486 Option opt = (Option) myarg;
487 addOption(opt).resetToDefault();
491 System.err.println("Ignoring unknown service argument type "
492 + arg.getClass().getName());
496 args = null; // no more args to process.
500 // initialise setname
501 setName.setSelectedItem(lastSetName = p.getName());
502 setDescr.setText(lastDescrText = p.getDescription());
506 args = p.getArguments(serviceOptions);
507 } catch (Exception e)
511 // TODO: check if args should be unselected prior to resetting using the
517 if (lastParmSet == null)
519 // first call - so create a dummy name
520 setName.setSelectedItem(lastSetName = SVC_DEF);
524 if (jobArgset != null)
526 argSetModified(jobArgset, true);
529 // get setargs from current object
532 for (Argument arg : args)
534 if (arg instanceof Parameter)
536 setParameter((Parameter) arg);
540 if (arg instanceof Option)
542 // System.out.println("Setting option "
543 // + System.identityHashCode(arg) + ":" + arg.getName()
544 // + " with " + arg.getDefaultValue());
545 selectOption((Option) arg, arg.getDefaultValue());
552 jobOptions.setPreferredSize(new Dimension(PARAM_WIDTH, optSet.size()
554 jobOptions.setLayout(new GridLayout(optSet.size(), 1));
555 refreshParamLayout();
556 paramPane.validate();
560 private boolean isModified()
562 return modifiedElements.size() > 0;
565 private Hashtable modifiedElements = new Hashtable();
568 * reset gui and modification state settings
570 private void initArgSetModified()
573 modifiedElements.clear();
574 renmodified.setVisible(false);
575 savmodified.setVisible(false);
579 private void argSetModified(Object modifiedElement, boolean b)
588 modifiedElements.remove(modifiedElement);
592 modifiedElements.put(modifiedElement, modifiedElement);
594 // set mod status based on presence of elements in table
595 if (modifiedElements.size() > 0)
598 savmodified.setVisible(true);
599 revertsetting.setVisible(false);
603 revertsetting.setVisible(false);
605 .setVisible(!isServicePreset((String) setName
607 && _getUserPreset((String) setName.getSelectedItem()) != null);
608 savmodified.setVisible(false);
610 // special reveal if setName has been modified
611 if (modifiedElements.get(setName) != null)
613 if (curSetName != null && lastSetName != null
614 && !lastSetName.equals(curSetName))
616 renmodified.setVisible(!isServicePreset(lastSetName));
621 // setname isn't in modlist - so don't rename
622 renmodified.setVisible(false);
627 private boolean isServicePreset(String selectedItem)
629 return selectedItem.equals(SVC_DEF)
630 || servicePresets.containsKey(selectedItem);
634 * check if the current set name is a valid set name for saving, if not, then
637 private void makeSetNameValid()
639 boolean stn = settingDialog;
640 boolean renamed = false;
641 settingDialog = true;
642 String nm = (String) setName.getSelectedItem();
643 // check if the name is reserved - if it is, rename it.
644 if (isServicePreset(nm))
650 while (_getUserPreset(tnm)!=null)
652 tnm = nm+" ("+(++i)+")";
660 // if nm exists in user's preset store then savmodified will update an
661 // existing user defined preset
662 // if nm doesn't exist, then the button will create a new preset.
664 boolean makeupdate = false;
665 // sync the gui with the preset database
666 for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
668 String snm = (String) setName.getItemAt(i);
672 setName.setSelectedIndex(i);
676 if (_getUserPreset(nm) != null)
678 savmodified.setText("Update");
685 setName.setSelectedIndex(setName.getItemCount() - 1);
687 savmodified.setText("Save");
692 private void addParameter(Parameter parm)
694 ParamBox pb = paramSet.get(parm.getName());
697 pb = new ParamBox(this, parm);
698 paramSet.put(parm.getName(), pb);
702 // take the defaults from the parameter
703 pb.updateControls(parm);
706 private void setParameter(Parameter arg)
708 ParamBox pb = paramSet.get(arg.getName());
715 pb.updateControls(arg);
720 private void selectOption(Option opt, String string)
722 OptionBox cb = optSet.get(opt.getName());
727 cb.enabled.setSelected(true); // initial state for an option.
730 if (opt.getPossibleValues().contains(string))
732 cb.val.setSelectedItem(string);
736 throw new Error("Invalid value " + string + " for option " + opt);
740 if (opt.isRequired() && !cb.enabled.isSelected())
742 // TODO: indicate paramset is not valid.. option needs to be selected!
744 cb.setInitialValue();
747 Map<String, ParamBox> paramSet = new Hashtable<String, ParamBox>();
749 public class ParamBox extends JPanel implements ChangeListener,
750 ActionListener, MouseListener
752 JButton showDesc = new JButton();
754 JTextArea string = new JTextArea();
756 JScrollPane descPanel = new JScrollPane();
758 JSlider slider = null;
760 JTextField valueField = null;
762 ValueConstrain validator = null;
764 JPanel settingPanel = new JPanel();
766 JPanel controlPanel = new JPanel();
768 boolean integ = false;
770 boolean choice = false;
772 boolean descisvisible = false;
774 final WsJobParameters pmdialogbox;
778 public ParamBox(final WsJobParameters pmlayout, Parameter parm)
780 pmdialogbox = pmlayout;
781 setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
782 setBorder(new TitledBorder(parm.getName()));
784 showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
785 showDesc.setText("+");
786 string.setFont(new Font("Verdana", Font.PLAIN, 11));
787 string.setBackground(getBackground());
788 // string.setSize(new Dimension(PARAM_WIDTH, 80));
789 string.setEditable(false);
790 descPanel.getViewport().setView(string);
791 // descPanel.setLocation(2,17);
792 descPanel.setVisible(false);
793 // string.setMinimumSize(new Dimension(140,80));
794 // string.setMaximumSize(new Dimension(280,80));
795 final ParamBox me = this;
796 finfo = parm.getFurtherDetails();
799 showDesc.setToolTipText("<html><p>Click to show brief description, and right click to open link for further information.</p></html>");
800 showDesc.addMouseListener(this);
804 showDesc.setToolTipText("<html><p>Click to show brief description.</p></html>");
806 showDesc.addActionListener(new ActionListener()
809 public void actionPerformed(ActionEvent e)
811 descisvisible = !descisvisible;
812 descPanel.setVisible(descisvisible);
813 me.setPreferredSize(new Dimension(PARAM_WIDTH,
814 (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
816 pmlayout.refreshParamLayout();
819 string.setWrapStyleWord(true);
820 string.setLineWrap(true);
821 string.setColumns(32);
822 string.setText(parm.getDescription());
823 JPanel firstrow = new JPanel();
824 firstrow.setLayout(null);
825 controlPanel.setLayout(new BorderLayout());
826 controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
827 PARAM_CLOSEDHEIGHT - 50));
828 showDesc.setBounds(new Rectangle(10, 10, 16, 16));
829 firstrow.add(showDesc);
830 firstrow.add(controlPanel);
831 firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
832 PARAM_CLOSEDHEIGHT - 30));
834 validator = parm.getValidValue();
836 if (validator != null)
838 integ = validator.getType() == Type.Integer;
842 if (parameter.getPossibleValues() != null)
847 updateControls(parm);
848 descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
849 PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
856 // reset the widget's initial value.
860 boolean adjusting = false;
866 public int getBoxHeight()
868 return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
871 public void updateControls(Parameter parm)
874 boolean init = (choicebox == null && valueField == null);
881 choicebox = new JComboBox();
882 choicebox.addActionListener(this);
883 controlPanel.add(choicebox, BorderLayout.CENTER);
887 slider = new JSlider();
888 slider.addChangeListener(this);
889 valueField = new JTextField();
890 valueField.addActionListener(this);
891 valueField.setPreferredSize(new Dimension(60, 25));
892 controlPanel.add(slider, BorderLayout.WEST);
893 controlPanel.add(valueField, BorderLayout.EAST);
904 List vals = parm.getPossibleValues();
905 for (Object val : vals)
907 choicebox.addItem(val);
911 if (parm.getDefaultValue() != null)
913 choicebox.setSelectedItem(parm.getDefaultValue());
918 valueField.setText(parm.getDefaultValue());
921 lastVal = updateSliderFromValueField();
927 public Parameter getParameter()
929 Parameter prm = ParameterUtils.copyParameter(parameter);
934 prm.setDefaultValue((String) choicebox.getSelectedItem());
938 prm.setDefaultValue(valueField.getText());
940 } catch (WrongParameterException e)
948 public Object updateSliderFromValueField()
952 if (validator != null)
959 valueField.setText(valueField.getText().trim());
960 iVal = Integer.valueOf(valueField.getText());
961 } catch (Exception e)
965 if (validator.getMin() != null && validator.getMax() != null)
967 slider.getModel().setRangeProperties(iVal, 1,
968 validator.getMin().intValue(),
969 validator.getMax().intValue(), true);
973 slider.setVisible(false);
983 fVal = Float.valueOf(valueField.getText());
984 } catch (Exception e)
988 if (validator.getMin() != null && validator.getMax() != null)
990 slider.getModel().setRangeProperties((int) fVal * 1000, 1,
991 (int) validator.getMin().floatValue() * 1000,
992 (int) validator.getMax().floatValue() * 1000, true);
996 slider.setVisible(false);
1006 slider.setVisible(false);
1008 { valueField.getText().trim() };
1013 { (String) choicebox.getSelectedItem() };
1019 public void stateChanged(ChangeEvent e)
1023 valueField.setText(""
1024 + ((integ) ? ("" + (int) slider.getValue())
1025 : ("" + (float) (slider.getValue() / 1000f))));
1031 public void actionPerformed(ActionEvent e)
1039 updateSliderFromValueField();
1044 private void checkIfModified()
1046 Object cstate = updateSliderFromValueField();
1047 boolean notmod = false;
1048 if (cstate.getClass() == lastVal.getClass())
1050 if (cstate instanceof int[])
1052 notmod = (((int[]) cstate)[0] == ((int[]) lastVal)[0]);
1054 else if (cstate instanceof float[])
1056 notmod = (((float[]) cstate)[0] == ((float[]) lastVal)[0]);
1058 else if (cstate instanceof String[])
1060 notmod = (((String[]) cstate)[0].equals(((String[]) lastVal)[0]));
1063 pmdialogbox.argSetModified(this, !notmod);
1066 public void mouseClicked(MouseEvent e)
1068 if (javax.swing.SwingUtilities.isRightMouseButton(e))
1070 Desktop.showUrl(finfo.toString());
1074 public void mousePressed(MouseEvent e)
1076 // TODO Auto-generated method stub
1080 public void mouseReleased(MouseEvent e)
1082 // TODO Auto-generated method stub
1086 public void mouseEntered(MouseEvent e)
1088 // TODO Auto-generated method stub
1092 public void mouseExited(MouseEvent e)
1094 // TODO Auto-generated method stub
1100 Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();
1102 public class OptionBox extends JPanel implements MouseListener,
1105 JComboBox val = new JComboBox();
1107 JCheckBox enabled = new JCheckBox();
1109 JLabel optlabel = new JLabel();
1111 URL linkImageURL = getClass().getResource("/images/link.gif");
1115 boolean hasLink = false;
1119 public OptionBox(Option opt)
1122 setLayout(new BorderLayout());
1123 enabled.setSelected(opt.isRequired()); // TODO: lock required options
1124 enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
1125 enabled.setText("");
1126 enabled.setText(opt.getName());
1127 enabled.addActionListener(this);
1128 finfo = option.getFurtherDetails();
1132 // optlabel.setToolTipText("<html><p>"+opt.getDescription()+"</p><img src=\""+linkImageURL+"\"/></html>");
1133 enabled.setToolTipText("<html><p>" + opt.getDescription()
1134 + "</p><img src=\"" + linkImageURL + "\"/></html>");
1135 // optlabel.addMouseListener(this);
1136 enabled.addMouseListener(this);
1140 // optlabel.setToolTipText(opt.getDescription());
1141 enabled.setToolTipText(opt.getDescription());
1143 add(enabled, BorderLayout.NORTH);
1144 if (opt.getPossibleValues().size() > 1)
1146 setLayout(new GridLayout(1, 2));
1147 for (Object str : opt.getPossibleValues())
1149 val.addItem((String) str);
1151 val.setSelectedItem((String) opt.getDefaultValue());
1152 val.addActionListener(this);
1153 add(val, BorderLayout.SOUTH);
1155 // TODO: add actionListeners for popup (to open further info),
1156 // and to update list of parameters if an option is enabled
1157 // that takes a value.
1161 public void resetToDefault()
1163 enabled.setSelected(false);
1164 if (option.isRequired())
1166 // Apply default value
1167 selectOption(option, option.getDefaultValue());
1171 boolean initEnabled = false;
1173 String initVal = null;
1175 public void setInitialValue()
1177 initEnabled = enabled.isSelected();
1178 if (option.getPossibleValues() != null
1179 && option.getPossibleValues().size() > 1)
1181 initVal = (String) val.getSelectedItem();
1189 public Option getOptionIfEnabled()
1191 if (!enabled.isSelected())
1197 Option opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
1199 if (val.getSelectedItem() != null)
1201 opt.setDefaultValue((String) val.getSelectedItem());
1203 } catch (WrongParameterException e)
1205 e.printStackTrace();
1211 public void actionPerformed(ActionEvent e)
1213 if (e.getSource() != enabled)
1215 enabled.setSelected(true);
1220 private void checkIfModified()
1222 boolean notmod = (initEnabled == enabled.isSelected());
1223 if (enabled.isSelected() && initVal != null)
1225 notmod |= initVal.equals(val.getSelectedItem());
1227 argSetModified(this, !notmod);
1230 public void mouseClicked(MouseEvent e)
1232 if (javax.swing.SwingUtilities.isRightMouseButton(e))
1234 showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
1238 public void mousePressed(MouseEvent e)
1240 // TODO Auto-generated method stub
1244 public void mouseReleased(MouseEvent e)
1246 // TODO Auto-generated method stub
1250 public void mouseEntered(MouseEvent e)
1252 // TODO Auto-generated method stub
1256 public void mouseExited(MouseEvent e)
1258 // TODO Auto-generated method stub
1264 private OptionBox addOption(Option opt)
1266 OptionBox cb = optSet.get(opt.getName());
1269 cb = new OptionBox(opt);
1270 optSet.put(opt.getName(), cb);
1276 public static void showUrlPopUp(JComponent invoker, final String finfo,
1280 JPopupMenu mnu = new JPopupMenu();
1281 JMenuItem mitem = new JMenuItem("View " + finfo);
1282 mitem.addActionListener(new ActionListener()
1286 public void actionPerformed(ActionEvent e)
1288 Desktop.showUrl(finfo);
1293 mnu.show(invoker, x, y);
1296 protected void refreshParamLayout()
1299 for (ParamBox pbox : paramSet.values())
1301 s += pbox.getBoxHeight();
1303 paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
1304 paramList.setLayout(new FlowLayout());
1309 * testing method - grab a service and parameter set and show the window
1313 public static void main(String[] args)
1315 jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
1318 if (args.length > 3)
1320 Vector<String> services = new Vector<String>();
1321 services.addElement(args[p++]);
1322 Jws2Discoverer.setServiceUrls(services);
1327 } catch (Exception e)
1329 System.err.println("Aborting. Problem discovering services.");
1330 e.printStackTrace();
1333 Jws2Discoverer.Jws2Instance lastserv = null;
1334 for (Jws2Discoverer.Jws2Instance service : disc.getServices())
1337 if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
1339 if (lastserv != null)
1341 List<Preset> prl = null;
1343 if (++p < args.length)
1345 PresetManager prman = lastserv.getPresets();
1348 pr = prman.getPresetByName(args[p]);
1351 // just grab the last preset.
1352 prl = prman.getPresets();
1356 PresetManager prman = lastserv.getPresets();
1358 prl = prman.getPresets();
1361 Iterator<Preset> en = (prl == null) ? null : prl.iterator();
1362 while (en!=null && en.hasNext())
1368 en = prl.iterator();
1373 System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName());
1374 List<Option> rg = lastserv.getRunnerConfig().getOptions();
1379 Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
1380 } catch (Exception e)
1382 System.err.println("Failed to copy " + o.getName());
1383 e.printStackTrace();
1386 System.err.println("Failed to copy " + o.getName());
1387 e.printStackTrace();
1392 System.out.println("Testing param dupes:");
1393 List<Parameter> rg = lastserv.getRunnerConfig()
1395 for (Parameter o : rg)
1399 Parameter cpy = jalview.ws.jws2.ParameterUtils
1401 } catch (Exception e)
1403 System.err.println("Failed to copy " + o.getName());
1404 e.printStackTrace();
1407 System.err.println("Failed to copy " + o.getName());
1408 e.printStackTrace();
1412 WsJobParameters pgui = new WsJobParameters(lastserv, pr);
1413 JFrame jf = new JFrame("Parameters for "
1414 + lastserv.getActionText());
1415 JPanel cont = new JPanel();
1416 // jf.setPreferredSize(new Dimension(600, 800));
1419 final Thread thr = Thread.currentThread();
1420 jf.addWindowListener(new WindowListener()
1423 public void windowActivated(WindowEvent e)
1425 // TODO Auto-generated method stub
1429 public void windowClosed(WindowEvent e)
1433 public void windowClosing(WindowEvent e)
1439 public void windowDeactivated(WindowEvent e)
1441 // TODO Auto-generated method stub
1445 public void windowDeiconified(WindowEvent e)
1447 // TODO Auto-generated method stub
1451 public void windowIconified(WindowEvent e)
1453 // TODO Auto-generated method stub
1457 public void windowOpened(WindowEvent e)
1459 // TODO Auto-generated method stub
1464 jf.setVisible(true);
1465 boolean inter = false;
1470 Thread.sleep(10000);
1471 } catch (Exception e)
1484 public List<Argument> getJobParams()
1486 List<Argument> argSet = new ArrayList<Argument>();
1487 // recover options and parameters from GUI
1488 for (OptionBox opts : optSet.values())
1490 Option opt = opts.getOptionIfEnabled();
1496 for (ParamBox parambox : paramSet.values())
1498 Parameter parm = parambox.getParameter();
1508 String lastParmSet = null;
1510 Hashtable<String, Object[]> editedParams = new Hashtable<String, Object[]>();
1513 * store the given parameters in the user parameter set database.
1515 * @param storeSetName
1518 * - setDescr.getText()
1522 private void _storeUserPreset(String storeSetName, String descr,
1523 List<Argument> jobParams)
1525 // this is a simple hash store.
1527 editedParams.put(storeSetName, pset = new Object[3]);
1528 pset[0] = storeSetName;
1530 pset[2] = jobParams;
1531 //writeParam("Saving " + storeSetName + ": ", jobParams);
1534 private void writeParam(String nm, List<Argument> params)
1536 for (Argument p : params)
1538 System.out.println(nm + ":" + System.identityHashCode(p) + " Name: "
1539 + p.getName() + " Value: " + p.getDefaultValue());
1543 private Object[] _getUserPreset(String setName)
1545 Object[] pset = editedParams.get(setName);
1547 // writeParam("Retrieving " + setName + ": ", (List<Argument>) pset[2]);
1552 * remove the given user preset from the preset stash
1556 private void _deleteUserPreset(String setName)
1558 editedParams.remove(setName);
1561 private void syncSetNamesWithStore()
1564 // remove any set names in the drop down menu that aren't either a reserved
1565 // setting, or a user defined or service preset.
1566 while (n < setName.getItemCount())
1568 String item = (String) setName.getItemAt(n);
1569 if (!isServicePreset(item) && _getUserPreset(item) == null)
1571 setName.removeItemAt(n);
1581 private void reInitDialog(String nextPreset)
1583 settingDialog = true;
1584 syncSetNamesWithStore();
1585 // updateTable(null,null); // first reset to defaults
1587 Object[] pset = _getUserPreset(nextPreset);
1590 setDescr.setText((String) pset[1]);
1591 updateTable(null, (List<Argument>) pset[2]);
1592 lastParmSet = nextPreset;
1597 setDescr.setText("");
1598 // must be a default preset from service
1602 PresetManager prman = service.getPresets();
1605 p = prman.getPresetByName(nextPreset);
1607 } catch (Exception ex)
1609 ex.printStackTrace();
1613 updateTable(p, null);
1614 lastParmSet = nextPreset;
1618 updateTable(null, null);
1621 initArgSetModified();
1623 settingDialog = false;
1627 String curSetName = null;
1629 public void itemStateChanged(ItemEvent e)
1636 if (e.getSource() == setName)
1638 String setname = (String) setName.getSelectedItem();
1639 if (setname == null)
1643 if (curSetName == null || !setname.equals(curSetName))
1645 settingDialog = true;
1648 System.out.println("Prompting for "+setname);
1649 if (javax.swing.JOptionPane.showConfirmDialog(this,
1650 "Parameter set is modifed - save ?", "Save changes ?",
1651 javax.swing.JOptionPane.OK_CANCEL_OPTION) == JOptionPane.OK_OPTION)
1653 System.out.println("Saving for "+setname);
1654 savModified_actionPerformed(null);
1657 reInitDialog(setname);
1664 * last saved name for this user preset
1666 String lastSetName = null;
1669 * last saved value of the description text for this user preset
1671 String lastDescrText = null;
1673 public void actionPerformed(ActionEvent e)
1675 if (e.getSource() instanceof Component)
1677 Component src = (Component) e.getSource();
1678 if (src.getParent() == setName)
1680 // rename any existing records we know about for this set.
1681 String newname = (String) e.getActionCommand();
1683 if (isServicePreset(newname))
1685 JOptionPane.showConfirmDialog(this,
1686 "Invalid name - preset already exists.", "Invalid name",
1687 JOptionPane.OK_OPTION);
1690 curSetName = newname;
1691 System.err.println("Command " + curSetName + " : "
1692 + setName.getSelectedItem());
1693 if (curSetName.trim().equals(setName.getSelectedItem()))
1697 if (curSetName != null)
1699 setName.addItem(curSetName);
1700 setName.setSelectedItem(curSetName);
1701 argSetModified(setName,
1702 lastSetName != null && !curSetName.equals(lastSetName));
1710 private void checkDescrModified()
1717 (lastDescrText == null ? setDescr.getText().trim().length() > 0
1718 : !setDescr.getText().equals(lastDescrText)));
1723 public void insertUpdate(DocumentEvent e)
1725 checkDescrModified();
1728 public void removeUpdate(DocumentEvent e)
1730 checkDescrModified();
1733 public void changedUpdate(DocumentEvent e)
1735 checkDescrModified();