X-Git-Url: http://source.jalview.org/gitweb/?a=blobdiff_plain;f=src%2Fjalview%2Fgui%2FWsJobParameters.java;h=b19948999b9f6004f156629c357618938d17acd3;hb=a45774ee31d9f35d4eff46d54d7deab719afb092;hp=3facfa106e9a08393072ae1bdb1e4ce042abf929;hpb=6fbc6ebb2f261d9071e40fcf51b02584a2119aa2;p=jalview.git diff --git a/src/jalview/gui/WsJobParameters.java b/src/jalview/gui/WsJobParameters.java index 3facfa1..b199489 100644 --- a/src/jalview/gui/WsJobParameters.java +++ b/src/jalview/gui/WsJobParameters.java @@ -1,32 +1,55 @@ +/* + * Jalview - A Sequence Alignment Editor and Viewer (Version 2.7) + * Copyright (C) 2011 J Procter, AM Waterhouse, 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.Jws2Discoverer.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.ValueConstrainI; +import jalview.ws.params.WsParamSetI; + import java.awt.BorderLayout; -import java.awt.Color; import java.awt.Component; +import java.awt.Container; 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.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.net.URL; import java.util.ArrayList; -import java.util.EventObject; -import java.util.HashSet; import java.util.Hashtable; import java.util.Iterator; import java.util.List; @@ -40,7 +63,6 @@ import javax.swing.JComponent; import javax.swing.JDialog; import javax.swing.JFrame; import javax.swing.JLabel; -import javax.swing.JList; import javax.swing.JMenuItem; import javax.swing.JOptionPane; import javax.swing.JPanel; @@ -48,19 +70,14 @@ import javax.swing.JPopupMenu; import javax.swing.JScrollPane; import javax.swing.JSlider; import javax.swing.JSplitPane; -import javax.swing.JTable; +import javax.swing.JTabbedPane; 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 compbio.metadata.Argument; import compbio.metadata.Option; @@ -68,15 +85,8 @@ 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.util.jarInputStreamProvider; -import jalview.ws.jws2.Jws2Discoverer; -import jalview.ws.jws2.ParameterUtils; -import jalview.ws.jws2.Jws2Discoverer.Jws2Instance; - /** * job parameter editing/browsing dialog box. User can browse existing settings * (user + presets + Defaults), and any changes to parameters creates a modified @@ -93,17 +103,31 @@ 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(); JPanel setDetails = new JPanel(); @@ -112,7 +136,6 @@ public class WsJobParameters extends JPanel implements ItemListener, JSplitPane jobPanel = new JSplitPane(); - JPanel jobOptions = new JPanel(); JScrollPane jobOptionsPane = new JScrollPane(); @@ -136,21 +159,23 @@ public class WsJobParameters extends JPanel implements ItemListener, JScrollPane paramPane = new JScrollPane(); - // JList paramList = new JList(); - JPanel paramList = new JPanel(); + + 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); } /** @@ -158,16 +183,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, + WsParamSetI preset, List jobArgset) + { + this(parent, null, service, preset, jobArgset); + } + + /** + * + * @param parent + * @param paramStorei + * @param service + * @param preset + * @param jobArgset */ - public WsJobParameters(JFrame parent, Jws2Instance service, Preset p, - List 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(); } @@ -188,14 +233,23 @@ 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() - 250), 480, 500)); + 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 recover defaults from user prefs. + + // should perhaps recover defaults from user prefs. + frame.validate(); - settingsPanel.setDividerLocation(0.4); - jobPanel.setDividerLocation(0.3); - frame.setVisible(true); + javax.swing.SwingUtilities.invokeLater(new Runnable() + { + public void run() + { + jobPanel.setDividerLocation(0.25); + + } + }); + frame.setVisible(true); if (response > 0) { @@ -204,22 +258,10 @@ 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() { - updatepref = makeButton("Update", "Update the stored user preference", + updatepref = JvSwingUtils.makeButton("Update", + "Update this existing user parameter set.", new ActionListener() { @@ -228,7 +270,8 @@ public class WsJobParameters extends JPanel implements ItemListener, update_actionPerformed(e); } }); - deletepref = makeButton("Delete", "Delete the user preference", + deletepref = JvSwingUtils.makeButton("Delete", + "Delete the currently selected user parameter set.", new ActionListener() { @@ -237,7 +280,8 @@ public class WsJobParameters extends JPanel implements ItemListener, delete_actionPerformed(e); } }); - createpref = makeButton("Create", "Create a new preference", + createpref = JvSwingUtils.makeButton("Create", + "Create a new parameter set with the current settings.", new ActionListener() { @@ -246,8 +290,9 @@ public class WsJobParameters extends JPanel implements ItemListener, create_actionPerformed(e); } }); - revertpref = makeButton("Revert", - "Undo all changes to the current set", new ActionListener() + revertpref = JvSwingUtils.makeButton("Revert", + "Undo all changes to the current parameter set", + new ActionListener() { public void actionPerformed(ActionEvent e) @@ -255,26 +300,22 @@ public class WsJobParameters extends JPanel implements ItemListener, revert_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); - } - }); + 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")); setDetails.setLayout(new BorderLayout()); @@ -284,6 +325,7 @@ 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); @@ -291,13 +333,15 @@ public class WsJobParameters extends JPanel implements ItemListener, setName.addItemListener(this); setName.getEditor().addActionListener(this); JPanel setNameInfo = new JPanel(new FlowLayout(FlowLayout.LEFT)); - SetNamePanel.setLayout(new GridLayout(2, 1)); - SetNamePanel.setMinimumSize(new Dimension(300, 40)); - JLabel setNameLabel = new JLabel("Parameter set: "); + 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)); - // setNameLabel.setHorizontalAlignment(FlowLayout.LEFT); + setNameInfo.add(setNameLabel); setNameInfo.add(setName); + // initial button visibility updatepref.setVisible(false); deletepref.setVisible(false); @@ -307,42 +351,51 @@ public class WsJobParameters extends JPanel implements ItemListener, 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, 20)); +// 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); + jobParameters.setBorder(new TitledBorder("Parameters")); + paramPane.setPreferredSize(new Dimension(360, 400)); + jobOptions.setBorder(new TitledBorder("Options")); + + paramList.setBorder(new TitledBorder("Parameters")); + + JPanel bjo=new JPanel(new BorderLayout()),bjp=new JPanel(new BorderLayout()); + bjo.add(jobOptions, BorderLayout.CENTER); + bjp.add(paramList, BorderLayout.CENTER); + optsAndparams.setLayout(new BorderLayout()); + + optsAndparams.add(bjo, BorderLayout.CENTER); + optsAndparams.add(bjp, BorderLayout.SOUTH); + paramPane.setViewportView(optsAndparams); + setLayout(new BorderLayout()); - // setPreferredSize(new Dimension(400, 600)); - // setSize(new Dimension(400, 600)); jobPanel.setLeftComponent(setDetails); - jobPanel.setRightComponent(settingsPanel); + jobPanel.setRightComponent(paramPane); jobPanel.setOrientation(JSplitPane.VERTICAL_SPLIT); + add(SetNamePanel, BorderLayout.NORTH); add(jobPanel, BorderLayout.CENTER); + JPanel dialogpanel = new JPanel(); dialogpanel.add(startjob); dialogpanel.add(canceljob); @@ -360,11 +413,7 @@ public class WsJobParameters extends JPanel implements ItemListener, if (isUserPreset) { String curname = ((String) setName.getSelectedItem()).trim(); - if (curname.length() > 0 && !curname.equals(lastParmSet)) - { - _deleteUserPreset(lastParmSet); - } - _storeCurrentPreset(curname); + _updatePreset(lastParmSet, curname); lastParmSet = curname; isUserPreset = true; initArgSetModified(); @@ -372,6 +421,11 @@ public class WsJobParameters extends JPanel implements ItemListener, } } + private void _deleteUserPreset(String lastParmSet2) + { + paramStore.deletePreset(lastParmSet2); + } + protected void delete_actionPerformed(ActionEvent e) { if (isUserPreset) @@ -429,43 +483,45 @@ 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 @@ -494,34 +550,39 @@ public class WsJobParameters extends JPanel implements ItemListener, } @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) + 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; + paramList.add(opanp.addParameter(parm)); } 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); + jobOptions.add(ob, FlowLayout.LEFT); + 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()); } } } @@ -536,14 +597,13 @@ public class WsJobParameters extends JPanel implements ItemListener, // 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 { @@ -551,6 +611,7 @@ public class WsJobParameters extends JPanel implements ItemListener, { isUserPreset = false; // first call - so create a dummy name + setName.setSelectedItem(lastSetName = SVC_DEF); } } @@ -563,31 +624,27 @@ 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 " // + System.identityHashCode(arg) + ":" + arg.getName() // + " with " + arg.getDefaultValue()); - selectOption((Option) arg, 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(); revalidate(); } @@ -636,19 +693,24 @@ public class WsJobParameters extends JPanel implements ItemListener, validate(); } - private void argSetModified(Object modifiedElement, boolean b) + public void argSetModified(Object modifiedElement, boolean b) { if (settingDialog) { return; } - if (!b) { modifiedElements.remove(modifiedElement); } else { + if (b && modifiedElement == setName + && modifiedElements.contains(modifiedElement)) + { + // HACK! prevents iteration on makeSetNameValid + b = false; + } modifiedElements.put(modifiedElement, modifiedElement); } // set mod status based on presence of elements in table @@ -675,7 +737,8 @@ public class WsJobParameters extends JPanel implements ItemListener, 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)) { @@ -686,7 +749,7 @@ public class WsJobParameters extends JPanel implements ItemListener, if (newuserset) { int i = 0; - while (_getUserPreset(tnm) != null) + while (paramStore.getPreset(tnm) != null) { tnm = nm + " (" + (++i) + ")"; renamed = true; @@ -721,634 +784,61 @@ public class WsJobParameters extends JPanel implements ItemListener, settingDialog = stn; } - private void addParameter(Parameter parm) - { - ParamBox pb = paramSet.get(parm.getName()); - if (pb == null) - { - 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); - } - - } - - private void selectOption(Option opt, String string) - { - OptionBox cb = optSet.get(opt.getName()); - if (cb == null) - { - cb = addOption(opt); - } - cb.enabled.setSelected(string != null); // initial state for an option. - if (string != null) - { - if (opt.getPossibleValues().contains(string)) - { - cb.val.setSelectedItem(string); - } - else - { - throw new Error("Invalid value " + string + " for option " + opt); - } - - } - if (opt.isRequired() && !cb.enabled.isSelected()) - { - // TODO: indicate paramset is not valid.. option needs to be selected! - } - cb.setInitialValue(); - } - - Map paramSet = new Hashtable(); - - public class ParamBox extends JPanel implements ChangeListener, - ActionListener, MouseListener - { - JButton showDesc = new JButton(); - - JTextArea string = new JTextArea(); - - JScrollPane descPanel = new JScrollPane(); - - JSlider slider = null; - - JTextField valueField = null; - - ValueConstrain validator = null; - - JPanel settingPanel = new JPanel(); - - JPanel controlPanel = new JPanel(); - - boolean integ = false; - - boolean choice = false; - - boolean descisvisible = false; - - final WsJobParameters pmdialogbox; - - final URL finfo; - - public ParamBox(final WsJobParameters pmlayout, Parameter parm) - { - pmdialogbox = pmlayout; - setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT)); - setBorder(new TitledBorder(parm.getName())); - setLayout(null); - showDesc.setFont(new Font("Verdana", Font.PLAIN, 6)); - showDesc.setText("+"); - string.setFont(new Font("Verdana", Font.PLAIN, 11)); - string.setBackground(getBackground()); - // string.setSize(new Dimension(PARAM_WIDTH, 80)); - string.setEditable(false); - descPanel.getViewport().setView(string); - // descPanel.setLocation(2,17); - descPanel.setVisible(false); - // string.setMinimumSize(new Dimension(140,80)); - // string.setMaximumSize(new Dimension(280,80)); - final ParamBox me = this; - finfo = parm.getFurtherDetails(); - if (finfo != null) - { - showDesc.setToolTipText("

Click to show brief description, and right click to open link for further information.

"); - showDesc.addMouseListener(this); - } - else - { - showDesc.setToolTipText("

Click to show brief description.

"); - } - showDesc.addActionListener(new ActionListener() - { - - public void actionPerformed(ActionEvent e) - { - descisvisible = !descisvisible; - descPanel.setVisible(descisvisible); - me.setPreferredSize(new Dimension(PARAM_WIDTH, - (descisvisible) ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT)); - me.validate(); - pmlayout.refreshParamLayout(); - } - }); - string.setWrapStyleWord(true); - string.setLineWrap(true); - string.setColumns(32); - string.setText(parm.getDescription()); - JPanel firstrow = new JPanel(); - firstrow.setLayout(null); - controlPanel.setLayout(new BorderLayout()); - controlPanel.setBounds(new Rectangle(39, 10, PARAM_WIDTH - 70, - PARAM_CLOSEDHEIGHT - 50)); - showDesc.setBounds(new Rectangle(10, 10, 16, 16)); - firstrow.add(showDesc); - firstrow.add(controlPanel); - firstrow.setBounds(new Rectangle(10, 20, PARAM_WIDTH - 30, - PARAM_CLOSEDHEIGHT - 30)); - add(firstrow); - validator = parm.getValidValue(); - parameter = parm; - if (validator != null) - { - integ = validator.getType() == Type.Integer; - } - else - { - if (parameter.getPossibleValues() != null) - { - choice = true; - } - } - updateControls(parm); - descPanel.setBounds(new Rectangle(10, PARAM_CLOSEDHEIGHT, - PARAM_WIDTH - 20, PARAM_HEIGHT - PARAM_CLOSEDHEIGHT - 5)); - add(descPanel); - validate(); - } - - public void init() - { - // reset the widget's initial value. - lastVal = null; - } - - boolean adjusting = false; - - Parameter parameter; - - JComboBox choicebox; - - public int getBoxHeight() - { - return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT); - } - - public void updateControls(Parameter parm) - { - adjusting = true; - boolean init = (choicebox == null && valueField == null); - float fVal = 0f; - int iVal = 0; - if (init) - { - if (choice) - { - choicebox = new JComboBox(); - choicebox.addActionListener(this); - controlPanel.add(choicebox, BorderLayout.CENTER); - } - else - { - slider = new JSlider(); - slider.addChangeListener(this); - valueField = new JTextField(); - valueField.addActionListener(this); - valueField.setPreferredSize(new Dimension(60, 25)); - controlPanel.add(slider, BorderLayout.WEST); - controlPanel.add(valueField, BorderLayout.EAST); - - } - } - - if (parm != null) - { - if (choice) - { - if (init) - { - List vals = parm.getPossibleValues(); - for (Object val : vals) - { - choicebox.addItem(val); - } - } - - if (parm.getDefaultValue() != null) - { - choicebox.setSelectedItem(parm.getDefaultValue()); - } - } - else - { - valueField.setText(parm.getDefaultValue()); - } - } - lastVal = updateSliderFromValueField(); - adjusting = false; - } - - Object lastVal; - - public Parameter getParameter() - { - Parameter prm = ParameterUtils.copyParameter(parameter); - try - { - if (choice) - { - prm.setDefaultValue((String) choicebox.getSelectedItem()); - } - else - { - prm.setDefaultValue(valueField.getText()); - } - } catch (WrongParameterException e) - { - e.printStackTrace(); - return null; - } - return prm; - } - - public Object updateSliderFromValueField() - { - int iVal; - float fVal; - if (validator != null) - { - if (integ) - { - iVal = 0; - try - { - valueField.setText(valueField.getText().trim()); - iVal = Integer.valueOf(valueField.getText()); - } catch (Exception e) - { - } - ; - if (validator.getMin() != null && validator.getMax() != null) - { - slider.getModel().setRangeProperties(iVal, 1, - validator.getMin().intValue(), - validator.getMax().intValue(), true); - } - else - { - slider.setVisible(false); - } - return new int[] - { iVal }; - } - else - { - fVal = 0f; - try - { - fVal = Float.valueOf(valueField.getText()); - } catch (Exception e) - { - } - ; - if (validator.getMin() != null && validator.getMax() != null) - { - slider.getModel().setRangeProperties((int) fVal * 1000, 1, - (int) validator.getMin().floatValue() * 1000, - (int) validator.getMax().floatValue() * 1000, true); - } - else - { - slider.setVisible(false); - } - return new float[] - { fVal }; - } - } - else - { - if (!choice) - { - slider.setVisible(false); - return new String[] - { valueField.getText().trim() }; - } - else - { - return new String[] - { (String) choicebox.getSelectedItem() }; - } - } - - } - - public void stateChanged(ChangeEvent e) - { - if (!adjusting) - { - valueField.setText("" - + ((integ) ? ("" + (int) slider.getValue()) - : ("" + (float) (slider.getValue() / 1000f)))); - checkIfModified(); - } - - } - - public void actionPerformed(ActionEvent e) - { - if (adjusting) - { - return; - } - if (!choice) - { - updateSliderFromValueField(); - } - checkIfModified(); - } - - private void checkIfModified() - { - Object cstate = updateSliderFromValueField(); - boolean notmod = false; - if (cstate.getClass() == lastVal.getClass()) - { - if (cstate instanceof int[]) - { - notmod = (((int[]) cstate)[0] == ((int[]) lastVal)[0]); - } - else if (cstate instanceof float[]) - { - notmod = (((float[]) cstate)[0] == ((float[]) lastVal)[0]); - } - else if (cstate instanceof String[]) - { - notmod = (((String[]) cstate)[0].equals(((String[]) lastVal)[0])); - } - } - pmdialogbox.argSetModified(this, !notmod); - } - - public void mouseClicked(MouseEvent e) - { - if (javax.swing.SwingUtilities.isRightMouseButton(e)) - { - Desktop.showUrl(finfo.toString()); - } - } - - public void mousePressed(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - public void mouseReleased(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - public void mouseEntered(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - public void mouseExited(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - } - - Map optSet = new Hashtable(); - public class OptionBox extends JPanel implements MouseListener, - ActionListener + public void refreshParamLayout() { - JComboBox val = new JComboBox(); - - JCheckBox enabled = new JCheckBox(); - - JLabel optlabel = new JLabel(); - - URL linkImageURL = getClass().getResource("/images/link.gif"); - - final URL finfo; - - boolean hasLink = false; - - Option option; - - public OptionBox(Option opt) - { - option = opt; - setLayout(new BorderLayout()); - enabled.setSelected(opt.isRequired()); // TODO: lock required options - enabled.setFont(new Font("Verdana", Font.PLAIN, 11)); - enabled.setText(""); - enabled.setText(opt.getName()); - enabled.addActionListener(this); - finfo = option.getFurtherDetails(); - if (finfo != null) - { - hasLink = true; - // optlabel.setToolTipText("

"+opt.getDescription()+"

"); - enabled.setToolTipText("

" + opt.getDescription() - + "

"); - // optlabel.addMouseListener(this); - enabled.addMouseListener(this); - } - else - { - // optlabel.setToolTipText(opt.getDescription()); - enabled.setToolTipText(opt.getDescription()); - } - add(enabled, BorderLayout.NORTH); - if (opt.getPossibleValues().size() > 1) - { - setLayout(new GridLayout(1, 2)); - for (Object str : opt.getPossibleValues()) - { - val.addItem((String) str); - } - val.setSelectedItem((String) opt.getDefaultValue()); - val.addActionListener(this); - add(val, BorderLayout.SOUTH); - } - // TODO: add actionListeners for popup (to open further info), - // and to update list of parameters if an option is enabled - // that takes a value. - setInitialValue(); - } - - public void resetToDefault() - { - enabled.setSelected(false); - if (option.isRequired()) - { - // Apply default value - selectOption(option, option.getDefaultValue()); - } - } - - boolean initEnabled = false; - - String initVal = null; - - public void setInitialValue() - { - initEnabled = enabled.isSelected(); - if (option.getPossibleValues() != null - && option.getPossibleValues().size() > 1) - { - initVal = (String) val.getSelectedItem(); - } - else - { - initVal = (initEnabled) ? option.getDefaultValue() : null; - } - } - - public Option getOptionIfEnabled() - { - if (!enabled.isSelected()) - { - return null; - } - Option opt = null; - try - { - opt = jalview.ws.jws2.ParameterUtils.copyOption(option); - - if (val.getSelectedItem() != null) - { - opt.setDefaultValue((String) val.getSelectedItem()); - } - } catch (WrongParameterException e) + 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 > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH : OptsAndParamsPage.PARAM_WIDTH); + jobOptions.setLayout(fl); + if (opanp.getOptSet().size() > 0) + { + + for (OptionBox pbox : opanp.getOptSet().values()) { - e.printStackTrace(); - return null; + pbox.revalidate(); + s += sep + pbox.getPreferredSize().height; } - return opt; + jobOptions.setPreferredSize(new Dimension(w, s)); + jobOptions.setLayout(new GridLayout(opanp.getOptSet().size(),1)); + os=s; } - - public void actionPerformed(ActionEvent e) + else { - if (e.getSource() != enabled) - { - enabled.setSelected(true); - } - checkIfModified(); + jobOptions.setVisible(false); } - private void checkIfModified() + // 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 (opanp.getParamSet().size() > 0) { - boolean notmod = (initEnabled == enabled.isSelected()); - 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 == null; - } - argSetModified(this, !notmod); - } + paramList.setLayout(fl); - public void mouseClicked(MouseEvent e) - { - if (javax.swing.SwingUtilities.isRightMouseButton(e)) + s = 2 * sep; + for (ParamBox pbox : opanp.getParamSet().values()) { - showUrlPopUp(this, finfo.toString(), e.getX(), e.getY()); + 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; } - - public void mousePressed(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - public void mouseReleased(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - public void mouseEntered(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - public void mouseExited(MouseEvent e) - { - // TODO Auto-generated method stub - - } - - } - - private OptionBox addOption(Option opt) - { - OptionBox cb = optSet.get(opt.getName()); - if (cb == null) - { - cb = new OptionBox(opt); - optSet.put(opt.getName(), cb); - jobOptions.add(cb); - } - return cb; - } - - public static void showUrlPopUp(JComponent invoker, final String finfo, - int x, int y) - { - - JPopupMenu mnu = new JPopupMenu(); - JMenuItem mitem = new JMenuItem("View " + finfo); - mitem.addActionListener(new ActionListener() - { - - @Override - public void actionPerformed(ActionEvent e) - { - Desktop.showUrl(finfo); - - } - }); - mnu.add(mitem); - mnu.show(invoker, x, y); - } - - protected void refreshParamLayout() - { - FlowLayout fl = new FlowLayout(); - paramList.setLayout(fl); - int s = 2 * fl.getVgap(); - for (ParamBox pbox : paramSet.values()) + else { - s += fl.getVgap() + pbox.getBoxHeight(); // getBoxHeight(); + paramList.setVisible(false); } - paramList.setPreferredSize(new Dimension(PARAM_WIDTH, s)); + // 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(OptsAndParamsPage.PARAM_CLOSEDHEIGHT*2); + paramPane.validate(); validate(); } @@ -1362,7 +852,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++]); @@ -1421,7 +911,7 @@ public class WsJobParameters extends JPanel implements ItemListener, } { System.out.println("Testing opts dupes for " - + lastserv.getHost() + " : " + + lastserv.getUri() + " : " + lastserv.getActionText() + ":" + pr.getName()); List