{
if (!adjusting)
{
- thresholdValue.setText((slider.getValue() / 1000f) + "");
+ setThresholdValueText();
valueChanged(!sliderDragging);
}
}
@Override
public void actionPerformed(ActionEvent evt)
{
- if (evt.getSource() == thresholdValue)
- {
- try
- {
- float f = new Float(thresholdValue.getText()).floatValue();
- slider.setValue((int) (f * 1000));
- adjustmentValueChanged(null);
- } catch (NumberFormatException ex)
- {
- }
- }
- else if (evt.getSource() == ok)
+ if (evt.getSource() == ok)
{
ok_actionPerformed(null);
}
updateView();
}
+ /**
+ * update the text field from the threshold slider. preserves state of
+ * 'adjusting' so safe to call in init.
+ */
protected void setThresholdValueText()
{
+ boolean oldadj = adjusting;
adjusting = true;
if (percentThreshold.getState())
{
double scl = slider.getMaximum() - slider.getMinimum();
scl = (slider.getValue() - slider.getMinimum()) / scl;
- thresholdValue.setText(100 * scl + "");
+ thresholdValue.setText(100f * scl + "");
}
else
{
thresholdValue.setText((slider.getValue() / 1000f) + "");
}
thresholdValue.setCaretPosition(0);
- adjusting = false;
+ adjusting = oldadj;
}
public void thresholdValue_actionPerformed(ActionEvent e)
float f = Float.parseFloat(thresholdValue.getText());
if (percentThreshold.getState())
{
- slider.setValue(slider.getMinimum()
- + ((int) ((f / 100f) * (slider.getMaximum() - slider
- .getMinimum()))));
+ int pos = slider.getMinimum()
+ + (int) ((slider.getMaximum() - slider.getMinimum()) * f / 100f);
+ slider.setValue(pos);
}
else
{
slider.setValue((int) (f * 1000));
}
- updateView();
+ valueChanged(false);
} catch (NumberFormatException ex)
{
}
slider.setMaximum((int) (getCurrentAnnotation().graphMax * 1000));
slider.setValue((int) (getCurrentAnnotation().threshold.value * 1000));
- if (percentThreshold.isSelected())
- {
- thresholdValue
- .setText(""
- + ((getCurrentAnnotation().threshold.value - getCurrentAnnotation().graphMin) * 100f / (getCurrentAnnotation().graphMax - getCurrentAnnotation().graphMin)));
- }
- else
- {
- thresholdValue.setText(getCurrentAnnotation().threshold.value + "");
- }
+ setThresholdValueText();
slider.setMajorTickSpacing((int) (range / 10f));
slider.setEnabled(true);
});
}
+ /**
+ * update the text field from the threshold slider. preserves state of
+ * 'adjusting' so safe to call in init.
+ */
protected void setThresholdValueText()
{
+ boolean oldadj = adjusting;
adjusting = true;
if (percentThreshold.isSelected())
{
{
thresholdValue.setText((slider.getValue() / 1000f) + "");
}
- adjusting = false;
+ adjusting = oldadj;
}
protected void addSliderMouseListeners()
{
try
{
float f = Float.parseFloat(thresholdValue.getText());
- if (percentThreshold.isEnabled())
+ if (percentThreshold.isSelected())
{
slider.setValue(slider.getMinimum()
+ ((int) ((f / 100f) * (slider.getMaximum() - slider