--- /dev/null
+package jalview.gui;
+
+import jalview.ws.params.OptionI;
+import jalview.ws.params.ParameterI;
+import jalview.ws.params.ValueConstrainI;
+
+import java.awt.BorderLayout;
+import java.awt.Component;
+import java.awt.Container;
+import java.awt.Dimension;
+import java.awt.FlowLayout;
+import java.awt.Font;
+import java.awt.GridLayout;
+import java.awt.Rectangle;
+import java.awt.event.ActionEvent;
+import java.awt.event.ActionListener;
+import java.awt.event.MouseEvent;
+import java.awt.event.MouseListener;
+import java.net.URL;
+import java.util.Hashtable;
+import java.util.List;
+import java.util.Map;
+
+import javax.swing.JButton;
+import javax.swing.JCheckBox;
+import javax.swing.JComboBox;
+import javax.swing.JComponent;
+import javax.swing.JLabel;
+import javax.swing.JMenuItem;
+import javax.swing.JPanel;
+import javax.swing.JPopupMenu;
+import javax.swing.JScrollPane;
+import javax.swing.JSlider;
+import javax.swing.JTextArea;
+import javax.swing.JTextField;
+import javax.swing.border.TitledBorder;
+import javax.swing.event.ChangeEvent;
+import javax.swing.event.ChangeListener;
+
+import compbio.metadata.ValueConstrain.Type;
+
+/**
+ * GUI generator/manager for options and parameters. Originally abstracted from the WsJobParameters dialog box.
+ * @author jprocter
+ *
+ */
+public class OptsAndParamsPage
+{
+ public class OptionBox extends JPanel implements MouseListener,
+ ActionListener
+ {
+ JCheckBox enabled = new JCheckBox();
+
+ final URL finfo;
+
+ boolean hasLink = false;
+
+ boolean initEnabled = false;
+
+ String initVal = null;
+
+ OptionI option;
+
+ JLabel optlabel = new JLabel();
+
+ JComboBox val = new JComboBox();
+
+ public OptionBox(OptionI opt)
+ {
+ option = opt;
+ setLayout(new BorderLayout());
+ enabled.setSelected(opt.isRequired()); // TODO: lock required options
+ enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
+ enabled.setText("");
+ enabled.setText(opt.getName());
+ enabled.addActionListener(this);
+ finfo = option.getFurtherDetails();
+ if (finfo != null)
+ {
+ hasLink = true;
+ enabled.setToolTipText("<html>"
+ + JvSwingUtils.wrapTooltip(opt.getDescription()
+ + "<br><img src=\"" + linkImageURL + "\"/>")
+ + "</html>");
+ enabled.addMouseListener(this);
+ }
+ else
+ {
+ enabled.setToolTipText("<html>"
+ + JvSwingUtils.wrapTooltip(opt.getDescription())
+ + "</html>");
+ }
+ 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. JBPNote: is this TODO still valid ?
+ setInitialValue();
+ }
+
+ public void actionPerformed(ActionEvent e)
+ {
+ if (e.getSource() != enabled)
+ {
+ enabled.setSelected(true);
+ }
+ checkIfModified();
+ }
+
+ private void checkIfModified()
+ {
+ boolean notmod = (initEnabled == enabled.isSelected());
+ if (enabled.isSelected())
+ {
+ if (initVal != null)
+ {
+ notmod &= initVal.equals(val.getSelectedItem());
+ }
+ else
+ {
+ // compare against default service setting
+ notmod &= option.getDefaultValue() == null
+ || option.getDefaultValue().equals(val.getSelectedItem());
+ }
+ }
+ else
+ {
+ notmod &= initVal == null;
+ }
+ poparent.argSetModified(this, !notmod);
+ }
+
+ public OptionI getOptionIfEnabled()
+ {
+ if (!enabled.isSelected())
+ {
+ return null;
+ }
+ OptionI opt = option.copy();
+
+ if (val.getSelectedItem() != null)
+ {
+ opt.setDefaultValue((String) val.getSelectedItem());
+ }
+ return opt;
+ }
+
+ public void mouseClicked(MouseEvent e)
+ {
+ if (javax.swing.SwingUtilities.isRightMouseButton(e))
+ {
+ showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
+ }
+ }
+
+ public void mouseEntered(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseExited(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void resetToDefault()
+ {
+ enabled.setSelected(false);
+ if (option.isRequired())
+ {
+ // Apply default value
+ selectOption(option, option.getDefaultValue());
+ }
+ }
+
+ 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 class ParamBox extends JPanel implements ChangeListener,
+ ActionListener, MouseListener
+ {
+ boolean adjusting = false;
+
+ boolean choice = false;
+
+ JComboBox choicebox;
+
+ JPanel controlPanel = new JPanel();
+
+ boolean descisvisible = false;
+
+ JScrollPane descPanel = new JScrollPane();
+
+ final URL finfo;
+
+ boolean integ = false;
+
+ Object lastVal;
+
+ ParameterI parameter;
+
+ final OptsParametersContainerI pmdialogbox;
+
+ JPanel settingPanel = new JPanel();
+
+ JButton showDesc = new JButton();
+
+ JSlider slider = null;
+
+ JTextArea string = new JTextArea();
+
+ ValueConstrainI validator = null;
+
+ JTextField valueField = null;
+
+ public ParamBox(final OptsParametersContainerI pmlayout, ParameterI parm)
+ {
+ pmdialogbox = pmlayout;
+ setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
+ setBorder(new TitledBorder(parm.getName()));
+ setLayout(null);
+ showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
+ showDesc.setText("+");
+ string.setFont(new Font("Verdana", Font.PLAIN, 11));
+ string.setBackground(getBackground());
+
+ string.setEditable(false);
+ descPanel.getViewport().setView(string);
+
+ descPanel.setVisible(false);
+
+ final ParamBox me = this;
+ finfo = parm.getFurtherDetails();
+ if (finfo != null)
+ {
+ showDesc.setToolTipText("<html>"
+ + JvSwingUtils
+ .wrapTooltip("Click to show brief description<br><img src=\""
+ + linkImageURL
+ + "\"/> Right click for further information.")
+ + "</html>");
+ showDesc.addMouseListener(this);
+ }
+ else
+ {
+ showDesc.setToolTipText("<html>"
+ + JvSwingUtils
+ .wrapTooltip("Click to show brief description.")
+ + "</html>");
+ }
+ showDesc.addActionListener(new ActionListener()
+ {
+
+ public void actionPerformed(ActionEvent e)
+ {
+ descisvisible = !descisvisible;
+ descPanel.setVisible(descisvisible);
+ descPanel.getVerticalScrollBar().setValue(0);
+ 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 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);
+ }
+
+ @Override
+ public int getBaseline(int width, int height) {
+ return 0;
+ }
+
+ // from http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
+ // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
+ @Override
+ public Component.BaselineResizeBehavior getBaselineResizeBehavior() {
+ return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
+ }
+
+ public int getBoxHeight()
+ {
+ return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
+ }
+
+ public ParameterI getParameter()
+ {
+ ParameterI prm = parameter.copy();
+ if (choice)
+ {
+ prm.setDefaultValue((String) choicebox.getSelectedItem());
+ }
+ else
+ {
+ prm.setDefaultValue(valueField.getText());
+ }
+ return prm;
+ }
+
+ public void init()
+ {
+ // reset the widget's initial value.
+ lastVal = null;
+ }
+
+ public void mouseClicked(MouseEvent e)
+ {
+ if (javax.swing.SwingUtilities.isRightMouseButton(e))
+ {
+ showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
+ }
+ }
+
+ public void mouseEntered(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseExited(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mousePressed(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void mouseReleased(MouseEvent e)
+ {
+ // TODO Auto-generated method stub
+
+ }
+
+ public void stateChanged(ChangeEvent e)
+ {
+ if (!adjusting)
+ {
+ valueField.setText(""
+ + ((integ) ? ("" + (int) slider.getValue())
+ : ("" + (float) (slider.getValue() / 1000f))));
+ checkIfModified();
+ }
+
+ }
+ public void updateControls(ParameterI parm)
+ {
+ adjusting = true;
+ boolean init = (choicebox == null && valueField == null);
+ 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;
+ }
+
+ 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());
+ if (validator.getMin() != null
+ && validator.getMin().intValue() > iVal)
+ {
+ iVal = validator.getMin().intValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
+ if (validator.getMax() != null
+ && validator.getMax().intValue() < iVal)
+ {
+ iVal = validator.getMax().intValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
+ } catch (Exception e)
+ {
+ }
+ ;
+ 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());
+ if (validator.getMin() != null
+ && validator.getMin().floatValue() > fVal)
+ {
+ fVal = validator.getMin().floatValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
+ if (validator.getMax() != null
+ && validator.getMax().floatValue() < fVal)
+ {
+ fVal = validator.getMax().floatValue();
+ // TODO: provide visual indication that hard limit was reached for
+ // this parameter
+ }
+ } catch (Exception e)
+ {
+ }
+ ;
+ 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() };
+ }
+ }
+
+ }
+ }
+
+ static final int PARAM_WIDTH = 340;
+
+ private static final int PARAM_HEIGHT = 150;
+
+ static final int PARAM_CLOSEDHEIGHT = 80;
+ public OptsAndParamsPage(WsJobParameters wsJobParameters)
+ {
+ poparent = wsJobParameters;
+ }
+
+ 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);
+ }
+
+
+ URL linkImageURL = getClass().getResource("/images/link.gif");
+
+ Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();
+
+ Map<String, ParamBox> paramSet = new Hashtable<String, ParamBox>();
+
+ public Map<String, OptionBox> getOptSet()
+ {
+ return optSet;
+ }
+
+ public void setOptSet(Map<String, OptionBox> optSet)
+ {
+ this.optSet = optSet;
+ }
+
+ public Map<String, ParamBox> getParamSet()
+ {
+ return paramSet;
+ }
+
+ public void setParamSet(Map<String, ParamBox> paramSet)
+ {
+ this.paramSet = paramSet;
+ }
+
+
+ OptsParametersContainerI poparent;
+
+ OptionBox addOption(OptionI opt)
+ {
+ OptionBox cb = optSet.get(opt.getName());
+ if (cb == null)
+ {
+ cb = new OptionBox(opt);
+ optSet.put(opt.getName(), cb);
+ // jobOptions.add(cb, FlowLayout.LEFT);
+ }
+ return cb;
+ }
+
+ ParamBox addParameter(ParameterI arg)
+ {
+ ParamBox pb = paramSet.get(arg.getName());
+ if (pb == null)
+ {
+ pb = new ParamBox(poparent, arg);
+ paramSet.put(arg.getName(), pb);
+// paramList.add(pb);
+ }
+ pb.init();
+ // take the defaults from the parameter
+ pb.updateControls(arg);
+ return pb;
+ }
+
+ void selectOption(OptionI option, String string)
+ {
+ OptionBox cb = optSet.get(option.getName());
+ if (cb == null)
+ {
+ cb = addOption(option);
+ }
+ cb.enabled.setSelected(string != null); // initial state for an option.
+ if (string != null)
+ {
+ if (option.getPossibleValues().contains(string))
+ {
+ cb.val.setSelectedItem(string);
+ }
+ else
+ {
+ throw new Error("Invalid value " + string + " for option " + option);
+ }
+
+ }
+ if (option.isRequired() && !cb.enabled.isSelected())
+ {
+ // TODO: indicate paramset is not valid.. option needs to be selected!
+ }
+ cb.setInitialValue();
+ }
+
+ void setParameter(ParameterI arg)
+ {
+ ParamBox pb = paramSet.get(arg.getName());
+ if (pb == null)
+ {
+ addParameter(arg);
+ }
+ else
+ {
+ pb.updateControls(arg);
+ }
+
+ }
+
+
+}
*/
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 java.awt.BorderLayout;
import java.awt.Component;
+import java.awt.Container;
import java.awt.Dimension;
import java.awt.FlowLayout;
import java.awt.Font;
*
*/
public class WsJobParameters extends JPanel implements ItemListener,
- ActionListener, DocumentListener
+ ActionListener, DocumentListener, OptsParametersContainerI
{
URL linkImageURL = getClass().getResource("/images/link.gif");
// 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();
+
+ /**
+ * panel containing job parameters
+ */
+ JPanel paramList = new JPanel();
+
+
JPanel SetNamePanel = new JPanel();
JPanel setDetails = new JPanel();
JSplitPane jobPanel = new JSplitPane();
- JPanel jobOptions = new JPanel();
JScrollPane jobOptionsPane = new JScrollPane();
JScrollPane paramPane = new JScrollPane();
- JPanel paramList = new JPanel();
JPanel optsAndparams = new JPanel();
if (myarg instanceof ParameterI)
{
ParameterI parm = (ParameterI) myarg;
- addParameter(parm);
+ paramList.add(opanp.addParameter(parm));
}
else
{
if (myarg instanceof OptionI)
{
OptionI opt = (OptionI) myarg;
- OptionBox ob = addOption(opt);
+ OptionBox ob = opanp.addOption(opt);
+ jobOptions.add(ob, FlowLayout.LEFT);
ob.resetToDefault();
if (MAX_OPTWIDTH < ob.getPreferredSize().width)
{
{
if (arg instanceof ParameterI)
{
- setParameter((ParameterI) arg);
+ opanp.setParameter((ParameterI) arg);
}
else
{
// System.out.println("Setting option "
// + System.identityHashCode(arg) + ":" + arg.getName()
// + " with " + arg.getDefaultValue());
- selectOption((OptionI) arg, arg.getDefaultValue());
+ opanp.selectOption((OptionI) arg, arg.getDefaultValue());
}
}
validate();
}
- private void argSetModified(Object modifiedElement, boolean b)
+ public void argSetModified(Object modifiedElement, boolean b)
{
if (settingDialog)
{
settingDialog = stn;
}
- private void addParameter(ParameterI arg)
- {
- ParamBox pb = paramSet.get(arg.getName());
- if (pb == null)
- {
- pb = new ParamBox(this, arg);
- paramSet.put(arg.getName(), pb);
- paramList.add(pb);
- }
- pb.init();
- // take the defaults from the parameter
- pb.updateControls(arg);
- }
-
- private void setParameter(ParameterI arg)
- {
- ParamBox pb = paramSet.get(arg.getName());
- if (pb == null)
- {
- addParameter(arg);
- }
- else
- {
- pb.updateControls(arg);
- }
-
- }
-
- private void selectOption(OptionI option, String string)
- {
- OptionBox cb = optSet.get(option.getName());
- if (cb == null)
- {
- cb = addOption(option);
- }
- cb.enabled.setSelected(string != null); // initial state for an option.
- if (string != null)
- {
- if (option.getPossibleValues().contains(string))
- {
- cb.val.setSelectedItem(string);
- }
- else
- {
- throw new Error("Invalid value " + string + " for option " + option);
- }
-
- }
- if (option.isRequired() && !cb.enabled.isSelected())
- {
- // TODO: indicate paramset is not valid.. option needs to be selected!
- }
- cb.setInitialValue();
- }
-
- Map<String, ParamBox> paramSet = new Hashtable<String, ParamBox>();
-
- public class ParamBox extends JPanel implements ChangeListener,
- ActionListener, MouseListener
- {
- JButton showDesc = new JButton();
-
- JTextArea string = new JTextArea();
-
- JScrollPane descPanel = new JScrollPane();
-
- JSlider slider = null;
-
- JTextField valueField = null;
-
- ValueConstrainI validator = null;
-
- JPanel settingPanel = new JPanel();
-
- JPanel controlPanel = new JPanel();
-
- boolean integ = false;
-
- boolean choice = false;
-
- boolean descisvisible = false;
-
- final WsJobParameters pmdialogbox;
-
- final URL finfo;
-
- public ParamBox(final WsJobParameters pmlayout, ParameterI parm)
- {
- pmdialogbox = pmlayout;
- setPreferredSize(new Dimension(PARAM_WIDTH, PARAM_CLOSEDHEIGHT));
- setBorder(new TitledBorder(parm.getName()));
- setLayout(null);
- showDesc.setFont(new Font("Verdana", Font.PLAIN, 6));
- showDesc.setText("+");
- string.setFont(new Font("Verdana", Font.PLAIN, 11));
- string.setBackground(getBackground());
-
- string.setEditable(false);
- descPanel.getViewport().setView(string);
-
- descPanel.setVisible(false);
-
- final ParamBox me = this;
- finfo = parm.getFurtherDetails();
- if (finfo != null)
- {
- showDesc.setToolTipText("<html>"
- + JvSwingUtils
- .wrapTooltip("Click to show brief description<br><img src=\""
- + linkImageURL
- + "\"/> Right click for further information.")
- + "</html>");
- showDesc.addMouseListener(this);
- }
- else
- {
- showDesc.setToolTipText("<html>"
- + JvSwingUtils
- .wrapTooltip("Click to show brief description.")
- + "</html>");
- }
- showDesc.addActionListener(new ActionListener()
- {
-
- public void actionPerformed(ActionEvent e)
- {
- descisvisible = !descisvisible;
- descPanel.setVisible(descisvisible);
- descPanel.getVerticalScrollBar().setValue(0);
- 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;
-
- ParameterI parameter;
-
- JComboBox choicebox;
-
- public int getBoxHeight()
- {
- return (descisvisible ? PARAM_HEIGHT : PARAM_CLOSEDHEIGHT);
- }
-
- public void updateControls(ParameterI parm)
- {
- adjusting = true;
- boolean init = (choicebox == null && valueField == null);
- 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 ParameterI getParameter()
- {
- ParameterI prm = parameter.copy();
- if (choice)
- {
- prm.setDefaultValue((String) choicebox.getSelectedItem());
- }
- else
- {
- prm.setDefaultValue(valueField.getText());
- }
- 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());
- if (validator.getMin() != null
- && validator.getMin().intValue() > iVal)
- {
- iVal = validator.getMin().intValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- }
- if (validator.getMax() != null
- && validator.getMax().intValue() < iVal)
- {
- iVal = validator.getMax().intValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- }
- } catch (Exception e)
- {
- }
- ;
- 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());
- if (validator.getMin() != null
- && validator.getMin().floatValue() > fVal)
- {
- fVal = validator.getMin().floatValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- }
- if (validator.getMax() != null
- && validator.getMax().floatValue() < fVal)
- {
- fVal = validator.getMax().floatValue();
- // TODO: provide visual indication that hard limit was reached for
- // this parameter
- }
- } catch (Exception e)
- {
- }
- ;
- 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))
- {
- showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
- }
- }
-
- 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
-
- }
- // from http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
- // helpful hint of using the Java 1.6 alignBaseLine property of FlowLayout
- @Override
- public Component.BaselineResizeBehavior getBaselineResizeBehavior() {
- return Component.BaselineResizeBehavior.CONSTANT_ASCENT;
- }
-
- @Override
- public int getBaseline(int width, int height) {
- return 0;
- }
- }
-
- Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();
-
- public class OptionBox extends JPanel implements MouseListener,
- ActionListener
- {
- JComboBox val = new JComboBox();
-
- JCheckBox enabled = new JCheckBox();
-
- JLabel optlabel = new JLabel();
-
- final URL finfo;
-
- boolean hasLink = false;
-
- OptionI option;
-
- public OptionBox(OptionI opt)
- {
- option = opt;
- setLayout(new BorderLayout());
- enabled.setSelected(opt.isRequired()); // TODO: lock required options
- enabled.setFont(new Font("Verdana", Font.PLAIN, 11));
- enabled.setText("");
- enabled.setText(opt.getName());
- enabled.addActionListener(this);
- finfo = option.getFurtherDetails();
- if (finfo != null)
- {
- hasLink = true;
- enabled.setToolTipText("<html>"
- + JvSwingUtils.wrapTooltip(opt.getDescription()
- + "<br><img src=\"" + linkImageURL + "\"/>")
- + "</html>");
- enabled.addMouseListener(this);
- }
- else
- {
- enabled.setToolTipText("<html>"
- + JvSwingUtils.wrapTooltip(opt.getDescription())
- + "</html>");
- }
- 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. JBPNote: is this TODO still valid ?
- setInitialValue();
- }
-
- public void resetToDefault()
- {
- enabled.setSelected(false);
- if (option.isRequired())
- {
- // Apply default value
- selectOption(option, option.getDefaultValue());
- }
- }
-
- boolean initEnabled = false;
-
- String initVal = null;
-
- public void setInitialValue()
- {
- initEnabled = enabled.isSelected();
- if (option.getPossibleValues() != null
- && option.getPossibleValues().size() > 1)
- {
- initVal = (String) val.getSelectedItem();
- }
- else
- {
- initVal = (initEnabled) ? option.getDefaultValue() : null;
- }
- }
-
- public OptionI getOptionIfEnabled()
- {
- if (!enabled.isSelected())
- {
- return null;
- }
- OptionI opt = option.copy();
-
- if (val.getSelectedItem() != null)
- {
- opt.setDefaultValue((String) val.getSelectedItem());
- }
- return opt;
- }
-
- public void actionPerformed(ActionEvent e)
- {
- if (e.getSource() != enabled)
- {
- enabled.setSelected(true);
- }
- checkIfModified();
- }
-
- private void checkIfModified()
- {
- boolean notmod = (initEnabled == enabled.isSelected());
- if (enabled.isSelected())
- {
- if (initVal != null)
- {
- notmod &= initVal.equals(val.getSelectedItem());
- }
- else
- {
- // compare against default service setting
- notmod &= option.getDefaultValue() == null
- || option.getDefaultValue().equals(val.getSelectedItem());
- }
- }
- else
- {
- notmod &= initVal == null;
- }
- argSetModified(this, !notmod);
- }
-
- public void mouseClicked(MouseEvent e)
- {
- if (javax.swing.SwingUtilities.isRightMouseButton(e))
- {
- showUrlPopUp(this, finfo.toString(), e.getX(), e.getY());
- }
- }
-
- public void mousePressed(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseReleased(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseEntered(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- public void mouseExited(MouseEvent e)
- {
- // TODO Auto-generated method stub
-
- }
-
- }
-
- private OptionBox addOption(OptionI opt)
- {
- OptionBox cb = optSet.get(opt.getName());
- if (cb == null)
- {
- cb = new OptionBox(opt);
- optSet.put(opt.getName(), cb);
- jobOptions.add(cb, FlowLayout.LEFT);
- }
- 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()
+ public void refreshParamLayout()
{
FlowLayout fl = new FlowLayout(FlowLayout.LEFT);
int sep=fl.getVgap();
int os=0,s = jobOptions.getBorder().getBorderInsets(jobOptions).bottom+jobOptions.getBorder().getBorderInsets(jobOptions).top+2 * sep;
- int w = 2 * fl.getHgap() + (MAX_OPTWIDTH > PARAM_WIDTH ? MAX_OPTWIDTH : PARAM_WIDTH);
+ int w = 2 * fl.getHgap() + (MAX_OPTWIDTH > OptsAndParamsPage.PARAM_WIDTH ? MAX_OPTWIDTH : OptsAndParamsPage.PARAM_WIDTH);
jobOptions.setLayout(fl);
- if (optSet.size() > 0)
+ if (opanp.getOptSet().size() > 0)
{
- for (OptionBox pbox : optSet.values())
+ for (OptionBox pbox : opanp.getOptSet().values())
{
pbox.revalidate();
s += sep + pbox.getPreferredSize().height;
}
jobOptions.setPreferredSize(new Dimension(w, s));
- jobOptions.setLayout(new GridLayout(optSet.size(),1));
+ jobOptions.setLayout(new GridLayout(opanp.getOptSet().size(),1));
os=s;
}
else
fl = new FlowLayout(FlowLayout.CENTER);
// helpful hint from http://stackoverflow.com/questions/2743177/top-alignment-for-flowlayout
fl.setAlignOnBaseline(true);
- if (paramSet.size() > 0)
+ if (opanp.getParamSet().size() > 0)
{
paramList.setLayout(fl);
s = 2 * sep;
- for (ParamBox pbox : paramSet.values())
+ for (ParamBox pbox : opanp.getParamSet().values())
{
pbox.validate();
s += sep + pbox.getPreferredSize().height+pbox.getBorder().getBorderInsets(pbox).bottom;
// System.out.println("Size will be : "+w+","+os);
optsAndparams.validate();
paramPane.getViewport().validate();
- paramPane.getVerticalScrollBar().setBlockIncrement(PARAM_CLOSEDHEIGHT*2);
+ paramPane.getVerticalScrollBar().setBlockIncrement(OptsAndParamsPage.PARAM_CLOSEDHEIGHT*2);
paramPane.validate();
validate();
}
{
List<ArgumentI> argSet = new ArrayList<ArgumentI>();
// recover options and parameters from GUI
- for (OptionBox opts : optSet.values())
+ for (OptionBox opts : opanp.getOptSet().values())
{
OptionI opt = opts.getOptionIfEnabled();
if (opt != null)
argSet.add(opt);
}
}
- for (ParamBox parambox : paramSet.values())
+ for (ParamBox parambox : opanp.getParamSet().values())
{
ParameterI parm = parambox.getParameter();
if (parm != null)