args = paramStore.getServiceParameters();
// split to params and required arguments
{
- for (Argument arg : args)
+ for (ArgumentI myarg : args)
{
- Argument myarg = (Argument) arg;
// Ideally, Argument would implement isRequired !
- if (myarg instanceof Parameter)
+ if (myarg instanceof ParameterI)
{
- Parameter parm = (Parameter) myarg;
+ ParameterI parm = (ParameterI) myarg;
addParameter(parm);
}
else
{
- if (myarg instanceof Option)
+ if (myarg instanceof OptionI)
{
- Option opt = (Option) myarg;
- addOption(opt).resetToDefault();
+ OptionI opt = (OptionI) myarg;
+ OptionBox ob = addOption(opt);
+ ob.resetToDefault();
+ if (MAX_OPTWIDTH < ob.getPreferredSize().width)
+ {
+ MAX_OPTWIDTH = ob.getPreferredSize().width;
+ }
+
}
else
{
System.err.println("Ignoring unknown service argument type "
- + arg.getClass().getName());
+ + myarg.getClass().getName());
}
}
}
@@ -497,26 +574,28 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
if (p != null)
{
+ isUserPreset = false;
// initialise setname
setName.setSelectedItem(lastSetName = p.getName());
setDescr.setText(lastDescrText = p.getDescription());
// TODO - URL link
try
{
- args = p.getArguments(serviceOptions);
+ args = p.getArguments();
} catch (Exception e)
{
e.printStackTrace();
}
// TODO: check if args should be unselected prior to resetting using the
// preset
- setargs.clear();
}
else
{
if (lastParmSet == null)
{
+ isUserPreset = false;
// first call - so create a dummy name
+
setName.setSelectedItem(lastSetName = SVC_DEF);
}
}
@@ -529,32 +608,28 @@ public class WsJobParameters extends JPanel implements ItemListener,
// get setargs from current object
if (args != null)
{
- for (Argument arg : args)
+ for (ArgumentI arg : args)
{
- if (arg instanceof Parameter)
+ if (arg instanceof ParameterI)
{
- setParameter((Parameter) arg);
+ setParameter((ParameterI) arg);
}
else
{
- if (arg instanceof Option)
+ if (arg instanceof OptionI)
{
-// System.out.println("Setting option "
-// + System.identityHashCode(arg) + ":" + arg.getName()
-// + " with " + arg.getDefaultValue());
- selectOption((Option) arg, arg.getDefaultValue());
+ // System.out.println("Setting option "
+ // + System.identityHashCode(arg) + ":" + arg.getName()
+ // + " with " + arg.getDefaultValue());
+ selectOption((OptionI) arg, arg.getDefaultValue());
}
}
}
}
- jobOptions.setPreferredSize(new Dimension(PARAM_WIDTH, optSet.size()
- * OPTSET_HEIGHT));
- jobOptions.setLayout(new GridLayout(optSet.size(), 1));
refreshParamLayout();
- paramPane.validate();
- validate();
+ revalidate();
}
private boolean isModified()
@@ -571,9 +646,35 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
curSetName = null;
modifiedElements.clear();
- renmodified.setVisible(false);
- savmodified.setVisible(false);
+ updateButtonDisplay();
+ }
+
+ private void updateButtonDisplay()
+ {
+ boolean _update = false, _create = false, _delete = false, _revert = false;
+ if (modifiedElements.size() > 0)
+ {
+ // set modified
+ _revert = true;
+ _update = isUserPreset; // can only update user presets
+ if (!isUserPreset || modifiedElements.containsKey(setName))
+ {
+ // name modified - can create new preset
+ _create = true;
+ }
+ }
+ else
+ {
+ // set unmodified
+ }
+ // can still delete a user preset
+ _delete = isUserPreset;
+ createpref.setVisible(_create);
+ updatepref.setVisible(_update);
+ deletepref.setVisible(_delete);
+ revertpref.setVisible(_revert);
+ validate();
}
private void argSetModified(Object modifiedElement, boolean b)
@@ -582,46 +683,27 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
return;
}
-
if (!b)
{
modifiedElements.remove(modifiedElement);
}
else
{
- modifiedElements.put(modifiedElement, modifiedElement);
- }
- // set mod status based on presence of elements in table
- if (modifiedElements.size() > 0)
- {
- makeSetNameValid();
- savmodified.setVisible(true);
- revertsetting.setVisible(false);
- }
- else
- {
- revertsetting.setVisible(false);
- deletesetting
- .setVisible(!isServicePreset((String) setName
- .getSelectedItem())
- && _getUserPreset((String) setName.getSelectedItem()) != null);
- savmodified.setVisible(false);
- }
- // special reveal if setName has been modified
- if (modifiedElements.get(setName) != null)
- {
- if (curSetName != null && lastSetName != null
- && !lastSetName.equals(curSetName))
+ if (b && modifiedElement == setName
+ && modifiedElements.contains(modifiedElement))
{
- renmodified.setVisible(!isServicePreset(lastSetName));
+ // HACK! prevents iteration on makeSetNameValid
+ b = false;
}
+ modifiedElements.put(modifiedElement, modifiedElement);
}
- else
+ // set mod status based on presence of elements in table
+ if (b && modifiedElements.size() > 0)
{
- // setname isn't in modlist - so don't rename
- renmodified.setVisible(false);
+ makeSetNameValid(!isUserPreset);
+ SetNamePanel.revalidate();
}
- validate();
+ updateButtonDisplay();
}
private boolean isServicePreset(String selectedItem)
@@ -634,32 +716,33 @@ public class WsJobParameters extends JPanel implements ItemListener,
* check if the current set name is a valid set name for saving, if not, then
* fix it.
*/
- private void makeSetNameValid()
+ private void makeSetNameValid(boolean newuserset)
{
boolean stn = settingDialog;
boolean renamed = false;
settingDialog = true;
- String nm = (String) setName.getSelectedItem();
+ String nm = (curSetName != null ? curSetName : (String) setName
+ .getSelectedItem());
// check if the name is reserved - if it is, rename it.
if (isServicePreset(nm))
{
nm = "User " + nm;
- String tnm=nm;
renamed = true;
- int i=0;
- while (_getUserPreset(tnm)!=null)
+ }
+ String tnm = nm;
+ if (newuserset)
+ {
+ int i = 0;
+ while (paramStore.getPreset(tnm) != null)
{
- tnm = nm+" ("+(++i)+")";
+ tnm = nm + " (" + (++i) + ")";
+ renamed = true;
}
- if (i>0)
+ if (i > 0)
{
nm = tnm;
}
}
- // if ()
- // if nm exists in user's preset store then savmodified will update an
- // existing user defined preset
- // if nm doesn't exist, then the button will create a new preset.
boolean makeupdate = false;
// sync the gui with the preset database
@@ -669,41 +752,37 @@ public class WsJobParameters extends JPanel implements ItemListener,
if (snm.equals(nm))
{
makeupdate = true;
- setName.setSelectedIndex(i);
+ // setName.setSelectedIndex(i);
}
}
-
- if (_getUserPreset(nm) != null)
+ if (!makeupdate)
{
- savmodified.setText("Update");
+ setName.addItem(curSetName = nm);
+ setName.setSelectedItem(curSetName);
}
- else
+ if (renamed)
{
- if (renamed)
- {
- setName.addItem(nm);
- setName.setSelectedIndex(setName.getItemCount() - 1);
- }
- savmodified.setText("Save");
+ settingDialog = false; // we need this name change to be registered.
+ argSetModified(setName, renamed);
}
settingDialog = stn;
}
- private void addParameter(Parameter parm)
+ private void addParameter(ParameterI arg)
{
- ParamBox pb = paramSet.get(parm.getName());
+ ParamBox pb = paramSet.get(arg.getName());
if (pb == null)
{
- pb = new ParamBox(this, parm);
- paramSet.put(parm.getName(), pb);
+ pb = new ParamBox(this, arg);
+ paramSet.put(arg.getName(), pb);
paramList.add(pb);
}
pb.init();
// take the defaults from the parameter
- pb.updateControls(parm);
+ pb.updateControls(arg);
}
- private void setParameter(Parameter arg)
+ private void setParameter(ParameterI arg)
{
ParamBox pb = paramSet.get(arg.getName());
if (pb == null)
@@ -717,27 +796,27 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
- private void selectOption(Option opt, String string)
+ private void selectOption(OptionI option, String string)
{
- OptionBox cb = optSet.get(opt.getName());
+ OptionBox cb = optSet.get(option.getName());
if (cb == null)
{
- cb = addOption(opt);
+ cb = addOption(option);
}
- cb.enabled.setSelected(true); // initial state for an option.
+ cb.enabled.setSelected(string != null); // initial state for an option.
if (string != null)
{
- if (opt.getPossibleValues().contains(string))
+ if (option.getPossibleValues().contains(string))
{
cb.val.setSelectedItem(string);
}
else
{
- throw new Error("Invalid value " + string + " for option " + opt);
+ throw new Error("Invalid value " + string + " for option " + option);
}
}
- if (opt.isRequired() && !cb.enabled.isSelected())
+ if (option.isRequired() && !cb.enabled.isSelected())
{
// TODO: indicate paramset is not valid.. option needs to be selected!
}
@@ -759,7 +838,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
JTextField valueField = null;
- ValueConstrain validator = null;
+ ValueConstrainI validator = null;
JPanel settingPanel = new JPanel();
@@ -775,7 +854,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
final URL finfo;
- public ParamBox(final WsJobParameters pmlayout, Parameter parm)
+ public ParamBox(final WsJobParameters pmlayout, ParameterI parm)
{
pmdialogbox = pmlayout;
setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
@@ -785,23 +864,30 @@ public class WsJobParameters extends JPanel implements ItemListener,
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.setToolTipText(""
+ + JvSwingUtils
+ .wrapTooltip("Click to show brief description
Right click for further information.")
+ + "");
showDesc.addMouseListener(this);
}
else
{
- showDesc.setToolTipText("Click to show brief description.
");
+ showDesc.setToolTipText(""
+ + JvSwingUtils
+ .wrapTooltip("Click to show brief description.")
+ + "");
}
showDesc.addActionListener(new ActionListener()
{
@@ -810,6 +896,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
descisvisible = !descisvisible;
descPanel.setVisible(descisvisible);
+ descPanel.getVerticalScrollBar().setValue(0);
me.setPreferredSize(new Dimension(PARAM_WIDTH,
(descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
me.validate();
@@ -859,7 +946,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
boolean adjusting = false;
- Parameter parameter;
+ ParameterI parameter;
JComboBox choicebox;
@@ -868,12 +955,10 @@ public class WsJobParameters extends JPanel implements ItemListener,
return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
}
- public void updateControls(Parameter parm)
+ public void updateControls(ParameterI parm)
{
adjusting = true;
boolean init = (choicebox == null && valueField == null);
- float fVal = 0f;
- int iVal = 0;
if (init)
{
if (choice)
@@ -924,23 +1009,16 @@ public class WsJobParameters extends JPanel implements ItemListener,
Object lastVal;
- public Parameter getParameter()
+ public ParameterI getParameter()
{
- Parameter prm = ParameterUtils.copyParameter(parameter);
- try
+ ParameterI prm = parameter.copy();
+ if (choice)
{
- if (choice)
- {
- prm.setDefaultValue((String) choicebox.getSelectedItem());
- }
- else
- {
- prm.setDefaultValue(valueField.getText());
- }
- } catch (WrongParameterException e)
+ prm.setDefaultValue((String) choicebox.getSelectedItem());
+ }
+ else
{
- e.printStackTrace();
- return null;
+ prm.setDefaultValue(valueField.getText());
}
return prm;
}
@@ -958,6 +1036,20 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
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() < iVal)
+ {
+ iVal = validator.getMax().intValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
} catch (Exception e)
{
}
@@ -981,6 +1073,20 @@ public class WsJobParameters extends JPanel implements ItemListener,
try
{
fVal = Float.valueOf(valueField.getText());
+ if (validator.getMin() != null
+ && validator.getMin().floatValue() > fVal)
+ {
+ fVal = validator.getMin().floatValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
+ if (validator.getMax() != null
+ && validator.getMax().floatValue() < fVal)
+ {
+ fVal = validator.getMax().floatValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
} catch (Exception e)
{
}
@@ -1067,7 +1173,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
if (javax.swing.SwingUtilities.isRightMouseButton(e))
{
- Desktop.showUrl(finfo.toString());
+ showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
}
}
@@ -1094,7 +1200,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
// TODO Auto-generated method stub
}
+ // from http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
+ // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
+ @Override
+ public Component.BaselineResizeBehavior getBaselineResizeBehavior() {
+ return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
+ }
+ @Override
+ public int getBaseline(int width, int height) {
+ return 0;
+ }
}
Map optSet = new Hashtable();
@@ -1108,15 +1224,13 @@ public class WsJobParameters extends JPanel implements ItemListener,
JLabel optlabel = new JLabel();
- URL linkImageURL = getClass().getResource("/images/link.gif");
-
final URL finfo;
boolean hasLink = false;
- Option option;
+ OptionI option;
- public OptionBox(Option opt)
+ public OptionBox(OptionI opt)
{
option = opt;
setLayout(new BorderLayout());
@@ -1129,16 +1243,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
if (finfo != null)
{
hasLink = true;
- // optlabel.setToolTipText(""+opt.getDescription()+"
");
- enabled.setToolTipText("" + opt.getDescription()
- + "
");
- // optlabel.addMouseListener(this);
+ enabled.setToolTipText(""
+ + JvSwingUtils.wrapTooltip(opt.getDescription()
+ + "
")
+ + "");
enabled.addMouseListener(this);
}
else
{
- // optlabel.setToolTipText(opt.getDescription());
- enabled.setToolTipText(opt.getDescription());
+ enabled.setToolTipText(""
+ + JvSwingUtils.wrapTooltip(opt.getDescription())
+ + "");
}
add(enabled, BorderLayout.NORTH);
if (opt.getPossibleValues().size() > 1)
@@ -1154,7 +1269,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
// TODO: add actionListeners for popup (to open further info),
// and to update list of parameters if an option is enabled
- // that takes a value.
+ // that takes a value. JBPNote: is this TODO still valid ?
setInitialValue();
}
@@ -1182,30 +1297,23 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
else
{
- initVal = null;
+ initVal = (initEnabled) ? option.getDefaultValue() : null;
}
}
- public Option getOptionIfEnabled()
+ public OptionI getOptionIfEnabled()
{
if (!enabled.isSelected())
{
return null;
}
- try
- {
- Option opt = jalview.ws.jws2.ParameterUtils.copyOption(option);
+ OptionI opt = option.copy();
- if (val.getSelectedItem() != null)
- {
- opt.setDefaultValue((String) val.getSelectedItem());
- }
- } catch (WrongParameterException e)
+ if (val.getSelectedItem() != null)
{
- e.printStackTrace();
- return null;
+ opt.setDefaultValue((String) val.getSelectedItem());
}
- return option;
+ return opt;
}
public void actionPerformed(ActionEvent e)
@@ -1220,9 +1328,22 @@ public class WsJobParameters extends JPanel implements ItemListener,
private void checkIfModified()
{
boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected() && initVal != null)
+ if (enabled.isSelected())
+ {
+ if (initVal != null)
+ {
+ notmod &= initVal.equals(val.getSelectedItem());
+ }
+ else
+ {
+ // compare against default service setting
+ notmod &= option.getDefaultValue() == null
+ || option.getDefaultValue().equals(val.getSelectedItem());
+ }
+ }
+ else
{
- notmod |= initVal.equals(val.getSelectedItem());
+ notmod &= initVal == null;
}
argSetModified(this, !notmod);
}
@@ -1261,14 +1382,14 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
- private OptionBox addOption(Option opt)
+ 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);
+ jobOptions.add(cb, FlowLayout.LEFT);
}
return cb;
}
@@ -1295,13 +1416,58 @@ public class WsJobParameters extends JPanel implements ItemListener,
protected void refreshParamLayout()
{
- int s = 100;
- for (ParamBox pbox : paramSet.values())
+ FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
+ int sep=fl.getVgap();
+ int os=0,s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom+jobOptions.getBorder().getBorderInsets(jobOptions).top+2 * sep;
+ int w = 2 * fl.getHgap() + (MAX_OPTWIDTH > PARAM_WIDTH ? MAX_OPTWIDTH : PARAM_WIDTH);
+ jobOptions.setLayout(fl);
+ if (optSet.size() > 0)
+ {
+
+ for (OptionBox pbox : optSet.values())
+ {
+ pbox.revalidate();
+ s += sep + pbox.getPreferredSize().height;
+ }
+ jobOptions.setPreferredSize(new Dimension(w, s));
+ jobOptions.setLayout(new GridLayout(optSet.size(),1));
+ os=s;
+ }
+ else
+ {
+ jobOptions.setVisible(false);
+ }
+
+ // Now layout the parameters assuming they occupy one column - to calculate total height of options+parameters
+ fl = new FlowLayout(FlowLayout.CENTER);
+ // helpful hint from http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
+ fl.setAlignOnBaseline(true);
+ if (paramSet.size() > 0)
+ {
+ paramList.setLayout(fl);
+
+ s = 2 * sep;
+ for (ParamBox pbox : paramSet.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;
+ }
+ else
{
- s += pbox.getBoxHeight();
+ paramList.setVisible(false);
}
- paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s));
- paramList.setLayout(new FlowLayout());
+ // TODO: waste some time trying to eliminate any unnecessary .validate calls here
+ paramList.validate();
+ jobOptions.validate();
+ // System.out.println("Size will be : "+w+","+os);
+ optsAndparams.validate();
+ paramPane.getViewport().validate();
+ paramPane.getVerticalScrollBar().setBlockIncrement(PARAM_CLOSEDHEIGHT*2);
+ paramPane.validate();
validate();
}
@@ -1315,7 +1481,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++]);
@@ -1352,14 +1518,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
prl = prman.getPresets();
}
}
- } else {
+ }
+ else
+ {
PresetManager prman = lastserv.getPresets();
- if (prman!=null) {
+ if (prman != null)
+ {
prl = prman.getPresets();
}
}
Iterator en = (prl == null) ? null : prl.iterator();
- while (en!=null && en.hasNext())
+ while (en != null && en.hasNext())
{
if (en != null)
{
@@ -1370,7 +1539,9 @@ public class WsJobParameters extends JPanel implements ItemListener,
pr = en.next();
}
{
- System.out.println("Testing opts dupes for "+lastserv.getHost()+" : "+lastserv.getActionText()+":"+pr.getName());
+ System.out.println("Testing opts dupes for "
+ + lastserv.getUri() + " : "
+ + lastserv.getActionText() + ":" + pr.getName());
List