();
-
- public class ParamBox extends JPanel implements ChangeListener,
- ActionListener, MouseListener
- {
- JButton showDesc = new JButton();
-
- JTextArea string = new JTextArea();
-
- JScrollPane descPanel = new JScrollPane();
-
- JSlider slider = null;
-
- JTextField valueField = null;
-
- ValueConstrainI validator = null;
-
- JPanel settingPanel = new JPanel();
-
- JPanel controlPanel = new JPanel();
-
- boolean integ = false;
-
- boolean choice = false;
-
- boolean descisvisible = false;
-
- final WsJobParameters pmdialogbox;
-
- final URL finfo;
-
- public ParamBox(final WsJobParameters pmlayout, ParameterI parm)
- {
- 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)
- {
- showDesc.setToolTipText("Click to show brief description, and right click to open link for further information.
");
- showDesc.addMouseListener(this);
- }
- else
- {
- showDesc.setToolTipText("Click to show brief description.
");
- }
- showDesc.addActionListener(new ActionListener()
- {
-
- 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)
- {
- integ = validator.getType() == Type.Integer;
- }
- else
+ // optsAndparams.setPreferredSize(null);
+ FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
+ int sep = fl.getVgap();
+ boolean fh = true;
+ int os = 0, s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom
+ + jobOptions.getBorder().getBorderInsets(jobOptions).top
+ + 2
+ * sep;
+ /**
+ * final height for viewport
+ */
+ int finalh = s;
+ int panewidth = paramPane.getViewport().getSize().width - 120
+ - jobOptions.getBorder().getBorderInsets(jobOptions).left
+ + jobOptions.getBorder().getBorderInsets(jobOptions).right;
+
+ int w = 2
+ * fl.getHgap()
+ + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH
+ : OptsAndParamsPage.PARAM_WIDTH);
+ int hgap = fl.getHgap(), cw = hgap;
+
+ if (opanp.getOptSet().size() > 0)
+ {
+
+ jobOptions.setLayout(new MigLayout("", "", ""));
+ jobOptions.removeAll();
+
+ for (OptionBox pbox : opanp.getOptSet().values())
{
- if (parameter.getPossibleValues() != null)
+ pbox.validate();
+ cw += pbox.getSize().width + hgap;
+ if (cw + 120 > panewidth)
{
- choice = true;
- }
- }
- updateControls(parm);
- descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
- PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
- add(descPanel);
- validate();
- }
-
- public void init()
- {
- // reset the widget's initial value.
- lastVal = null;
- }
-
- boolean adjusting = false;
-
- ParameterI parameter;
-
- JComboBox choicebox;
-
- public int getBoxHeight()
- {
- return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
- }
-
- public void updateControls(ParameterI 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);
+ jobOptions.add(pbox, "wrap");
+ // System.out.println("Wrap on "+pbox.option.getName());
+ cw = hgap + pbox.getSize().width;
+ fh = true;
}
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);
-
+ jobOptions.add(pbox);
}
- }
-
- if (parm != null)
- {
- if (choice)
+ if (fh)
{
- 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());
+ finalh += pbox.getSize().height + fl.getVgap();
+ fh = false;
}
}
- lastVal = updateSliderFromValueField();
- adjusting = false;
+ jobOptions.revalidate();
}
-
- Object lastVal;
-
- public ParameterI getParameter()
+ else
{
- ParameterI prm = parameter.copy();
- if (choice)
- {
- prm.setDefaultValue((String) choicebox.getSelectedItem());
- }
- else
- {
- prm.setDefaultValue(valueField.getText());
- }
- return prm;
+ jobOptions.setVisible(false);
}
- public Object updateSliderFromValueField()
+ // Now layout the parameters assuming they occupy one column - to calculate
+ // total height of options+parameters
+ fl = new FlowLayout(FlowLayout.LEFT);
+ // helpful hint from
+ // http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
+ fl.setAlignOnBaseline(true);
+ if (opanp.getParamSet().size() > 0)
{
- int iVal;
- float fVal;
- if (validator != null)
- {
- if (integ)
- {
- iVal = 0;
- try
- {
- valueField.setText(valueField.getText().trim());
- iVal = Integer.valueOf(valueField.getText());
- if (validator.getMin()!=null && validator.getMin().intValue()>iVal)
- {
- iVal = validator.getMin().intValue();
- // TODO: provide visual indication that hard limit was reached for this parameter
- }
- if (validator.getMax()!=null && validator.getMax().intValue()fVal)
- {
- fVal = validator.getMin().floatValue();
- // TODO: provide visual indication that hard limit was reached for this parameter
- }
- if (validator.getMax()!=null && validator.getMax().floatValue() panewidth)
{
- slider.setVisible(false);
- return new String[]
- { valueField.getText().trim() };
+ paramList.add(pbox, "wrap");
+ cw = pbox.getSize().width + hgap;
+ fh = true;
}
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)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseExited(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- Map optSet = new Hashtable();
-
- public class OptionBox extends JPanel implements MouseListener,
- ActionListener
- {
- 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;
-
- OptionI option;
-
- public OptionBox(OptionI 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()
- {
- initEnabled = enabled.isSelected();
- if (option.getPossibleValues() != null
- && option.getPossibleValues().size() > 1)
- {
- initVal = (String) val.getSelectedItem();
- }
- else
- {
- initVal = (initEnabled) ? option.getDefaultValue() : null;
- }
- }
-
- public OptionI getOptionIfEnabled()
- {
- if (!enabled.isSelected())
- {
- return null;
- }
- OptionI opt = option.copy();
-
- if (val.getSelectedItem() != null)
- {
- opt.setDefaultValue((String) val.getSelectedItem());
- }
- return opt;
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if (e.getSource() != enabled)
- {
- enabled.setSelected(true);
- }
- checkIfModified();
- }
-
- private void checkIfModified()
- {
- boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected())
- {
- if (initVal != null)
- {
- notmod &= initVal.equals(val.getSelectedItem());
+ paramList.add(pbox);
}
- else
+ if (fh)
{
- // compare against default service setting
- notmod &= option.getDefaultValue() == null
- || option.getDefaultValue().equals(val.getSelectedItem());
+ finalh += pbox.getSize().height + fl.getVgap();
+ fh = false;
}
- }
- else
- {
- notmod &= initVal == null;
- }
- argSetModified(this, !notmod);
- }
- public void mouseClicked(MouseEvent e)
- {
- if (javax.swing.SwingUtilities.isRightMouseButton(e))
- {
- showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
}
+ /*
+ * s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
+ * pbox.validate(); s += sep +
+ * pbox.getPreferredSize().height+pbox.getBorder
+ * ().getBorderInsets(pbox).bottom; }
+ *
+ * // paramList.setPreferredSize(new Dimension(w, s));
+ * os+=s+2*sep+paramList
+ * .getBorder().getBorderInsets(paramList).bottom+paramList
+ * .getBorder().getBorderInsets(paramList).top;
+ */
+ paramList.revalidate();
}
-
- 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(OptionI 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)
- {
-
- JPopupMenu mnu = new JPopupMenu();
- JMenuItem mitem = new JMenuItem("View " + finfo);
- mitem.addActionListener(new ActionListener()
- {
-
- @Override
- public void actionPerformed(ActionEvent e)
- {
- Desktop.showUrl(finfo);
-
- }
- });
- mnu.add(mitem);
- mnu.show(invoker, x, y);
- }
-
- protected void refreshParamLayout()
- {
- FlowLayout fl = new FlowLayout();
- paramList.setLayout(fl);
- int s = 2 * fl.getVgap();
- for (ParamBox pbox : paramSet.values())
+ else
{
- s += fl.getVgap() + pbox.getBoxHeight(); // getBoxHeight();
+ paramList.setVisible(false);
}
- paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
- validate();
+ // TODO: waste some time trying to eliminate any unnecessary .validate calls
+ // here
+ // System.out.println("Size will be : "+w+","+os);
+ // optsAndparams.setPreferredSize(null);
+ // paramPane.getViewport().setView(optsAndparams);
+ paramPane.getViewport().setAutoscrolls(true);
+ paramPane.revalidate();
+ revalidate();
}
/**
@@ -1407,7 +929,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
jalview.ws.jws2.Jws2Discoverer disc = jalview.ws.jws2.Jws2Discoverer
.getDiscoverer();
int p = 0;
- if (args.length > 3)
+ if (args.length > 0)
{
Vector services = new Vector();
services.addElement(args[p++]);
@@ -1422,8 +944,8 @@ public class WsJobParameters extends JPanel implements ItemListener,
e.printStackTrace();
return;
}
- Jws2Discoverer.Jws2Instance lastserv = null;
- for (Jws2Discoverer.Jws2Instance service : disc.getServices())
+ Jws2Instance lastserv = null;
+ for (Jws2Instance service : disc.getServices())
{
lastserv = service;
if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
@@ -1466,7 +988,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
{
System.out.println("Testing opts dupes for "
- + lastserv.getHost() + " : "
+ + lastserv.getUri() + " : "
+ lastserv.getActionText() + ":" + pr.getName());
List