items = new Vector<>();
+ while (n < setName.getItemCount())
{
- pmdialogbox = pmlayout;
- setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
- setBorder(new TitledBorder(parm.getName()));
- setLayout(null);
- showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
- showDesc.setText("+");
- string.setFont(new Font("Verdana", Font.PLAIN, 11));
- string.setBackground(getBackground());
- // string.setSize(new Dimension(PARAM_WIDTH, 80));
- string.setEditable(false);
- descPanel.getViewport().setView(string);
- // descPanel.setLocation(2,17);
- descPanel.setVisible(false);
- // string.setMinimumSize(new Dimension(140,80));
- // string.setMaximumSize(new Dimension(280,80));
- final ParamBox me = this;
- finfo = parm.getFurtherDetails();
- if (finfo != null)
+ String item = setName.getItemAt(n);
+ if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
{
- showDesc.setToolTipText("Click to show brief description, and right click to open link for further information.
");
- showDesc.addMouseListener(this);
+ setName.removeItemAt(n);
}
else
{
- showDesc.setToolTipText("Click to show brief description.
");
+ items.addElement(item);
+ n++;
}
- showDesc.addActionListener(new ActionListener()
+ }
+ if (!items.contains(SVC_DEF))
+ {
+ setName.addItem(SVC_DEF);
+ }
+ for (WsParamSetI upn : paramStore.getPresets())
+ {
+ if (!items.contains(upn.getName()))
{
+ setName.addItem(upn.getName());
+ }
+ }
+ }
- public void actionPerformed(ActionEvent e)
- {
- descisvisible = !descisvisible;
- descPanel.setVisible(descisvisible);
- me.setPreferredSize(new Dimension(PARAM_WIDTH,
- (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
- me.validate();
- pmlayout.refreshParamLayout();
- }
- });
- string.setWrapStyleWord(true);
- string.setLineWrap(true);
- string.setColumns(32);
- string.setText(parm.getDescription());
- JPanel firstrow = new JPanel();
- firstrow.setLayout(null);
- controlPanel.setLayout(new BorderLayout());
- controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70,
- PARAM_CLOSEDHEIGHT - 50));
- showDesc.setBounds(new Rectangle(10, 10, 16, 16));
- firstrow.add(showDesc);
- firstrow.add(controlPanel);
- firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30,
- PARAM_CLOSEDHEIGHT - 30));
- add(firstrow);
- validator = parm.getValidValue();
- parameter = parm;
- if (validator != null)
+ /**
+ * true if lastParmSet is a user preset
+ */
+ boolean isUserPreset = false;
+
+ private void reInitDialog(String nextPreset)
+ {
+ settingDialog = true;
+ // updateTable(null,null); // first reset to defaults
+ WsParamSetI pset = null;
+ if (nextPreset != null && nextPreset.length() > 0)
+ {
+ pset = paramStore.getPreset(nextPreset);
+ }
+ if (pset != null)
+ {
+ if (pset.isModifiable())
{
- integ = validator.getType() == Type.Integer;
+ isUserPreset = true;
+ setDescr.setText(pset.getDescription());
+ updateTable(null, pset.getArguments());
+ lastParmSet = nextPreset;
}
else
{
- if (parameter.getPossibleValues() != null)
- {
- choice = true;
- }
+ isUserPreset = false;
+ setDescr.setText("");
+ // must be a default preset from service
+ updateTable(pset, null);
+ lastParmSet = nextPreset;
}
- updateControls(parm);
- descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
- PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
- add(descPanel);
- validate();
}
-
- public void init()
+ else
{
- // reset the widget's initial value.
- lastVal = null;
+ isUserPreset = false;
+ // Service defaults
+ setDescr.setText("");
+ updateTable(null, null);
+ lastParmSet = SVC_DEF;
}
- boolean adjusting = false;
-
- Parameter parameter;
-
- JComboBox choicebox;
+ initArgSetModified();
+ syncSetNamesWithStore();
+ setName.setSelectedItem(lastParmSet);
+ setNamePanel.validate();
+ validate();
+ settingDialog = false;
+ }
- public int getBoxHeight()
- {
- return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
- }
-
- public void updateControls(Parameter parm)
- {
- adjusting = true;
- boolean init = (choicebox == null && valueField == null);
- float fVal = 0f;
- int iVal = 0;
- if (init)
- {
- if (choice)
- {
- choicebox = new JComboBox();
- choicebox.addActionListener(this);
- controlPanel.add(choicebox, BorderLayout.CENTER);
- }
- else
- {
- slider = new JSlider();
- slider.addChangeListener(this);
- valueField = new JTextField();
- valueField.addActionListener(this);
- valueField.setPreferredSize(new Dimension(60, 25));
- controlPanel.add(slider, BorderLayout.WEST);
- controlPanel.add(valueField, BorderLayout.EAST);
-
- }
- }
-
- if (parm != null)
- {
- if (choice)
- {
- if (init)
- {
- List vals = parm.getPossibleValues();
- for (Object val : vals)
- {
- choicebox.addItem(val);
- }
- }
-
- if (parm.getDefaultValue() != null)
- {
- choicebox.setSelectedItem(parm.getDefaultValue());
- }
- }
- else
- {
- valueField.setText(parm.getDefaultValue());
- }
- }
- lastVal = updateSliderFromValueField();
- adjusting = false;
- }
-
- Object lastVal;
-
- public Parameter getParameter()
- {
- Parameter prm = ParameterUtils.copyParameter(parameter);
- try
- {
- if (choice)
- {
- prm.setDefaultValue((String) choicebox.getSelectedItem());
- }
- else
- {
- prm.setDefaultValue(valueField.getText());
- }
- } catch (WrongParameterException e)
- {
- e.printStackTrace();
- return null;
- }
- return prm;
- }
-
- public Object updateSliderFromValueField()
- {
- int iVal;
- float fVal;
- if (validator != null)
- {
- if (integ)
- {
- iVal = 0;
- try
- {
- valueField.setText(valueField.getText().trim());
- iVal = Integer.valueOf(valueField.getText());
- } catch (Exception e)
- {
- }
- ;
- if (validator.getMin() != null && validator.getMax() != null)
- {
- slider.getModel().setRangeProperties(iVal, 1,
- validator.getMin().intValue(),
- validator.getMax().intValue(), true);
- }
- else
- {
- slider.setVisible(false);
- }
- return new int[]
- { iVal };
- }
- else
- {
- fVal = 0f;
- try
- {
- fVal = Float.valueOf(valueField.getText());
- } catch (Exception e)
- {
- }
- ;
- if (validator.getMin() != null && validator.getMax() != null)
- {
- slider.getModel().setRangeProperties((int) fVal * 1000, 1,
- (int) validator.getMin().floatValue() * 1000,
- (int) validator.getMax().floatValue() * 1000, true);
- }
- else
- {
- slider.setVisible(false);
- }
- return new float[]
- { fVal };
- }
- }
- else
- {
- if (!choice)
- {
- slider.setVisible(false);
- return new String[]
- { valueField.getText().trim() };
- }
- else
- {
- return new String[]
- { (String) choicebox.getSelectedItem() };
- }
- }
-
- }
-
- public void stateChanged(ChangeEvent e)
- {
- if (!adjusting)
- {
- valueField.setText(""
- + ((integ) ? ("" + (int) slider.getValue())
- : ("" + (float) (slider.getValue() / 1000f))));
- checkIfModified();
- }
-
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if (adjusting)
- {
- return;
- }
- if (!choice)
- {
- updateSliderFromValueField();
- }
- checkIfModified();
- }
-
- private void checkIfModified()
- {
- Object cstate = updateSliderFromValueField();
- boolean notmod = false;
- if (cstate.getClass() == lastVal.getClass())
- {
- if (cstate instanceof int[])
- {
- notmod = (((int[]) cstate)[0] == ((int[]) lastVal)[0]);
- }
- else if (cstate instanceof float[])
- {
- notmod = (((float[]) cstate)[0] == ((float[]) lastVal)[0]);
- }
- else if (cstate instanceof String[])
- {
- notmod = (((String[]) cstate)[0].equals(((String[]) lastVal)[0]));
- }
- }
- pmdialogbox.argSetModified(this, !notmod);
- }
-
- public void mouseClicked(MouseEvent e)
- {
- if (javax.swing.SwingUtilities.isRightMouseButton(e))
- {
- Desktop.showUrl(finfo.toString());
- }
- }
-
- public void mousePressed(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseReleased(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseEntered(MouseEvent e)
+ /**
+ * Rebuild the AlignFrame web service menus (after add/delete of a preset
+ * option).
+ */
+ protected void updateWebServiceMenus()
+ {
+ if (Desktop.getInstance() == null)
{
- // TODO Auto-generated method stub
-
+ return;
}
-
- public void mouseExited(MouseEvent e)
+ for (AlignFrame alignFrame : Desktop.getAlignFrames())
{
- // TODO Auto-generated method stub
-
+ alignFrame.buildWebServicesMenu();
}
-
}
- Map optSet = new Hashtable();
+ String curSetName = null;
- public class OptionBox extends JPanel implements MouseListener,
- ActionListener
+ @Override
+ public void itemStateChanged(ItemEvent e)
{
- JComboBox val = new JComboBox();
-
- JCheckBox enabled = new JCheckBox();
-
- JLabel optlabel = new JLabel();
-
- URL linkImageURL = getClass().getResource("/images/link.gif");
-
- final URL finfo;
-
- boolean hasLink = false;
-
- Option option;
-
- public OptionBox(Option opt)
- {
- option = opt;
- setLayout(new BorderLayout());
- enabled.setSelected(opt.isRequired()); // TODO: lock required options
- enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
- enabled.setText("");
- enabled.setText(opt.getName());
- enabled.addActionListener(this);
- finfo = option.getFurtherDetails();
- if (finfo != null)
- {
- hasLink = true;
- // optlabel.setToolTipText(""+opt.getDescription()+"
");
- enabled.setToolTipText("" + opt.getDescription()
- + "
");
- // optlabel.addMouseListener(this);
- enabled.addMouseListener(this);
- }
- else
- {
- // optlabel.setToolTipText(opt.getDescription());
- enabled.setToolTipText(opt.getDescription());
- }
- add(enabled, BorderLayout.NORTH);
- if (opt.getPossibleValues().size() > 1)
- {
- setLayout(new GridLayout(1, 2));
- for (Object str : opt.getPossibleValues())
- {
- val.addItem((String) str);
- }
- val.setSelectedItem((String) opt.getDefaultValue());
- val.addActionListener(this);
- add(val, BorderLayout.SOUTH);
- }
- // TODO: add actionListeners for popup (to open further info),
- // and to update list of parameters if an option is enabled
- // that takes a value.
- setInitialValue();
- }
-
- public void resetToDefault()
- {
- enabled.setSelected(false);
- if (option.isRequired())
- {
- // Apply default value
- selectOption(option, option.getDefaultValue());
- }
- }
-
- boolean initEnabled = false;
-
- String initVal = null;
-
- public void setInitialValue()
+ if (e.getSource() == setName
+ && e.getStateChange() == ItemEvent.SELECTED)
{
- initEnabled = enabled.isSelected();
- if (option.getPossibleValues() != null
- && option.getPossibleValues().size() > 1)
+ final String setname = (String) setName.getSelectedItem();
+ if (Console.isDebugEnabled())
{
- initVal = (String) val.getSelectedItem();
+ Console.debug("Item state changed for " + setname + " (handling ? "
+ + !settingDialog + ")");
}
- else
+ if (settingDialog)
{
- initVal = null;
+ // ignore event
+ return;
}
- }
-
- public Option getOptionIfEnabled()
- {
- if (!enabled.isSelected())
+ if (setname == null)
{
- return null;
+ return;
}
- try
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
{
- Option opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
-
- if (val.getSelectedItem() != null)
+ @Override
+ public void run()
{
- opt.setDefaultValue((String) val.getSelectedItem());
+ doPreferenceComboStateChange(setname);
}
- } catch (WrongParameterException e)
- {
- e.printStackTrace();
- return null;
- }
- return option;
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if (e.getSource() != enabled)
- {
- enabled.setSelected(true);
- }
- checkIfModified();
- }
-
- private void checkIfModified()
- {
- boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected() && initVal != null)
- {
- notmod |= initVal.equals(val.getSelectedItem());
- }
- argSetModified(this, !notmod);
- }
-
- public void mouseClicked(MouseEvent e)
- {
- if (javax.swing.SwingUtilities.isRightMouseButton(e))
- {
- showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
- }
- }
-
- public void mousePressed(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseReleased(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseEntered(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseExited(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- private OptionBox addOption(Option opt)
- {
- OptionBox cb = optSet.get(opt.getName());
- if (cb == null)
- {
- cb = new OptionBox(opt);
- optSet.put(opt.getName(), cb);
- jobOptions.add(cb);
+ });
}
- return cb;
}
- public static void showUrlPopUp(JComponent invoker, final String finfo,
- int x, int y)
+ private void doPreferenceComboStateChange(String setname)
{
-
- JPopupMenu mnu = new JPopupMenu();
- JMenuItem mitem = new JMenuItem("View " + finfo);
- mitem.addActionListener(new ActionListener()
+ // user has selected a different item from combo-box
+ if (isModified())
{
-
- @Override
- public void actionPerformed(ActionEvent e)
+ String lsetname = (curSetName != null) ? curSetName : lastParmSet;
+ if (lsetname.equals(setname))
{
- Desktop.showUrl(finfo);
-
+ // setname was just edited - so ignore this event.
+ return;
}
- });
- mnu.add(mitem);
- mnu.show(invoker, x, y);
- }
-
- protected void refreshParamLayout()
- {
- int s = 100;
- for (ParamBox pbox : paramSet.values())
- {
- s += pbox.getBoxHeight();
- }
- paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
- paramList.setLayout(new FlowLayout());
- validate();
- }
-
- /**
- * testing method - grab a service and parameter set and show the window
- *
- * @param args
- */
- public static void main(String[] args)
- {
- jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
- .getDiscoverer();
- int p = 0;
- if (args.length > 3)
- {
- Vector services = new Vector();
- services.addElement(args[p++]);
- Jws2Discoverer.setServiceUrls(services);
- }
- try
- {
- disc.run();
- } catch (Exception e)
- {
- System.err.println("Aborting. Problem discovering services.");
- e.printStackTrace();
- return;
- }
- Jws2Discoverer.Jws2Instance lastserv = null;
- for (Jws2Discoverer.Jws2Instance service : disc.getServices())
- {
- lastserv = service;
- if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
+ settingDialog = true;
+ System.out.println("Prompting to save " + lsetname);
+ if (JvOptionPane.showConfirmDialog(this, "Parameter set '" + lsetname
+ + "' is modifed, and your changes will be lost.\nReally change preset ?",
+ "Warning: Unsaved Changes",
+ JvOptionPane.OK_CANCEL_OPTION) != JvOptionPane.OK_OPTION)
{
- if (lastserv != null)
- {
- List prl = null;
- Preset pr = null;
- if (++p < args.length)
- {
- PresetManager prman = lastserv.getPresets();
- if (prman != null)
- {
- pr = prman.getPresetByName(args[p]);
- if (pr == null)
- {
- // just grab the last preset.
- prl = prman.getPresets();
- }
- }
- } else {
- PresetManager prman = lastserv.getPresets();
- if (prman!=null) {
- prl = prman.getPresets();
- }
- }
- Iterator en = (prl == null) ? null : prl.iterator();
- while (en!=null && en.hasNext())
- {
- if (en != null)
- {
- if (!en.hasNext())
- {
- en = prl.iterator();
- }
- pr = en.next();
- }
- {
- System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName());
- List