X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;ds=sidebyside;f=src%2Fjalview%2Fgui%2FWsJobParameters.java;h=42f2ddb5cf0440ab268522e94af8e55ae208e68d;hb=747167089ecf8d6afc70d417f5a20352e029bd95;hp=8abbcee1a6b95c40e10d9d97d5014a40cd18d5f3;hpb=59d682209891099d46b960509907c79e3fb276fe;p=jalview.git
diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java
index 8abbcee..42f2ddb 100644
--- a/src/jalview/gui/WsJobParameters.java
+++ b/src/jalview/gui/WsJobParameters.java
@@ -1,34 +1,35 @@
/*
- * 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
+ * Jalview - A Sequence Alignment Editor and Viewer ($$Version-Rel$$)
+ * Copyright (C) $$Year-Rel$$ The Jalview Authors
*
* 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.
+ * 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 .
+ * You should have received a copy of the GNU General Public License
+ * along with Jalview. If not, see .
+ * The Jalview Authors are detailed in the 'AUTHORS' file.
*/
package jalview.gui;
+import jalview.bin.Console;
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.util.MessageManager;
+import jalview.ws.api.UIinfo;
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.Component;
import java.awt.Dimension;
@@ -44,37 +45,27 @@ import java.awt.event.HierarchyBoundsListener;
import java.awt.event.HierarchyEvent;
import java.awt.event.ItemEvent;
import java.awt.event.ItemListener;
-import java.awt.event.WindowEvent;
-import java.awt.event.WindowListener;
-import java.net.URL;
import java.util.Hashtable;
-import java.util.Iterator;
import java.util.List;
import java.util.Vector;
+import java.util.concurrent.CompletableFuture;
+import java.util.concurrent.CompletionStage;
import javax.swing.JButton;
import javax.swing.JComboBox;
import javax.swing.JDialog;
import javax.swing.JFrame;
import javax.swing.JLabel;
-import javax.swing.JOptionPane;
import javax.swing.JPanel;
import javax.swing.JScrollPane;
-import javax.swing.JSplitPane;
import javax.swing.JTextArea;
+import javax.swing.WindowConstants;
import javax.swing.border.TitledBorder;
import javax.swing.event.DocumentEvent;
import javax.swing.event.DocumentListener;
import net.miginfocom.swing.MigLayout;
-import compbio.metadata.Argument;
-import compbio.metadata.Option;
-import compbio.metadata.Parameter;
-import compbio.metadata.Preset;
-import compbio.metadata.PresetManager;
-import compbio.metadata.RunnerConfig;
-
/**
* job parameter editing/browsing dialog box. User can browse existing settings
* (user + presets + Defaults), and any changes to parameters creates a modified
@@ -93,36 +84,38 @@ import compbio.metadata.RunnerConfig;
public class WsJobParameters extends JPanel implements ItemListener,
ActionListener, DocumentListener, OptsParametersContainerI
{
- URL linkImageURL = getClass().getResource("/images/link.gif");
+ private static final int PREFERRED_WIDTH = 540;
+
+ private static final int DEFAULT_HEIGHT = 640;
+
+ // the default parameter set shown to the user
+ private static final String SVC_DEF = "Defaults";
+
+ private int maxOptWidth = 200;
+
+ // URL linkImageURL = getClass().getResource("/images/link.gif");
- private static final String SVC_DEF = "Defaults"; // this is the null
- // parameter set as shown to
- // user
+ // TODO ABSRACT FROM JABAWS CLASSES
+ // completion stage representing whether start was clicked
+ private final CompletableFuture completionStage = new CompletableFuture<>();
+
/**
* manager for options and parameters.
*/
- OptsAndParamsPage opanp = new OptsAndParamsPage(this);
+ OptsAndParamsPage opanp;
- /**
+ /*
* panel containing job options
*/
- JPanel jobOptions = new JPanel();
+ JPanel optionsPanel = new JPanel();
- /**
+ /*
* panel containing job parameters
*/
- JPanel paramList = new JPanel();
-
- JPanel SetNamePanel = new JPanel();
+ JPanel paramsPanel = new JPanel();
- JPanel setDetails = new JPanel();
-
- JSplitPane settingsPanel = new JSplitPane();
-
- JPanel jobPanel = new JPanel();
-
- JScrollPane jobOptionsPane = new JScrollPane();
+ JPanel setNamePanel = new JPanel();
JButton createpref = new JButton();
@@ -132,95 +125,108 @@ public class WsJobParameters extends JPanel implements ItemListener,
JButton updatepref = new JButton();
- JButton startjob = new JButton();
-
- JButton canceljob = new JButton();
-
- JComboBox setName = new JComboBox();
+ JComboBox setName = new JComboBox<>();
JTextArea setDescr = new JTextArea();
JScrollPane paramPane = new JScrollPane();
-
- // ScrollablePanel optsAndparams = new ScrollablePanel();
- JPanel optsAndparams = new JPanel();
-
- RunnerConfig serviceOptions;
+
+ JButton startjob = JvSwingUtils.makeButton(
+ MessageManager.getString("action.start_job"),
+ MessageManager.getString("label.start_job_current_settings"),
+ this::startjob_actionPerformed);
+ JButton canceljob = JvSwingUtils.makeButton(
+ MessageManager.getString("action.cancel_job"),
+ MessageManager.getString("label.cancel_job_close_dialog"),
+ this::canceljob_actionPerformed);
ParamDatastoreI paramStore;
- private int MAX_OPTWIDTH = 200;
+ // set true when 'Start Job' is clicked
+ boolean startJob = false;
- WsJobParameters(Jws2Instance service)
- {
- this(service, null);
- }
+ JFrame frame = null;
- public WsJobParameters(Jws2Instance service, WsParamSetI preset)
- {
- this(null, service, preset, null);
- }
+ UIinfo service;
- /**
- *
- * @param desktop
- * - if null, create new JFrame outside of desktop
- * @param service
- * @param preset
+ /*
+ * list of service presets in the gui
*/
- public WsJobParameters(JFrame parent, Jws2Instance service,
- WsParamSetI preset, List jobArgset)
+ Hashtable servicePresets = null;
+
+ /*
+ * set if dialog is being set - so handlers will avoid spurious events
+ */
+ boolean settingDialog = false;
+
+ private Hashtable modifiedElements = new Hashtable<>();
+
+ String lastParmSet = null;
+
+ public WsJobParameters(ParamDatastoreI store, WsParamSetI preset,
+ List args)
{
- this(parent, null, service, preset, jobArgset);
+ super();
+
+ // parameters dialog in 'compact' format (help as tooltips)
+ opanp = new OptsAndParamsPage(this, true);
+ jbInit();
+ this.paramStore = store;
+ this.service = null;
+ initForService(preset, args);
+ validate();
}
/**
+ * Constructor given a set of parameters and presets, a service to be invoked,
+ * and a list of (Jabaws client) arguments
*
- * @param parent
* @param paramStorei
* @param service
* @param preset
* @param jobArgset
*/
- public WsJobParameters(JFrame parent, ParamDatastoreI paramStorei,
- Jws2Instance service, WsParamSetI preset, List jobArgset)
+ public WsJobParameters(ParamDatastoreI paramStorei, UIinfo service,
+ WsParamSetI preset, List jobArgset)
{
super();
+ // parameters dialog in 'expanded' format (help text boxes)
+ opanp = new OptsAndParamsPage(this, false);
jbInit();
this.paramStore = paramStorei;
- if (paramStore == null)
+ if (paramStore == null && service != null)
{
paramStore = service.getParamStore();
}
this.service = service;
- // argSetModified(false);
- // populate parameter table
- initForService(service, preset, jobArgset);
- // display in new JFrame attached to parent.
+ initForService(preset, jobArgset);
validate();
}
- int response = -1;
-
- JDialog frame = null;
/**
- * shows a modal dialog containing the parameters.
+ * Shows a modal dialog containing the parameters and Start or Cancel options.
+ * Answers true if the job is started, false if cancelled.
*
* @return
*/
- public boolean showRunDialog()
+ public CompletionStage showRunDialog()
{
- frame = new JDialog(Desktop.instance, true);
-
- frame.setTitle("Edit parameters for " + service.getActionText());
- Rectangle deskr = Desktop.instance.getBounds();
+ // Should JFrame hahve a parent of getDesktop ?
+ frame = new JFrame();
+ frame.setDefaultCloseOperation(WindowConstants.DO_NOTHING_ON_CLOSE);
+ if (service != null)
+ {
+ frame.setTitle(MessageManager.formatMessage("label.edit_params_for",
+ new String[] { service.getActionText() }));
+ }
+ Rectangle deskr = Desktop.getInstance().getBounds();
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.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.
@@ -228,19 +234,17 @@ public class WsJobParameters extends JPanel implements ItemListener,
frame.validate();
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
+ @Override
public void run()
{
// jobPanel.setDividerLocation(0.25);
}
});
+
frame.setVisible(true);
- if (response > 0)
- {
- return true;
- }
- return false;
+ return completionStage;
}
private void jbInit()
@@ -261,64 +265,28 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
});
- updatepref = JvSwingUtils.makeButton("Update",
- "Update this existing user parameter set.",
- new ActionListener()
- {
-
- public void actionPerformed(ActionEvent e)
- {
- update_actionPerformed(e);
- }
- });
- deletepref = JvSwingUtils.makeButton("Delete",
- "Delete the currently selected user parameter set.",
- new ActionListener()
- {
-
- public void actionPerformed(ActionEvent e)
- {
- delete_actionPerformed(e);
- }
- });
- createpref = JvSwingUtils.makeButton("Create",
- "Create a new parameter set with the current settings.",
- new ActionListener()
- {
-
- public void actionPerformed(ActionEvent e)
- {
- create_actionPerformed(e);
- }
- });
- revertpref = JvSwingUtils.makeButton("Revert",
- "Undo all changes to the current parameter set",
- new ActionListener()
- {
-
- public void actionPerformed(ActionEvent 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);
- }
- });
-
- setDetails.setBorder(new TitledBorder("Details"));
+ updatepref = JvSwingUtils.makeButton(
+ MessageManager.getString("action.update"),
+ MessageManager.getString("label.update_user_parameter_set"),
+ this::update_actionPerformed);
+ deletepref = JvSwingUtils.makeButton(
+ MessageManager.getString("action.delete"),
+ MessageManager.getString("label.delete_user_parameter_set"),
+ this::delete_actionPerformed);
+ createpref = JvSwingUtils.makeButton(
+ MessageManager.getString("action.create"),
+ MessageManager.getString("label.create_user_parameter_set"),
+ this::create_actionPerformed);
+ revertpref = JvSwingUtils.makeButton(
+ MessageManager.getString("action.revert"),
+ MessageManager
+ .getString("label.revert_changes_user_parameter_set"),
+ this::revert_actionPerformed);
+
+
+ JPanel setDetails = new JPanel();
+ setDetails.setBorder(
+ new TitledBorder(MessageManager.getString("label.details")));
setDetails.setLayout(new BorderLayout());
setDescr.setColumns(40);
setDescr.setWrapStyleWord(true);
@@ -326,18 +294,19 @@ 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.");
+ setDescr.setToolTipText(
+ MessageManager.getString("label.edit_notes_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);
JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT));
GridBagLayout gbl = new GridBagLayout();
- SetNamePanel.setLayout(gbl);
+ setNamePanel.setLayout(gbl);
- JLabel setNameLabel = new JLabel("Current parameter set name :");
+ JLabel setNameLabel = new JLabel(
+ MessageManager.getString("label.current_parameter_set_name"));
setNameLabel.setFont(new java.awt.Font("Verdana", Font.PLAIN, 10));
setNameInfo.add(setNameLabel);
@@ -349,9 +318,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
revertpref.setVisible(false);
createpref.setVisible(false);
JPanel setsavebuts = new JPanel();
- setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT)); // GridLayout(1,2));
- ((FlowLayout) setsavebuts.getLayout()).setHgap(10);
- ((FlowLayout) setsavebuts.getLayout()).setVgap(0);
+ setsavebuts.setLayout(new FlowLayout(FlowLayout.LEFT, 10, 0)); // GridLayout(1,2));
JPanel spacer = new JPanel();
spacer.setPreferredSize(new Dimension(2, 30));
setsavebuts.add(spacer);
@@ -362,11 +329,11 @@ public class WsJobParameters extends JPanel implements ItemListener,
// setsavebuts.setSize(new Dimension(150, 30));
JPanel buttonArea = new JPanel(new GridLayout(1, 1));
buttonArea.add(setsavebuts);
- SetNamePanel.add(setNameInfo);
+ setNamePanel.add(setNameInfo);
GridBagConstraints gbc = new GridBagConstraints();
gbc.gridheight = 2;
gbl.setConstraints(setNameInfo, gbc);
- SetNamePanel.add(buttonArea);
+ setNamePanel.add(buttonArea);
gbc = new GridBagConstraints();
gbc.gridx = 0;
gbc.gridy = 2;
@@ -376,39 +343,42 @@ public class WsJobParameters extends JPanel implements ItemListener,
// 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);
+ optionsPanel.setBorder(
+ new TitledBorder(MessageManager.getString("label.options")));
+ optionsPanel.setOpaque(true);
+ paramsPanel.setBorder(
+ new TitledBorder(MessageManager.getString("label.parameters")));
+ paramsPanel.setOpaque(true);
// optsAndparams.setScrollableWidth(ScrollableSizeHint.FIT);
// optsAndparams.setScrollableHeight(ScrollableSizeHint.NONE);
// optsAndparams.setLayout(new BorderLayout());
+ JPanel optsAndparams = new JPanel();
optsAndparams.setLayout(new BorderLayout());
- optsAndparams.add(jobOptions, BorderLayout.NORTH);
- optsAndparams.add(paramList, BorderLayout.CENTER);
+ optsAndparams.add(optionsPanel, BorderLayout.NORTH);
+ optsAndparams.add(paramsPanel, BorderLayout.CENTER);
JPanel jp = new JPanel(new BorderLayout());
jp.add(optsAndparams, BorderLayout.CENTER);
paramPane.getViewport().setView(jp);
paramPane.setBorder(null);
setLayout(new BorderLayout());
+ JPanel jobPanel = new JPanel();
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(setNamePanel, BorderLayout.NORTH);
add(jobPanel, BorderLayout.CENTER);
JPanel dialogpanel = new JPanel();
dialogpanel.add(startjob);
dialogpanel.add(canceljob);
+ // JAL-1580: setMaximumSize() doesn't work, so just size for the worst case:
+ // check for null is for JUnit usage
+ final int windowHeight = Desktop.getInstance() == null ? DEFAULT_HEIGHT
+ : Desktop.getInstance().getHeight();
+ setPreferredSize(new Dimension(540, windowHeight));
add(dialogpanel, BorderLayout.SOUTH);
validate();
}
@@ -416,7 +386,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
protected void revert_actionPerformed(ActionEvent e)
{
reInitDialog(lastParmSet);
-
+ updateWebServiceMenus();
}
protected void update_actionPerformed(ActionEvent e)
@@ -445,6 +415,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
_deleteUserPreset(lastParmSet);
}
reInitDialog(null); // service default
+ updateWebServiceMenus();
}
protected void create_actionPerformed(ActionEvent e)
@@ -455,7 +426,9 @@ public class WsJobParameters extends JPanel implements ItemListener,
_storeCurrentPreset(curname);
lastParmSet = curname;
isUserPreset = true;
+ reInitDialog(curname);
initArgSetModified();
+ updateWebServiceMenus();
}
else
{
@@ -466,53 +439,40 @@ public class WsJobParameters extends JPanel implements ItemListener,
protected void canceljob_actionPerformed(ActionEvent e)
{
- response = 0;
+ startJob = false;
if (frame != null)
{
frame.setVisible(false);
}
+ completionStage.complete(false);
}
protected void startjob_actionPerformed(ActionEvent e)
{
- response = 1;
+ startJob = true;
if (frame != null)
{
frame.setVisible(false);
}
+ completionStage.complete(true);
}
- Jws2Instance service;
+ void initForService(WsParamSetI paramSet, List jobArgset)
+ {
+ settingDialog = true;
- /**
- * list of service presets in the gui
- */
- Hashtable servicePresets = null;
+ init(paramSet, jobArgset);
- /**
- * set if dialog is being set - so handlers will avoid spurious events
- */
- boolean settingDialog = false;
+ }
- void initForService(Jws2Instance service, WsParamSetI jabap,
- List jabajobArgset)
+ void init(WsParamSetI p, List jobArgset)
{
- WsParamSetI p = null;
- List jobArgset = null;
- settingDialog = true;
- { // 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();
+ Hashtable exnames = new Hashtable<>();
for (int i = 0, iSize = setName.getItemCount(); i < iSize; i++)
{
- exnames.put((String) setName.getItemAt(i), setName.getItemAt(i));
+ exnames.put(setName.getItemAt(i), setName.getItemAt(i));
}
- servicePresets = new Hashtable();
+ servicePresets = new Hashtable<>();
// Add the default entry - if not present already.
if (!exnames.contains(SVC_DEF))
{
@@ -520,7 +480,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
exnames.put(SVC_DEF, SVC_DEF);
servicePresets.put(SVC_DEF, SVC_DEF);
}
- String curname = (p == null ? "" : p.getName());
+ // String curname = (p == null ? "" : p.getName());
for (WsParamSetI pr : paramStore.getPresets())
{
if (!pr.isModifiable())
@@ -563,15 +523,27 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
- @SuppressWarnings("unchecked")
private void updateTable(WsParamSetI p, List jobArgset)
{
+ boolean setDefaultParams = false;
+ if (lastParmSet == null)
+ {
+ isUserPreset = false;
+ // First call - so provide Service default settings
+ setName.setSelectedItem(lastSetName = SVC_DEF);
+ }
+ if (p == null && SVC_DEF.equals("" + setName.getSelectedItem()))
+ {
+ // indicate that service defaults should be set if available
+ setDefaultParams = true;
+ }
// populate table from default parameter set.
List args = paramStore.getServiceParameters();
// split to params and required arguments
{
int cw = 0;
+ boolean optset = false;
for (ArgumentI myarg : args)
{
// Ideally, Argument would implement isRequired !
@@ -586,10 +558,10 @@ public class WsJobParameters extends JPanel implements ItemListener,
{
OptionI opt = (OptionI) myarg;
OptionBox ob = opanp.addOption(opt);
- ob.resetToDefault();
- if (MAX_OPTWIDTH < ob.getPreferredSize().width)
+ ob.resetToDefault(setDefaultParams);
+ if (maxOptWidth < ob.getPreferredSize().width)
{
- MAX_OPTWIDTH = ob.getPreferredSize().width;
+ maxOptWidth = ob.getPreferredSize().width;
}
ob.validate();
cw += ob.getPreferredSize().width + 5;
@@ -620,16 +592,6 @@ public class WsJobParameters extends JPanel implements ItemListener,
// TODO: check if args should be unselected prior to resetting using the
// preset
}
- else
- {
- if (lastParmSet == null)
- {
- isUserPreset = false;
- // first call - so create a dummy name
-
- setName.setSelectedItem(lastSetName = SVC_DEF);
- }
- }
if (jobArgset != null)
{
@@ -668,7 +630,6 @@ public class WsJobParameters extends JPanel implements ItemListener,
return modifiedElements.size() > 0;
}
- private Hashtable modifiedElements = new Hashtable();
/**
* reset gui and modification state settings
@@ -682,7 +643,8 @@ public class WsJobParameters extends JPanel implements ItemListener,
private void updateButtonDisplay()
{
- boolean _update = false, _create = false, _delete = false, _revert = false;
+ boolean _update = false, _create = false, _delete = false,
+ _revert = false;
if (modifiedElements.size() > 0)
{
// set modified
@@ -708,6 +670,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
validate();
}
+ @Override
public void argSetModified(Object modifiedElement, boolean b)
{
if (settingDialog)
@@ -732,7 +695,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
if (b && modifiedElements.size() > 0)
{
makeSetNameValid(!isUserPreset);
- SetNamePanel.revalidate();
+ setNamePanel.revalidate();
}
updateButtonDisplay();
}
@@ -752,8 +715,8 @@ public class WsJobParameters extends JPanel implements ItemListener,
boolean stn = settingDialog;
boolean renamed = false;
settingDialog = true;
- String nm = (curSetName != null ? curSetName : (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))
{
@@ -779,7 +742,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
// sync the gui with the preset database
for (int i = 0, iS = setName.getItemCount(); i < iS; i++)
{
- String snm = (String) setName.getItemAt(i);
+ String snm = setName.getItemAt(i);
if (snm.equals(nm))
{
makeupdate = true;
@@ -799,96 +762,88 @@ public class WsJobParameters extends JPanel implements ItemListener,
settingDialog = stn;
}
+ /**
+ * Rebuilds the Options and Parameters panels
+ */
+ @Override
public void refreshParamLayout()
{
- // 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;
+ final int rightMargin = 40;
+ final int availableWidth = paramPane.getViewport().getSize().width
+ - rightMargin
+ - optionsPanel.getBorder().getBorderInsets(optionsPanel).left
+ + optionsPanel.getBorder().getBorderInsets(optionsPanel).right;
if (opanp.getOptSet().size() > 0)
{
+ int hgap = 5;
+ int currentWidth = hgap;
- jobOptions.setLayout(new MigLayout("", "", ""));
- jobOptions.removeAll();
+ /*
+ * layout constraint 'nogrid' prevents vertical column alignment,
+ * allowing controls to flow without extra space inserted to align
+ */
+ optionsPanel.setLayout(new MigLayout("nogrid", "", ""));
+ optionsPanel.removeAll();
+ JPanel lastAdded = null;
+ /*
+ * add each control in turn; if adding would overflow the right margin,
+ * remove and re-add the previous parameter with "wrap" (after)
+ * in order to start a new row
+ */
for (OptionBox pbox : opanp.getOptSet().values())
{
pbox.validate();
- cw += pbox.getSize().width + hgap;
- if (cw + 120 > panewidth)
+ int boxWidth = pbox.getSize().width;
+ currentWidth += boxWidth + hgap;
+ boolean wrapAfterLast = currentWidth > availableWidth
+ && lastAdded != null;
+ // System.out.println(String.format(
+ // "%s width=%d, paneWidth=%d, currentWidth=%d, wrapAfterLast=%s",
+ // pbox.toString(), boxWidth, panewidth, currentWidth,
+ // wrapAfterLast));
+ if (wrapAfterLast)
{
- 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;
+ optionsPanel.remove(lastAdded);
+ optionsPanel.add(lastAdded, "wrap");
+ currentWidth = hgap + boxWidth;
}
+ optionsPanel.add(pbox);
+ lastAdded = pbox;
}
- jobOptions.revalidate();
+ optionsPanel.revalidate();
}
else
{
- jobOptions.setVisible(false);
+ optionsPanel.setVisible(false);
}
- // 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)
{
- paramList.removeAll();
- paramList.setLayout(new MigLayout("", "", ""));
- fh = true;
+ paramsPanel.removeAll();
+ paramsPanel.setLayout(new MigLayout("", "", ""));
+ int hgap = 5;
+ int currentWidth = hgap;
+
+ JPanel lastAdded = null;
for (ParamBox pbox : opanp.getParamSet().values())
{
pbox.validate();
- cw += pbox.getSize().width + hgap;
- if (cw + 160 > panewidth)
+ int boxWidth = pbox.getSize().width;
+ currentWidth += boxWidth + hgap;
+ boolean wrapAfterLast = currentWidth > availableWidth
+ && lastAdded != null;
+ if (wrapAfterLast)
{
- paramList.add(pbox, "wrap");
- cw = pbox.getSize().width + hgap;
- fh = true;
+ paramsPanel.remove(lastAdded);
+ paramsPanel.add(lastAdded, "wrap");
+ currentWidth = pbox.getSize().width + hgap;
}
- else
- {
- paramList.add(pbox);
- }
- if (fh)
- {
- finalh += pbox.getSize().height + fl.getVgap();
- fh = false;
- }
-
+ paramsPanel.add(pbox);
+ lastAdded = pbox;
}
+
/*
* s = 2 * sep; for (ParamBox pbox : opanp.getParamSet().values()) {
* pbox.validate(); s += sep +
@@ -900,11 +855,11 @@ public class WsJobParameters extends JPanel implements ItemListener,
* .getBorder().getBorderInsets(paramList).bottom+paramList
* .getBorder().getBorderInsets(paramList).top;
*/
- paramList.revalidate();
+ paramsPanel.revalidate();
}
else
{
- paramList.setVisible(false);
+ paramsPanel.setVisible(false);
}
// TODO: waste some time trying to eliminate any unnecessary .validate calls
// here
@@ -916,239 +871,11 @@ public class WsJobParameters extends JPanel implements ItemListener,
revalidate();
}
- /**
- * 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)
- {
- 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;
- }
- Jws2Instance lastserv = null;
- for (Jws2Instance service : disc.getServices())
- {
- lastserv = service;
- if (p >= args.length || service.serviceType.equalsIgnoreCase(args[p]))
- {
- 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.getUri() + " : "
- + lastserv.getActionText() + ":" + pr.getName());
- List rg = lastserv.getRunnerConfig().getOptions();
- for (Option o : rg)
- {
- try
- {
- Option cpy = jalview.ws.jws2.ParameterUtils.copyOption(o);
- } catch (Exception e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- } catch (Error e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- }
- }
- }
- {
- System.out.println("Testing param dupes:");
- List rg = lastserv.getRunnerConfig()
- .getParameters();
- for (Parameter o : rg)
- {
- try
- {
- Parameter cpy = jalview.ws.jws2.ParameterUtils
- .copyParameter(o);
- } catch (Exception e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- } catch (Error e)
- {
- System.err.println("Failed to copy " + o.getName());
- e.printStackTrace();
- }
- }
- }
- {
- System.out.println("Testing param write:");
- List writeparam = null, readparam = null;
- try
- {
- writeparam = jalview.ws.jws2.ParameterUtils
- .writeParameterSet(
- pr.getArguments(lastserv.getRunnerConfig()),
- " ");
- System.out.println("Testing param read :");
- List pset = jalview.ws.jws2.ParameterUtils
- .processParameters(writeparam,
- lastserv.getRunnerConfig(), " ");
- readparam = jalview.ws.jws2.ParameterUtils
- .writeParameterSet(pset, " ");
- Iterator o = pr.getOptions().iterator(), s = writeparam
- .iterator(), t = readparam.iterator();
- boolean failed = false;
- while (s.hasNext() && t.hasNext())
- {
- String on = o.next(), sn = s.next(), st = t.next();
- if (!sn.equals(st))
- {
- System.out.println("Original was " + on
- + " Phase 1 wrote " + sn + "\tPhase 2 wrote "
- + st);
- failed = true;
- }
- }
- if (failed)
- {
- System.out.println("Original parameters:\n"
- + pr.getOptions());
- System.out.println("Wrote parameters in first set:\n"
- + writeparam);
- System.out.println("Wrote parameters in second set:\n"
- + readparam);
-
- }
- } catch (Exception e)
- {
- e.printStackTrace();
- }
- }
- WsJobParameters pgui = new WsJobParameters(lastserv,
- new JabaPreset(lastserv, pr));
- JFrame jf = new JFrame("Parameters for "
- + lastserv.getActionText());
- JPanel cont = new JPanel(new BorderLayout());
- pgui.validate();
- cont.setPreferredSize(pgui.getPreferredSize());
- cont.add(pgui, BorderLayout.CENTER);
- jf.setLayout(new BorderLayout());
- jf.add(cont, BorderLayout.CENTER);
- jf.validate();
- final Thread thr = Thread.currentThread();
- jf.addWindowListener(new WindowListener()
- {
-
- public void windowActivated(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowClosed(WindowEvent e)
- {
- }
-
- public void windowClosing(WindowEvent e)
- {
- thr.interrupt();
-
- }
-
- public void windowDeactivated(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowDeiconified(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowIconified(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void windowOpened(WindowEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- });
- jf.setVisible(true);
- boolean inter = false;
- while (!inter)
- {
- try
- {
- Thread.sleep(10000);
- } catch (Exception e)
- {
- inter = true;
- }
- ;
- }
- jf.dispose();
- }
- }
- }
- }
- }
public boolean isServiceDefaults()
{
- return (!isModified() && (lastParmSet != null && lastParmSet
- .equals(SVC_DEF)));
+ return (!isModified()
+ && (lastParmSet != null && lastParmSet.equals(SVC_DEF)));
}
public List getJobParams()
@@ -1156,7 +883,6 @@ public class WsJobParameters extends JPanel implements ItemListener,
return opanp.getCurrentSettings();
}
- String lastParmSet = null;
/*
* Hashtable editedParams = new Hashtable items = new Vector<>();
while (n < setName.getItemCount())
{
- String item = (String) setName.getItemAt(n);
+ String item = setName.getItemAt(n);
if (!item.equals(SVC_DEF) && !paramStore.presetExists(item))
{
setName.removeItemAt(n);
@@ -1268,21 +994,41 @@ public class WsJobParameters extends JPanel implements ItemListener,
initArgSetModified();
syncSetNamesWithStore();
setName.setSelectedItem(lastParmSet);
- SetNamePanel.validate();
+ setNamePanel.validate();
validate();
settingDialog = false;
+ }
+ /**
+ * Rebuild the AlignFrame web service menus (after add/delete of a preset
+ * option).
+ */
+ protected void updateWebServiceMenus()
+ {
+ if (Desktop.getInstance() == null)
+ {
+ return;
+ }
+ for (AlignFrame alignFrame : Desktop.getAlignFrames())
+ {
+ alignFrame.buildWebServicesMenu();
+ }
}
String curSetName = null;
+ @Override
public void itemStateChanged(ItemEvent e)
{
- if (e.getSource() == setName && e.getStateChange() == e.SELECTED)
+ if (e.getSource() == setName
+ && e.getStateChange() == ItemEvent.SELECTED)
{
final String setname = (String) setName.getSelectedItem();
- System.out.println("Item state changed for " + setname
- + " (handling ? " + !settingDialog + ")");
+ if (Console.isDebugEnabled())
+ {
+ Console.debug("Item state changed for " + setname + " (handling ? "
+ + !settingDialog + ")");
+ }
if (settingDialog)
{
// ignore event
@@ -1294,6 +1040,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
+ @Override
public void run()
{
doPreferenceComboStateChange(setname);
@@ -1315,14 +1062,10 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
settingDialog = true;
System.out.println("Prompting to save " + lsetname);
- if (javax.swing.JOptionPane
- .showConfirmDialog(
- this,
- "Parameter set '"
- + lsetname
- + "' is modifed, and your changes will be lost.\nReally change preset ?",
- "Warning: Unsaved Changes",
- javax.swing.JOptionPane.OK_CANCEL_OPTION) != JOptionPane.OK_OPTION)
+ 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)
{
// revert the combobox to the current item
settingDialog = true;
@@ -1341,12 +1084,6 @@ public class WsJobParameters extends JPanel implements ItemListener,
}
- private void _renameExistingPreset(String oldName, String curSetName2)
- {
- paramStore.updatePreset(oldName, curSetName2, setDescr.getText(),
- getJobParams());
- }
-
/**
* store current settings as given name. You should then reset gui.
*
@@ -1374,6 +1111,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
*/
String lastDescrText = null;
+ @Override
public void actionPerformed(ActionEvent e)
{
if (e.getSource() instanceof Component)
@@ -1382,7 +1120,7 @@ public class WsJobParameters extends JPanel implements ItemListener,
if (src.getParent() == setName)
{
// rename any existing records we know about for this set.
- String newname = (String) e.getActionCommand().trim();
+ String newname = e.getActionCommand().trim();
String msg = null;
if (isServicePreset(newname))
{
@@ -1394,11 +1132,14 @@ public class WsJobParameters extends JPanel implements ItemListener,
settingDialog = false;
javax.swing.SwingUtilities.invokeLater(new Runnable()
{
+ @Override
public void run()
{
- JOptionPane.showMessageDialog(ourframe,
- "Invalid name - preset already exists.",
- "Invalid name", JOptionPane.WARNING_MESSAGE);
+ JvOptionPane.showMessageDialog(ourframe,
+ MessageManager.getString(
+ "label.invalid_name_preset_exists"),
+ MessageManager.getString("label.invalid_name"),
+ JvOptionPane.WARNING_MESSAGE);
}
});
@@ -1426,24 +1167,27 @@ public class WsJobParameters extends JPanel implements ItemListener,
if (!settingDialog)
{
- argSetModified(
- setDescr,
- (lastDescrText == null ? setDescr.getText().trim().length() > 0
+ argSetModified(setDescr,
+ (lastDescrText == null
+ ? setDescr.getText().trim().length() > 0
: !setDescr.getText().equals(lastDescrText)));
}
}
+ @Override
public void insertUpdate(DocumentEvent e)
{
checkDescrModified();
}
+ @Override
public void removeUpdate(DocumentEvent e)
{
checkDescrModified();
}
+ @Override
public void changedUpdate(DocumentEvent e)
{
checkDescrModified();