boolean adjusting = false;
- private float min;
+ final private float min;
- private float max;
+ final private float max;
+
+ final private float scaleFactor;
String type = null;
{
if (!adjusting)
{
- thresholdValue.setText((slider.getValue() / 1000f) + "");
+ thresholdValue.setText((slider.getValue() / scaleFactor) + "");
valueChanged();
}
}
float mm[] = ((float[][]) fr.getMinMax().get(type))[0];
min = mm[0];
max = mm[1];
+
+ /*
+ * ensure scale factor allows a scaled range with
+ * 10 integer divisions ('ticks'); if we have got here,
+ * we should expect that max != min
+ */
+ scaleFactor = (max == min) ? 1f : 100f / (max - min);
+
oldcs = fr.getFeatureColours().get(type);
if (oldcs instanceof GraduatedColor)
{
waitForInput();
}
- public FeatureColourChooser()
- {
- try
- {
- jbInit();
- } catch (Exception ex)
- {
- ex.printStackTrace();
- }
- }
-
private void jbInit() throws Exception
{
adjusting = true;
acg.setThresh(threshline.value);
- float range = max * 1000f - min * 1000f;
+ float range = (max - min) * scaleFactor;
- slider.setMinimum((int) (min * 1000));
- slider.setMaximum((int) (max * 1000));
- slider.setValue((int) (threshline.value * 1000));
+ slider.setMinimum((int) (min * scaleFactor));
+ slider.setMaximum((int) (max * scaleFactor));
+ slider.setValue((int) (threshline.value * scaleFactor));
thresholdValue.setText(threshline.value + "");
slider.setMajorTickSpacing((int) (range / 10f));
slider.setEnabled(true);
try
{
float f = Float.parseFloat(thresholdValue.getText());
- slider.setValue((int) (f * 1000));
+ slider.setValue((int) (f * scaleFactor));
threshline.value = f;
} catch (NumberFormatException ex)
{
public void valueChanged()
{
- threshline.value = slider.getValue() / 1000f;
+ threshline.value = slider.getValue() / scaleFactor;
cs.setThresh(threshline.value);
changeColour();
ap.paintAlignment(false);