FieldNumber

public final class FieldNumber extends Field

A 'field_number' type of field, for an editable number.

Constant Summary

double NO_CONSTRAINT

Inherited Constant Summary

Field Summary

protected static final DecimalFormat INTEGER_DECIMAL_FORMAT This formatter is used when precision is a multiple of 1.

Inherited Field Summary

Public Constructor Summary

FieldNumber(String name)

Public Method Summary

FieldNumber
clone()
static FieldNumber
fromJson(JSONObject json)
double
double
NumberFormat
getNumberFormatForLocale(Locale locale)
Retrieves (possibly constructing) a NumberFormat configured for both the field constraints and the provided Locale.
double
getPrecision()
This returns the precision of the value allowed by this field.
String
double
boolean
boolean
boolean
boolean
void
setConstraints(double min, double max, double precision)
Sets the constraints on valid number values.
boolean
setFromString(String text)
Sets the value from a string.
void
setValue(double newValue)
Sets the number in this Field.

Inherited Method Summary

Constants

public static final double NO_CONSTRAINT

Constant Value: NaN

Fields

protected static final DecimalFormat INTEGER_DECIMAL_FORMAT

This formatter is used when precision is a multiple of 1.

Public Constructors

public FieldNumber (String name)

Parameters
name

Public Methods

public FieldNumber clone ()

public static FieldNumber fromJson (JSONObject json)

Parameters
json

public double getMaximumValue ()

Returns
  • The maximum allowed value for this field.

public double getMinimumValue ()

Returns
  • The minimum allowed value for this field.

public NumberFormat getNumberFormatForLocale (Locale locale)

Retrieves (possibly constructing) a NumberFormat configured for both the field constraints and the provided Locale.

Parameters
locale The locale to construct a number formatter for.
Returns
  • A NumberFormat configured for both the field constraints and the Locale.

public double getPrecision ()

This returns the precision of the value allowed by this field. The value must be a multiple of precision. Precision is usually expressed as a power of 10 (e.g., 1, 100, 0.01), though other useful examples might be 5, 20, or 25.

Returns
  • The precision allowed for the value.

public String getSerializedValue ()

Returns
  • The value serialized into a string.

public double getValue ()

Returns
  • The number the user has entered.

public boolean hasMaximum ()

Returns
  • True if there's a maximum constraint, false if the maximum is unbounded.

public boolean hasMinimum ()

Returns
  • True if there's a minimum constraint, false if the minimum is unbounded.

public boolean hasPrecision ()

Returns
  • True if there's a precision applied to the value, false otherwise.

public boolean isInteger ()

Returns
  • Whether the precision (and thus the value) is an integer.

public void setConstraints (double min, double max, double precision)

Sets the constraints on valid number values.

Changing the constraints may trigger a BlocklyEvent.ChangeEvent, even if the value does not change.

Parameters
min The minimum allowed value, inclusive.
max The maximum allowed value, inclusive.
precision The precision of allowed values. Valid values are multiples of this number, such as 1, 0.1, 100, or 0.125.

public boolean setFromString (String text)

Sets the value from a string. As long as the text can be parsed as a number, the value will be accepted. The actual value assigned might be modified to fit the min, max, and precision constraints.

Parameters
text The text value for this field.
Returns
  • True if the value parsed without error and the value has been updated.

public void setValue (double newValue)

Sets the number in this Field. The resulting value of this field may differ from newValue to adapt to the assigned min, max, and precision constraints.

Parameters
newValue The number to replace the field content with.