Package org.jdesktop.swingx.text
Class StrictNumberFormatter
- java.lang.Object
-
- javax.swing.JFormattedTextField.AbstractFormatter
-
- javax.swing.text.DefaultFormatter
-
- javax.swing.text.InternationalFormatter
-
- javax.swing.text.NumberFormatter
-
- org.jdesktop.swingx.text.StrictNumberFormatter
-
- All Implemented Interfaces:
java.io.Serializable,java.lang.Cloneable
public class StrictNumberFormatter extends javax.swing.text.NumberFormatterExperiment to work around Issue #1183-swingx: NumberEditorExt throws exception on getCellValue. Remaining issue: no visual error feedback if the expected number type exceeds its range.- See Also:
- Serialized Form
-
-
Constructor Summary
Constructors Constructor Description StrictNumberFormatter(java.text.NumberFormat format)
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description private java.lang.ObjectconvertValueToValueClass(java.lang.Object value, java.lang.Class<?> valueClass)Converts the passed in value to the passed in class.private java.lang.Comparable<java.math.BigDecimal>getMaximumAsBig()private java.lang.Comparable<java.math.BigDecimal>getMinimumAsBig()private java.lang.ObjectgetParsedValue(java.lang.String text, java.text.Format f)InvokesparseObjectonf, returning its value.private booleanisValueInRange(java.lang.Object orgValue, boolean wantsCCE)Returns true ifvalueis between the min/max.voidsetMaximum(java.lang.Comparable max)voidsetMinimum(java.lang.Comparable minimum)voidsetValueClass(java.lang.Class<?> valueClass)java.lang.ObjectstringToValue(java.lang.String text)Returns theObjectrepresentation of theStringtext, may be null.private voidupdateMinMax()-
Methods inherited from class javax.swing.text.InternationalFormatter
clone, getActions, getFields, getFormat, getMaximum, getMinimum, install, valueToString
-
Methods inherited from class javax.swing.text.DefaultFormatter
getAllowsInvalid, getCommitsOnValidEdit, getDocumentFilter, getNavigationFilter, getOverwriteMode, getValueClass, setAllowsInvalid, setCommitsOnValidEdit, setOverwriteMode
-
-
-
-
Method Detail
-
setValueClass
public void setValueClass(java.lang.Class<?> valueClass)
Overridden to automatically set the minimum/maximum to the boundaries of the Number type if it corresponds to a raw type, or null if not.
- Overrides:
setValueClassin classjavax.swing.text.DefaultFormatter
-
updateMinMax
private void updateMinMax()
-
setMaximum
public void setMaximum(java.lang.Comparable max)
- Overrides:
setMaximumin classjavax.swing.text.InternationalFormatter
-
setMinimum
public void setMinimum(java.lang.Comparable minimum)
- Overrides:
setMinimumin classjavax.swing.text.InternationalFormatter
-
stringToValue
public java.lang.Object stringToValue(java.lang.String text) throws java.text.ParseExceptionReturns theObjectrepresentation of theStringtext, may be null.- Overrides:
stringToValuein classjavax.swing.text.InternationalFormatter- Parameters:
text-Stringto convert- Returns:
Objectrepresentation of text- Throws:
java.text.ParseException- if there is an error in the conversion
-
convertValueToValueClass
private java.lang.Object convertValueToValueClass(java.lang.Object value, java.lang.Class<?> valueClass)Converts the passed in value to the passed in class. This only works ifvalueClassis one ofInteger,Long,Float,Double,ByteorShortandvalueis an instanceofNumber.
-
getParsedValue
private java.lang.Object getParsedValue(java.lang.String text, java.text.Format f) throws java.text.ParseExceptionInvokesparseObjectonf, returning its value.- Throws:
java.text.ParseException
-
isValueInRange
private boolean isValueInRange(java.lang.Object orgValue, boolean wantsCCE)Returns true ifvalueis between the min/max.- Parameters:
wantsCCE- If false, and a ClassCastException is thrown in comparing the values, the exception is consumed and false is returned.
-
getMinimumAsBig
private java.lang.Comparable<java.math.BigDecimal> getMinimumAsBig()
-
getMaximumAsBig
private java.lang.Comparable<java.math.BigDecimal> getMaximumAsBig()
-
-