X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=inline;f=src%2Fjalview%2Fgui%2FWsJobParameters.java;h=8abbcee1a6b95c40e10d9d97d5014a40cd18d5f3;hb=d83db1c05bf39e076ce0cd53635bedf7e89afed1;hp=b651833c42962bebcca0e530b172ed3c805f37bd;hpb=c6016c2fdffb1f7f84e44fbc0a1c0630d89ca17e;p=jalview.git
diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java
index b651833..8abbcee 100644
--- a/src/jalview/gui/WsJobParameters.java
+++ b/src/jalview/gui/WsJobParameters.java
@@ -1,62 +1,72 @@
+/*
+ * Jalview - A Sequence Alignment Editor and Viewer (Version 2.8)
+ * Copyright (C) 2012 J Procter, AM Waterhouse, LM Lui, J Engelhardt, G Barton, M Clamp, S Searle
+ *
+ * This file is part of Jalview.
+ *
+ * Jalview is free software: you can redistribute it and/or
+ * modify it under the terms of the GNU General Public License
+ * as published by the Free Software Foundation, either version 3 of the License, or (at your option) any later version.
+ *
+ * Jalview is distributed in the hope that it will be useful, but
+ * WITHOUT ANY WARRANTY; without even the implied warranty
+ * of MERCHANTABILITY or FITNESS FOR A PARTICULAR
+ * PURPOSE. See the GNU General Public License for more details.
+ *
+ * You should have received a copy of the GNU General Public License along with Jalview. If not, see .
+ */
package jalview.gui;
+import jalview.gui.OptsAndParamsPage.OptionBox;
+import jalview.gui.OptsAndParamsPage.ParamBox;
+import jalview.ws.jws2.JabaParamStore;
+import jalview.ws.jws2.JabaPreset;
+import jalview.ws.jws2.Jws2Discoverer;
+import jalview.ws.jws2.jabaws2.Jws2Instance;
+import jalview.ws.params.ArgumentI;
+import jalview.ws.params.OptionI;
+import jalview.ws.params.ParamDatastoreI;
+import jalview.ws.params.ParameterI;
+import jalview.ws.params.WsParamSetI;
+
import java.awt.BorderLayout;
-import java.awt.Color;
import java.awt.Component;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
+import java.awt.GridBagConstraints;
+import java.awt.GridBagLayout;
import java.awt.GridLayout;
import java.awt.Rectangle;
import java.awt.event.ActionEvent;
import java.awt.event.ActionListener;
-import java.awt.event.ComponentEvent;
-import java.awt.event.ComponentListener;
-import java.awt.event.ContainerEvent;
-import java.awt.event.ContainerListener;
+import java.awt.event.HierarchyBoundsListener;
+import java.awt.event.HierarchyEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
-import java.awt.event.KeyEvent;
-import java.awt.event.KeyListener;
-import java.awt.event.MouseEvent;
-import java.awt.event.MouseListener;
import java.awt.event.WindowEvent;
import java.awt.event.WindowListener;
-import java.awt.event.WindowStateListener;
-import java.util.ArrayList;
-import java.util.EventObject;
-import java.util.HashSet;
+import java.net.URL;
import java.util.Hashtable;
import java.util.Iterator;
import java.util.List;
-import java.util.Map;
import java.util.Vector;
import javax.swing.JButton;
-import javax.swing.JCheckBox;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
-import javax.swing.JList;
import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
-import javax.swing.JSlider;
import javax.swing.JSplitPane;
-import javax.swing.JTable;
import javax.swing.JTextArea;
-import javax.swing.JTextField;
-import javax.swing.ListSelectionModel;
-import javax.swing.SwingConstants;
-import javax.swing.SwingUtilities;
import javax.swing.border.TitledBorder;
-import javax.swing.event.CellEditorListener;
-import javax.swing.event.ChangeEvent;
-import javax.swing.event.ChangeListener;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
-import javax.swing.table.*;
+
+import net.miginfocom.swing.MigLayout;
import compbio.metadata.Argument;
import compbio.metadata.Option;
@@ -64,12 +74,6 @@ import compbio.metadata.Parameter;
import compbio.metadata.Preset;
import compbio.metadata.PresetManager;
import compbio.metadata.RunnerConfig;
-import compbio.metadata.ValueConstrain;
-import compbio.metadata.WrongParameterException;
-import compbio.metadata.ValueConstrain.Type;
-
-import jalview.ws.jws2.Jws2Discoverer;
-import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
/**
* job parameter editing/browsing dialog box. User can browse existing settings
@@ -87,16 +91,28 @@ import jalview.ws.jws2.Jws2Discoverer.Jws2Instance;
*
*/
public class WsJobParameters extends JPanel implements ItemListener,
- ActionListener, DocumentListener
+ ActionListener, DocumentListener, OptsParametersContainerI
{
+ URL linkImageURL = getClass().getResource("/images/link.gif");
+
private static final String SVC_DEF = "Defaults"; // this is the null
// parameter set as shown to
// user
- private static final int PARAM_WIDTH = 340, PARAM_HEIGHT = 150,
- PARAM_CLOSEDHEIGHT = 80;
+ /**
+ * manager for options and parameters.
+ */
+ OptsAndParamsPage opanp = new OptsAndParamsPage(this);
+
+ /**
+ * panel containing job options
+ */
+ JPanel jobOptions = new JPanel();
- private static final int OPTSET_HEIGHT = 30;
+ /**
+ * panel containing job parameters
+ */
+ JPanel paramList = new JPanel();
JPanel SetNamePanel = new JPanel();
@@ -104,21 +120,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
JSplitPane settingsPanel = new JSplitPane();
- JSplitPane jobPanel = new JSplitPane();
-
- JPanel jobOptions = new JPanel();
+ JPanel jobPanel = new JPanel();
JScrollPane jobOptionsPane = new JScrollPane();
- JPanel jobParameters = new JPanel();
-
- JButton savmodified = new JButton();
+ JButton createpref = new JButton();
- JButton renmodified = new JButton();
+ JButton deletepref = new JButton();
- JButton deletesetting = new JButton();
+ JButton revertpref = new JButton();
- JButton revertsetting = new JButton();
+ JButton updatepref = new JButton();
JButton startjob = new JButton();
@@ -130,21 +142,23 @@ public class WsJobParameters extends JPanel implements ItemListener,
JScrollPane paramPane = new JScrollPane();
- // JList paramList = new JList();
- JPanel paramList = new JPanel();
+ // ScrollablePanel optsAndparams = new ScrollablePanel();
+ JPanel optsAndparams = new JPanel();
RunnerConfig serviceOptions;
- private BorderLayout jparamLayout;
+ ParamDatastoreI paramStore;
+
+ private int MAX_OPTWIDTH = 200;
WsJobParameters(Jws2Instance service)
{
this(service, null);
}
- public WsJobParameters(Jws2Instance service, Preset p)
+ public WsJobParameters(Jws2Instance service, WsParamSetI preset)
{
- this(null, service, p, null);
+ this(null, service, preset, null);
}
/**
@@ -152,16 +166,36 @@ public class WsJobParameters extends JPanel implements ItemListener,
* @param desktop
* - if null, create new JFrame outside of desktop
* @param service
- * @param p
+ * @param preset
*/
- public WsJobParameters(JFrame parent, Jws2Instance service, Preset p,
- List jobArgset)
+ public WsJobParameters(JFrame parent, Jws2Instance service,
+ WsParamSetI preset, List jobArgset)
+ {
+ this(parent, null, service, preset, jobArgset);
+ }
+
+ /**
+ *
+ * @param parent
+ * @param paramStorei
+ * @param service
+ * @param preset
+ * @param jobArgset
+ */
+ public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei,
+ Jws2Instance service, WsParamSetI preset, List jobArgset)
{
super();
jbInit();
+ this.paramStore = paramStorei;
+ if (paramStore == null)
+ {
+ paramStore = service.getParamStore();
+ }
+ this.service = service;
// argSetModified(false);
// populate parameter table
- initForService(service, p, jobArgset);
+ initForService(service, preset, jobArgset);
// display in new JFrame attached to parent.
validate();
}
@@ -170,6 +204,11 @@ public class WsJobParameters extends JPanel implements ItemListener,
JDialog frame = null;
+ /**
+ * shows a modal dialog containing the parameters.
+ *
+ * @return
+ */
public boolean showRunDialog()
{
@@ -177,10 +216,24 @@ public class WsJobParameters extends JPanel implements ItemListener,
frame.setTitle("Edit parameters for " + service.getActionText());
Rectangle deskr = Desktop.instance.getBounds();
- frame.setBounds(new Rectangle((int) (deskr.getCenterX() - 240),
- (int) (deskr.getCenterY() - 92), 380, 385));
+ Dimension pref = this.getPreferredSize();
+ frame.setBounds(new Rectangle(
+ (int) (deskr.getCenterX() - pref.width / 2), (int) (deskr
+ .getCenterY() - pref.height / 2), pref.width,
+ pref.height));
frame.setContentPane(this);
+ // should perhaps recover defaults from user prefs.
+
+ frame.validate();
+ javax.swing.SwingUtilities.invokeLater(new Runnable()
+ {
+ public void run()
+ {
+ // jobPanel.setDividerLocation(0.25);
+
+ }
+ });
frame.setVisible(true);
if (response > 0)
@@ -190,78 +243,80 @@ public class WsJobParameters extends JPanel implements ItemListener,
return false;
}
- protected JButton makeButton(String label, String tooltip,
- ActionListener action)
- {
- JButton button = new JButton();
- button.setText(label);
- button.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- button.setForeground(Color.black);
- button.setHorizontalAlignment(SwingConstants.CENTER);
- button.setToolTipText(tooltip);
- button.addActionListener(action);
- return button;
- }
-
private void jbInit()
{
- savmodified = makeButton("Save", "Not implemented yet :) ",
+ this.addHierarchyBoundsListener(new HierarchyBoundsListener()
+ {
+
+ @Override
+ public void ancestorResized(HierarchyEvent arg0)
+ {
+ refreshParamLayout();
+ }
+
+ @Override
+ public void ancestorMoved(HierarchyEvent arg0)
+ {
+ // TODO Auto-generated method stub
+
+ }
+ });
+ updatepref = JvSwingUtils.makeButton("Update",
+ "Update this existing user parameter set.",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- savModified_actionPerformed(e);
+ update_actionPerformed(e);
}
});
- renmodified = makeButton("Rename", "Not implemented yet :) ",
+ deletepref = JvSwingUtils.makeButton("Delete",
+ "Delete the currently selected user parameter set.",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- renModified_actionPerformed(e);
+ delete_actionPerformed(e);
}
});
- deletesetting = makeButton("Delete", "Not implemented yet :) ",
+ createpref = JvSwingUtils.makeButton("Create",
+ "Create a new parameter set with the current settings.",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- deleteSetting_actionPerformed(e);
+ create_actionPerformed(e);
}
});
- revertsetting = makeButton("Revert", "Undo changes to parameters.",
+ revertpref = JvSwingUtils.makeButton("Revert",
+ "Undo all changes to the current parameter set",
new ActionListener()
{
public void actionPerformed(ActionEvent e)
{
- revertSetting_actionPerformed(e);
+ revert_actionPerformed(e);
+ }
+ });
+ startjob = JvSwingUtils.makeButton("Start Job",
+ "Start Job with current settings.", new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ startjob_actionPerformed(e);
+ }
+ });
+ canceljob = JvSwingUtils.makeButton("Cancel Job",
+ "Close this dialog and cancel job.", new ActionListener()
+ {
+ public void actionPerformed(ActionEvent e)
+ {
+ canceljob_actionPerformed(e);
}
});
-
- startjob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- startjob.setText("Start");
- startjob.setToolTipText("Start Job");
- startjob.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- startjob_actionPerformed(e);
- }
- });
- canceljob.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
- canceljob.setText("Cancel");
- canceljob.setToolTipText("Cancel Job");
- canceljob.addActionListener(new ActionListener()
- {
- public void actionPerformed(ActionEvent e)
- {
- canceljob_actionPerformed(e);
- }
- });
setDetails.setBorder(new TitledBorder("Details"));
setDetails.setLayout(new BorderLayout());
@@ -271,105 +326,142 @@ public class WsJobParameters extends JPanel implements ItemListener,
setDescr.setBackground(getBackground());
setDescr.setEditable(true);
setDescr.getDocument().addDocumentListener(this);
+ setDescr.setToolTipText("Click to edit the notes for this parameter set.");
JScrollPane setDescrView = new JScrollPane();
// setDescrView.setPreferredSize(new Dimension(350, 200));
setDescrView.getViewport().setView(setDescr);
setName.setEditable(true);
setName.addItemListener(this);
setName.getEditor().addActionListener(this);
- SetNamePanel.setLayout(new BorderLayout());
- SetNamePanel.add(setName, BorderLayout.WEST);
+ JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
+ GridBagLayout gbl = new GridBagLayout();
+ SetNamePanel.setLayout(gbl);
+
+ JLabel setNameLabel = new JLabel("Current parameter set name :");
+ setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
+
+ setNameInfo.add(setNameLabel);
+ setNameInfo.add(setName);
+
// initial button visibility
- deletesetting.setVisible(false);
- revertsetting.setVisible(false);
- renmodified.setVisible(false);
- savmodified.setVisible(false);
+ updatepref.setVisible(false);
+ deletepref.setVisible(false);
+ revertpref.setVisible(false);
+ createpref.setVisible(false);
JPanel setsavebuts = new JPanel();
- setsavebuts.setLayout(new FlowLayout());
- setsavebuts.add(revertsetting, BorderLayout.CENTER);
- setsavebuts.add(renmodified, BorderLayout.CENTER);
- setsavebuts.add(deletesetting, BorderLayout.CENTER);
- setsavebuts.add(savmodified, BorderLayout.EAST);
- SetNamePanel.add(setsavebuts,BorderLayout.EAST);
+ setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
+ ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
+ ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
+ JPanel spacer = new JPanel();
+ spacer.setPreferredSize(new Dimension(2, 30));
+ setsavebuts.add(spacer);
+ setsavebuts.add(deletepref);
+ setsavebuts.add(revertpref);
+ setsavebuts.add(createpref);
+ setsavebuts.add(updatepref);
+ // setsavebuts.setSize(new Dimension(150, 30));
+ JPanel buttonArea = new JPanel(new GridLayout(1, 1));
+ buttonArea.add(setsavebuts);
+ SetNamePanel.add(setNameInfo);
+ GridBagConstraints gbc = new GridBagConstraints();
+ gbc.gridheight = 2;
+ gbl.setConstraints(setNameInfo, gbc);
+ SetNamePanel.add(buttonArea);
+ gbc = new GridBagConstraints();
+ gbc.gridx = 0;
+ gbc.gridy = 2;
+ gbc.gridheight = 1;
+ gbl.setConstraints(buttonArea, gbc);
setDetails.add(setDescrView, BorderLayout.CENTER);
- // setDetails.setPreferredSize(new Dimension(360, 100));
- jobParameters.setBorder(new TitledBorder("Parameters"));
- jobParameters.setLayout(jparamLayout = new BorderLayout());
- paramPane.setPreferredSize(new Dimension(360, 300));
- paramPane.getVerticalScrollBar().setUnitIncrement(20);
- // paramPanel.setPreferredSize(new Dimension(360, 300));
- // TODO: relayout buttons nicely
- paramPane.getViewport().setView(paramList);
- jobParameters.add(paramPane, BorderLayout.CENTER);
- JPanel jobOptionsPanel = new JPanel();
- jobOptionsPanel.setLayout(new BorderLayout());
- jobOptionsPanel.setBorder(new TitledBorder("Options"));
- jobOptionsPane.getViewport().setView(jobOptions);
- jobOptionsPanel.add(jobOptionsPane, BorderLayout.CENTER);
- settingsPanel.setLeftComponent(jobOptionsPanel);
- settingsPanel.setRightComponent(jobParameters);
- settingsPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
- settingsPanel.setDividerLocation(0.4);
+ // paramPane.setPreferredSize(new Dimension(360, 400));
+ // paramPane.setPreferredSize(null);
+ jobOptions.setBorder(new TitledBorder("Options"));
+ jobOptions.setOpaque(true);
+ paramList.setBorder(new TitledBorder("Parameters"));
+ paramList.setOpaque(true);
+ JPanel bjo = new JPanel(new BorderLayout()), bjp = new JPanel(
+ new BorderLayout());
+ bjo.add(jobOptions, BorderLayout.CENTER);
+ bjp.add(paramList, BorderLayout.CENTER);
+ bjp.setOpaque(true);
+ bjo.setOpaque(true);
+ // optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
+ // optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
+ // optsAndparams.setLayout(new BorderLayout());
+ optsAndparams.setLayout(new BorderLayout());
+ optsAndparams.add(jobOptions, BorderLayout.NORTH);
+ optsAndparams.add(paramList, BorderLayout.CENTER);
+ JPanel jp = new JPanel(new BorderLayout());
+ jp.add(optsAndparams, BorderLayout.CENTER);
+ paramPane.getViewport().setView(jp);
+ paramPane.setBorder(null);
setLayout(new BorderLayout());
- // setPreferredSize(new Dimension(400, 600));
- // setSize(new Dimension(400, 600));
- jobPanel.setLeftComponent(setDetails);
- jobPanel.setRightComponent(settingsPanel);
- jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
- jobPanel.setDividerLocation(0.8);
+ jobPanel.setPreferredSize(null);
+ jobPanel.setLayout(new BorderLayout());
+ jobPanel.add(setDetails, BorderLayout.NORTH);
+ jobPanel.add(paramPane, BorderLayout.CENTER);
+ // jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT);
+
add(SetNamePanel, BorderLayout.NORTH);
add(jobPanel, BorderLayout.CENTER);
+
JPanel dialogpanel = new JPanel();
dialogpanel.add(startjob);
dialogpanel.add(canceljob);
add(dialogpanel, BorderLayout.SOUTH);
+ validate();
}
- protected void revertSetting_actionPerformed(ActionEvent e)
+ protected void revert_actionPerformed(ActionEvent e)
{
- // TODO Auto-generated method stub
+ reInitDialog(lastParmSet);
}
- protected void deleteSetting_actionPerformed(ActionEvent e)
+ protected void update_actionPerformed(ActionEvent e)
{
- String setname = (String) setName.getSelectedItem();
- int p=setName.getSelectedIndex();
- if (_getUserPreset(setname)!=null)
+ if (isUserPreset)
{
- _deleteUserPreset(setname);
-
+ String curname = ((String) setName.getSelectedItem()).trim();
+ _updatePreset(lastParmSet, curname);
+ lastParmSet = curname;
+ isUserPreset = true;
+ initArgSetModified();
+ syncSetNamesWithStore();
}
- if (p>0 && p+1==setName.getItemCount())
- {
- p--;
- }
- setName.setSelectedIndex(p);
-
}
- protected void renModified_actionPerformed(ActionEvent e)
+ private void _deleteUserPreset(String lastParmSet2)
{
- if (curSetName==null || _getUserPreset(lastSetName)==null) {
- System.err.println("can't rename - names unchanged or original name not a preset.");
- return;
+ paramStore.deletePreset(lastParmSet2);
+ }
+
+ protected void delete_actionPerformed(ActionEvent e)
+ {
+ if (isUserPreset)
+ {
+ // delete current preset's saved entry
+ _deleteUserPreset(lastParmSet);
}
- _deleteUserPreset(lastSetName);
- lastSetName=curSetName;
- savModified_actionPerformed(e);
- curSetName=null;
- boolean setd = settingDialog;
- settingDialog=true;
- syncSetNamesWithStore();
- settingDialog=setd;
+ reInitDialog(null); // service default
}
- protected void savModified_actionPerformed(ActionEvent e)
+ protected void create_actionPerformed(ActionEvent e)
{
- _storeUserPreset(lastSetName=(String) setName.getSelectedItem(), setDescr.getText(), getJobParams());
- curSetName=null;
- initArgSetModified(); // reset the modification state
+ String curname = ((String) setName.getSelectedItem()).trim();
+ if (curname.length() > 0)
+ {
+ _storeCurrentPreset(curname);
+ lastParmSet = curname;
+ isUserPreset = true;
+ initArgSetModified();
+ }
+ else
+ {
+ // TODO: show warning
+ System.err.println("Invalid name. Not saved.");
+ }
}
protected void canceljob_actionPerformed(ActionEvent e)
@@ -402,80 +494,110 @@ public class WsJobParameters extends JPanel implements ItemListener,
*/
boolean settingDialog = false;
- void initForService(Jws2Instance service, Preset p,
- List jobArgset)
+ void initForService(Jws2Instance service, WsParamSetI jabap,
+ List jabajobArgset)
{
+ WsParamSetI p = null;
+ List jobArgset = null;
settingDialog = true;
- this.service = service;
- // TODO: Recover window geometry prefs for this service
- // jobPanel.setDividerLocation(proportionalLocation)
- // settingsPanel.setDividerLocation(proportionalLocation)
+ { // instantiate the abstract proxy for Jaba objects
+ jobArgset = jabajobArgset == null ? null : JabaParamStore
+ .getJwsArgsfromJaba(jabajobArgset);
+ p = jabap; // (jabap != null) ? paramStore.getPreset(jabap.getName()) :
+ // null;
+ }
+
Hashtable exnames = new Hashtable();
for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
{
exnames.put((String) setName.getItemAt(i), setName.getItemAt(i));
}
+ servicePresets = new Hashtable();
// Add the default entry - if not present already.
if (!exnames.contains(SVC_DEF))
{
setName.addItem(SVC_DEF);
exnames.put(SVC_DEF, SVC_DEF);
+ servicePresets.put(SVC_DEF, SVC_DEF);
}
- serviceOptions = service.getRunnerConfig();
- // add any presets not already added.
String curname = (p == null ? "" : p.getName());
- PresetManager prman = service.getPresets();
- servicePresets = new Hashtable();
- if (prman != null)
+ for (WsParamSetI pr : paramStore.getPresets())
{
- List prList = service.getPresets().getPresets();
- if (prList != null)
+ if (!pr.isModifiable())
{
- for (Object pr : prList)
- {
- servicePresets.put(((Preset) pr).getName(), "preset");
- if (!exnames.contains(((Preset) pr).getName()))
- {
- setName.addItem(((Preset) pr).getName());
- }
- }
+ servicePresets.put(pr.getName(), "preset");
+ }
+ else
+ {
+ }
+ if (!exnames.contains(pr.getName()))
+ {
+ setName.addItem(pr.getName());
+ }
+ }
+ // TODO: if initial jobArgset matches a given user setting or preset then
+ // should recover setting accordingly
+ // updateTable(p, jobArgset);
+ if (p != null)
+ {
+ reInitDialog(p.getName());
+ initArgSetModified();
+ }
+ else
+ {
+ if (jobArgset != null && jobArgset.size() > 0)
+ {
+ curSetName = "Supplied Settings";
+ isUserPreset = false;
+ updateTable(p, jobArgset);
+ setName.setSelectedItem(curSetName);
+ updateButtonDisplay();
+ }
+ else
+ {
+ curSetName = null;
+ reInitDialog(null);
}
}
- updateTable(p, jobArgset);
- initArgSetModified();
settingDialog = false;
}
@SuppressWarnings("unchecked")
- private void updateTable(Preset p, List jobArgset)
+ private void updateTable(WsParamSetI p, List jobArgset)
{
- List setargs = new ArrayList();
// populate table from default parameter set.
- List args = serviceOptions.getArguments();
+ List args = paramStore.getServiceParameters();
// split to params and required arguments
{
- for (Argument arg : args)
+ int cw = 0;
+ 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;
- addParameter(parm);
+ ParameterI parm = (ParameterI) myarg;
+ opanp.addParameter(parm).validate();
}
else
{
- if (myarg instanceof Option)
+ if (myarg instanceof OptionI)
{
- Option opt = (Option) myarg;
- addOption(opt).resetToDefault();
+ OptionI opt = (OptionI) myarg;
+ OptionBox ob = opanp.addOption(opt);
+ ob.resetToDefault();
+ if (MAX_OPTWIDTH < ob.getPreferredSize().width)
+ {
+ MAX_OPTWIDTH = ob.getPreferredSize().width;
+ }
+ ob.validate();
+ cw += ob.getPreferredSize().width + 5;
}
else
{
System.err.println("Ignoring unknown service argument type "
- + arg.getClass().getName());
+ + myarg.getClass().getName());
}
}
}
@@ -483,26 +605,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);
}
}
@@ -515,31 +639,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);
+ opanp.setParameter((ParameterI) arg);
}
else
{
- if (arg instanceof Option)
+ if (arg instanceof OptionI)
{
- System.out.println("Setting option " + arg.getName() + " with "
- + arg.getDefaultValue());
- selectOption((Option) arg, arg.getDefaultValue());
+ // System.out.println("Setting option "
+ // + System.identityHashCode(arg) + ":" + arg.getName()
+ // + " with " + arg.getDefaultValue());
+ opanp.selectOption((OptionI) arg, arg.getValue());
}
}
}
}
- 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()
@@ -556,57 +677,64 @@ 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)
+ public void argSetModified(Object modifiedElement, boolean b)
{
if (settingDialog)
{
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)
@@ -619,22 +747,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;
renamed = true;
}
- // 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.
+ String tnm = nm;
+ if (newuserset)
+ {
+ int i = 0;
+ while (paramStore.getPreset(tnm) != null)
+ {
+ tnm = nm + " (" + (++i) + ")";
+ renamed = true;
+ }
+ if (i > 0)
+ {
+ nm = tnm;
+ }
+ }
boolean makeupdate = false;
// sync the gui with the preset database
@@ -644,783 +783,492 @@ 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)
+ public void refreshParamLayout()
{
- ParamBox pb = paramSet.get(parm.getName());
- if (pb == null)
+ // 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)
{
- pb = new ParamBox(this, parm);
- paramSet.put(parm.getName(), pb);
- paramList.add(pb);
- }
- pb.init();
- // take the defaults from the parameter
- pb.updateControls(parm);
- }
-
- private void setParameter(Parameter arg)
- {
- ParamBox pb = paramSet.get(arg.getName());
- if (pb == null)
- {
- addParameter(arg);
- }
- else
- {
- pb.updateControls(arg);
- }
- }
+ jobOptions.setLayout(new MigLayout("", "", ""));
+ jobOptions.removeAll();
- private void selectOption(Option opt, String string)
- {
- OptionBox cb = optSet.get(opt.getName());
- if (cb == null)
- {
- cb = addOption(opt);
- }
- cb.enabled.setSelected(true); // initial state for an option.
- if (string != null)
- {
- if (opt.getPossibleValues().contains(string))
- {
- cb.val.setSelectedItem(string);
- }
- else
+ for (OptionBox pbox : opanp.getOptSet().values())
{
- throw new Error("Invalid value " + string + " for option " + opt);
+ pbox.validate();
+ cw += pbox.getSize().width + hgap;
+ if (cw + 120 > panewidth)
+ {
+ jobOptions.add(pbox, "wrap");
+ // System.out.println("Wrap on "+pbox.option.getName());
+ cw = hgap + pbox.getSize().width;
+ fh = true;
+ }
+ else
+ {
+ jobOptions.add(pbox);
+ }
+ if (fh)
+ {
+ finalh += pbox.getSize().height + fl.getVgap();
+ fh = false;
+ }
}
-
+ jobOptions.revalidate();
}
- if (opt.isRequired() && !cb.enabled.isSelected())
+ else
{
- // TODO: indicate paramset is not valid.. option needs to be selected!
+ jobOptions.setVisible(false);
}
- cb.setInitialValue();
- }
-
- Map paramSet = new Hashtable();
-
- public class ParamBox extends JPanel implements ChangeListener,
- ActionListener
- {
- JButton showDesc = new JButton();
-
- JTextArea string = new JTextArea();
-
- JScrollPane descPanel = new JScrollPane();
- JSlider slider = null;
-
- JTextField valueField = null;
-
- ValueConstrain validator = null;
-
- JPanel settingPanel = new JPanel();
-
- JPanel controlPanel = new JPanel();
-
- boolean integ = false;
-
- boolean choice = false;
-
- boolean descisvisible = false;
-
- final WsJobParameters pmdialogbox;
-
- public ParamBox(final WsJobParameters pmlayout, Parameter parm)
+ // 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)
{
- 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;
- showDesc.addActionListener(new ActionListener()
+ paramList.removeAll();
+ paramList.setLayout(new MigLayout("", "", ""));
+ fh = true;
+ for (ParamBox pbox : opanp.getParamSet().values())
{
-
- @Override
- public void actionPerformed(ActionEvent e)
+ pbox.validate();
+ cw += pbox.getSize().width + hgap;
+ if (cw + 160 > panewidth)
{
- descisvisible = !descisvisible;
- descPanel.setVisible(descisvisible);
- me.setPreferredSize(new Dimension(PARAM_WIDTH,
- (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT));
- me.validate();
- pmlayout.refreshParamLayout();
+ paramList.add(pbox, "wrap");
+ cw = pbox.getSize().width + hgap;
+ fh = true;
}
- });
- 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
- {
- if (parameter.getPossibleValues() != null)
+ else
{
- choice = true;
+ paramList.add(pbox);
}
+ if (fh)
+ {
+ finalh += pbox.getSize().height + fl.getVgap();
+ fh = false;
+ }
+
}
- updateControls(parm);
- descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT,
- PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5));
- add(descPanel);
- validate();
+ /*
+ * 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 init()
+ else
{
- // reset the widget's initial value.
- lastVal = null;
+ paramList.setVisible(false);
}
+ // 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();
+ }
- boolean adjusting = false;
-
- Parameter parameter;
-
- JComboBox choicebox;
-
- public int getBoxHeight()
+ /**
+ * 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 > 0)
{
- return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
+ Vector services = new Vector();
+ services.addElement(args[p++]);
+ Jws2Discoverer.setServiceUrls(services);
}
-
- public void updateControls(Parameter parm)
+ try
{
- 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)
+ disc.run();
+ } catch (Exception e)
+ {
+ System.err.println("Aborting. Problem discovering services.");
+ e.printStackTrace();
+ return;
+ }
+ Jws2Instance lastserv = null;
+ for (Jws2Instance service : disc.getServices())
+ {
+ lastserv = service;
+ if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
{
- if (choice)
+ if (lastserv != null)
{
- if (init)
+ List prl = null;
+ Preset pr = null;
+ if (++p < args.length)
{
- List vals = parm.getPossibleValues();
- for (Object val : vals)
+ PresetManager prman = lastserv.getPresets();
+ if (prman != null)
{
- choicebox.addItem(val);
+ pr = prman.getPresetByName(args[p]);
+ if (pr == null)
+ {
+ // just grab the last preset.
+ prl = prman.getPresets();
+ }
}
}
-
- if (parm.getDefaultValue() != null)
+ else
{
- choicebox.setSelectedItem(parm.getDefaultValue());
+ PresetManager prman = lastserv.getPresets();
+ if (prman != null)
+ {
+ prl = prman.getPresets();
+ }
}
- }
- else
- {
- valueField.setText(parm.getDefaultValue());
- }
- }
- lastVal = updateSliderFromValueField();
- adjusting = false;
- }
-
- Object lastVal;
-
- public Parameter getParameter()
- {
- try
- {
- if (choice)
- {
- parameter.setDefaultValue((String) choicebox.getSelectedItem());
- }
- else
- {
- parameter.setDefaultValue(valueField.getText());
- }
- } catch (WrongParameterException e)
- {
- e.printStackTrace();
- return null;
- }
- return parameter;
- }
-
- 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)
+ Iterator en = (prl == null) ? null : prl.iterator();
+ while (en != null && en.hasNext())
{
- }
- ;
- 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() };
- }
- }
-
- }
+ if (en != null)
+ {
+ if (!en.hasNext())
+ {
+ en = prl.iterator();
+ }
+ pr = en.next();
+ }
+ {
+ System.out.println("Testing opts dupes for "
+ + lastserv.getUri() + " : "
+ + lastserv.getActionText() + ":" + pr.getName());
+ List