20.5 The InternationalFormatter Class


InternationalFormatter is a subclass of DefaultFormatter that delegates most of its work to an object of type java.text.Format (which is always a subclass since java.text.Format itself is abstract). Many of these subclasses provide internationalization support through awareness of locales, hence the name InternationalFormatter.

InternationalFormatter is rarely used directly. It is a repository for the common functionality of its two subclasses, DateFormatter and NumberFormatter.

20.5.1 Properties

Table 20-6 shows the properties defined by InternationalFormatter.

Table 20-6. InternationalFormatter properties

Property

Data type

get

is

set

Default value

format

java.text.Format

·

 

·

null

minimum

Comparable

·

 

·

null

maximum

Comparable

·

 

·

null

overwriteModeo

boolean

·

 

·

false

ooverridden

See also properties from the DefaultFormatter class (Table 20-3).

The format property is key to InternationalFormatter and is used by the valueToString( ) and stringToValue( ) methods to translate between the field's Object and String representations. It can be set in the constructor or via the setFormat( ) method.

The minimum and maximum properties can constrain the value of the field. If minimum is not null, value may not be less than minimum. If maximum is not null, value may not be greater than maximum. These may be of any type that implements the Comparable interface. (Provided it hasn't already been set, calling setMinimum( ) or setMaximum( ) also sets the formatter's valueClass property.)

InternationalFormatter overrides the overwriteMode property, setting it to false.

20.5.2 Constructors

public InternationalFormatter( )

Create a new InternationalFormatter with no Format.

public InternationalFormatter(java.text.Format format)

Create a new InternationalFormatter with the specified Format.

20.5.3 Public Methods

public Object stringToValue(String text) throws java.text.ParseException

This method is overridden to throw a ParseException if the value is less than minimum (if minimum is not null) or more than maximum (if maximum is not null). Otherwise, it delegates to getFormat( ).parseObject(text), allowing any ParseEx-ception to propagate. The valueClass property is honored.

public String valueToString(Object value) throws java.text.ParseException

This method delegates to getFormat( ).format(value).

public Format.Field[] getFields(int offset)

Return the Format.Field constants that correspond to the given offset of the field's text, or an empty array if there is no text. This can be used to determine the subfield at that offset (for example, DAY_OF_WEEK in a DateFormat).



Java Swing
Graphic Java 2: Mastering the Jfc, By Geary, 3Rd Edition, Volume 2: Swing
ISBN: 0130796670
EAN: 2147483647
Year: 2001
Pages: 289
Authors: David Geary

flylib.com © 2008-2017.
If you may any questions please contact us: flylib@qtcs.net