-
- double newValue = num.doubleValue();
- double converted = currentUnit.fromUnit(newValue);
-
- log.user("SpinnerModel setValue called for " + DoubleModel.this.toString() + " newValue=" + newValue +
- " converted=" + converted);
- DoubleModel.this.setValue(converted);
-
+
+ // Update the doublemodel with the new number or return to the last number if not possible
+ if (((Double) num).isNaN()) {
+ DoubleModel.this.setValue(lastValue);
+ log.user("SpinnerModel could not set value for " + DoubleModel.this.toString() + ". Could not convert " + value.toString());
+ }
+ else {
+ double newValue = num.doubleValue();
+ double converted = currentUnit.fromUnit(newValue);
+
+ log.user("SpinnerModel setValue called for " + DoubleModel.this.toString() + " newValue=" + newValue +
+ " converted=" + converted);
+ DoubleModel.this.setValue(converted);
+ }
+
+ // Force a refresh if text doesn't match up exactly with the stored value
+ if (!((Double) lastValue).toString().equals(this.getValue().toString())) {
+ DoubleModel.this.fireStateChanged();
+ log.debug("SpinnerModel " + DoubleModel.this.toString() + " refresh forced because string did not match actual value.");
+ }