org.jhotdraw.text
Class JavaNumberFormatter
- java.lang.Object
-
- javax.swing.JFormattedTextField.AbstractFormatter
-
- javax.swing.text.DefaultFormatter
-
- org.jhotdraw.text.JavaNumberFormatter
-
- All Implemented Interfaces:
- java.io.Serializable, java.lang.Cloneable
public class JavaNumberFormatter extends javax.swing.text.DefaultFormatterScaledNumberFormatteris used to format numbers written in the Java programming syntax.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor and Description JavaNumberFormatter()Creates aNumberFormatterwith the a defaultNumberFormatinstance obtained fromNumberFormat.getNumberInstance().JavaNumberFormatter(double min, double max, double multiplier)Creates a NumberFormatter with the specified Format instance.JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue)Creates a NumberFormatter with the specified Format instance.JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue, java.lang.String unit)Creates a NumberFormatter with the specified Format instance.
-
Method Summary
All Methods Static Methods Instance Methods Concrete Methods Modifier and Type Method and Description static javax.swing.JFormattedTextField.AbstractFormatterFactorycreateFormatterFactory(double min, double max, double multiplier)Convenience method for creating a formatter factory with aScalableNumberFormatterand a Java-style DecimalFormat.static javax.swing.JFormattedTextField.AbstractFormatterFactorycreateFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue)Convenience method for creating a formatter factory with aScalableNumberFormatterand a Java-style DecimalFormat.static javax.swing.JFormattedTextField.AbstractFormatterFactorycreateFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue, java.lang.String unit)Convenience method for creating a formatter factory with aScalableNumberFormatterand a Java-style DecimalFormat.booleangetAllowsNullValue()Returns true if null values are allowed.java.lang.ComparablegetMaximum()Returns the maximum permissible value.intgetMaximumFractionDigits()Gets the maximum number of digits allowed in the fraction portion of a number.intgetMaximumIntegerDigits()Gets the maximum number of digits allowed in the integer portion of a number.java.lang.ComparablegetMinimum()Returns the minimum permissible value.intgetMinimumFractionDigits()Returns true if null values are allowed.intgetMinimumIntegerDigits()Gets the minimum number of digits allowed in the integer portion of a number.intgetMinimumNegativeExponent()Gets the minimum negative exponent value for scientific notation.intgetMinimumPositiveExponent()Gets the minimum positive exponent value for scientific notation.doublegetMultiplier()Gets the multiplier for use in percent, per mille, and similar formats.java.lang.StringgetUnit()If non-null the unit string is appended to the value.booleanisUsesScientificNotation()Returns true if scientific notation is used.voidsetAllowsNullValue(boolean newValue)Allows/Disallows null values.voidsetMaximum(java.lang.Comparable max)Sets the maximum permissible value.voidsetMaximumFractionDigits(int newValue)Sets the maximum number of digits allowed in the fraction portion of a number.voidsetMaximumIntegerDigits(int newValue)Sets the maximum number of digits allowed in the integer portion of a number.voidsetMinimum(java.lang.Comparable minimum)Sets the minimum permissible value.voidsetMinimumFractionDigits(int newValue)Specifies whether ".0" is appended to double and float values.voidsetMinimumIntegerDigits(int newValue)Sets the minimum number of digits allowed in the integer portion of a number.voidsetMinimumNegativeExponent(int newValue)Sets the minimum negative exponent value for scientific notation.voidsetMinimumPositiveExponent(int newValue)Sets the minimum positive exponent value for scientific notation.voidsetMultiplier(double newValue)Sets the multiplier for use in percent, per mille, and similar formats.voidsetUnit(java.lang.String value)If non-null the unit string is appended to the value.voidsetUsesScientificNotation(boolean newValue)Sets whether scientific notation is used.java.lang.ObjectstringToValue(java.lang.String text)Returns theObjectrepresentation of theStringtext.java.lang.StringvalueToString(java.lang.Object value)Returns a String representation of the Objectvalue.
-
-
-
Constructor Detail
-
JavaNumberFormatter
public JavaNumberFormatter()
Creates aNumberFormatterwith the a defaultNumberFormatinstance obtained fromNumberFormat.getNumberInstance().
-
JavaNumberFormatter
public JavaNumberFormatter(double min, double max, double multiplier)Creates a NumberFormatter with the specified Format instance.
-
JavaNumberFormatter
public JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue)Creates a NumberFormatter with the specified Format instance.
-
JavaNumberFormatter
public JavaNumberFormatter(double min, double max, double multiplier, boolean allowsNullValue, @Nullable java.lang.String unit)Creates a NumberFormatter with the specified Format instance.
-
-
Method Detail
-
setMinimum
public void setMinimum(java.lang.Comparable minimum)
Sets the minimum permissible value. If thevalueClasshas not been specified, andminimumis non null, thevalueClasswill be set to that of the class ofminimum.- Parameters:
minimum- Minimum legal value that can be input- See Also:
DefaultFormatter.setValueClass(java.lang.Class<?>)
-
getMinimum
public java.lang.Comparable getMinimum()
Returns the minimum permissible value.- Returns:
- Minimum legal value that can be input
-
setMaximum
public void setMaximum(java.lang.Comparable max)
Sets the maximum permissible value. If thevalueClasshas not been specified, andmaxis non null, thevalueClasswill be set to that of the class ofmax.- Parameters:
max- Maximum legal value that can be input- See Also:
DefaultFormatter.setValueClass(java.lang.Class<?>)
-
getMaximum
public java.lang.Comparable getMaximum()
Returns the maximum permissible value.- Returns:
- Maximum legal value that can be input
-
setMultiplier
public void setMultiplier(double newValue)
Sets the multiplier for use in percent, per mille, and similar formats.
-
getMultiplier
public double getMultiplier()
Gets the multiplier for use in percent, per mille, and similar formats.
-
setAllowsNullValue
public void setAllowsNullValue(boolean newValue)
Allows/Disallows null values.- Parameters:
newValue-
-
getAllowsNullValue
public boolean getAllowsNullValue()
Returns true if null values are allowed.
-
setMinimumFractionDigits
public void setMinimumFractionDigits(int newValue)
Specifies whether ".0" is appended to double and float values. By default this is true.- Parameters:
newValue-
-
getMinimumFractionDigits
public int getMinimumFractionDigits()
Returns true if null values are allowed.
-
valueToString
public java.lang.String valueToString(java.lang.Object value) throws java.text.ParseExceptionReturns a String representation of the Objectvalue. This invokesformaton the currentFormat.- Overrides:
valueToStringin classjavax.swing.text.DefaultFormatter- Parameters:
value- Value to convert- Returns:
- String representation of value
- Throws:
java.text.ParseException- if there is an error in the conversion
-
stringToValue
public java.lang.Object stringToValue(java.lang.String text) throws java.text.ParseExceptionReturns theObjectrepresentation of theStringtext.- Overrides:
stringToValuein classjavax.swing.text.DefaultFormatter- Parameters:
text-Stringto convert- Returns:
Objectrepresentation of text- Throws:
java.text.ParseException- if there is an error in the conversion
-
setUnit
public void setUnit(@Nullable java.lang.String value)
If non-null the unit string is appended to the value.
-
getUnit
@Nullable public java.lang.String getUnit()
If non-null the unit string is appended to the value.
-
getMinimumIntegerDigits
public int getMinimumIntegerDigits()
Gets the minimum number of digits allowed in the integer portion of a number.
-
setMinimumIntegerDigits
public void setMinimumIntegerDigits(int newValue)
Sets the minimum number of digits allowed in the integer portion of a number.
-
getMaximumIntegerDigits
public int getMaximumIntegerDigits()
Gets the maximum number of digits allowed in the integer portion of a number.
-
setMaximumIntegerDigits
public void setMaximumIntegerDigits(int newValue)
Sets the maximum number of digits allowed in the integer portion of a number.
-
getMaximumFractionDigits
public int getMaximumFractionDigits()
Gets the maximum number of digits allowed in the fraction portion of a number.
-
setMaximumFractionDigits
public void setMaximumFractionDigits(int newValue)
Sets the maximum number of digits allowed in the fraction portion of a number.
-
getMinimumNegativeExponent
public int getMinimumNegativeExponent()
Gets the minimum negative exponent value for scientific notation.
-
setMinimumNegativeExponent
public void setMinimumNegativeExponent(int newValue)
Sets the minimum negative exponent value for scientific notation.
-
getMinimumPositiveExponent
public int getMinimumPositiveExponent()
Gets the minimum positive exponent value for scientific notation.
-
setMinimumPositiveExponent
public void setMinimumPositiveExponent(int newValue)
Sets the minimum positive exponent value for scientific notation.
-
isUsesScientificNotation
public boolean isUsesScientificNotation()
Returns true if scientific notation is used.
-
setUsesScientificNotation
public void setUsesScientificNotation(boolean newValue)
Sets whether scientific notation is used.
-
createFormatterFactory
public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier)Convenience method for creating a formatter factory with aScalableNumberFormatterand a Java-style DecimalFormat. Doesn't allow null values and doesn't append ".0" to double and float values.
-
createFormatterFactory
public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue)Convenience method for creating a formatter factory with aScalableNumberFormatterand a Java-style DecimalFormat.
-
createFormatterFactory
public static javax.swing.JFormattedTextField.AbstractFormatterFactory createFormatterFactory(double min, double max, double multiplier, boolean allowsNullValue, @Nullable java.lang.String unit)Convenience method for creating a formatter factory with aScalableNumberFormatterand a Java-style DecimalFormat.
-
-
DataMelt 3.0 © DataMelt by jWork.ORG