- 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.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("<html><p>Click to show brief description<br><img src=\"" + linkImageURL + "\"/> Right click for further information.</p></html>");
- showDesc.addMouseListener(this);
- }
- else
- {
- showDesc.setToolTipText("<html><p>Click to show brief description.</p></html>");
- }
- 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;
-
- 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);
- 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 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
-
- }
-
- }
-
- Map<String, OptionBox> optSet = new Hashtable<String, OptionBox>();