- 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)