InternationalFormatter extends DefaultFormatter,
using an instance of java.text.Format to handle the
conversion to a String, and the conversion from a String.
If getAllowsInvalid() is false, this will ask the
Format to format the current text on every edit.
You can specify a minimum and maximum value by way of the
setMinimum and setMaximum methods. In order
for this to work the values returned from stringToValue must be
comparable to the min/max values by way of the Comparable
interface.
Be careful how you configure the Format and the
InternationalFormatter, as it is possible to create a
situation where certain values can not be input. Consider the date
format 'M/d/yy', an InternationalFormatter that is always
valid (setAllowsInvalid(false)), is in overwrite mode
(setOverwriteMode(true)) and the date 7/1/99. In this
case the user will not be able to enter a two digit month or day of
month. To avoid this, the format should be 'MM/dd/yy'.
If InternationalFormatter is configured to only allow valid
values (setAllowsInvalid(false)), every valid edit will result
in the text of the JFormattedTextField being completely reset
from the Format.
The cursor position will also be adjusted as literal characters are
added/removed from the resulting String.
InternationalFormatter's behavior of
stringToValue is slightly different than that of
DefaultTextFormatter, it does the following:
parseObject is invoked on the Format
specified by setFormat
setValueClass),
supers implementation is invoked to convert the value returned
from parseObject to the appropriate class.
ParseException has not been thrown, and the value
is outside the min/max a ParseException is thrown.
InternationalFormatter implements stringToValue
in this manner so that you can specify an alternate Class than
Format may return.Warning
Serialized objects of this class will not be compatible with
future Swing releases. The current serialization support is
appropriate for short term storage or RMI between applications running
the same version of Swing. As of 1.4, support for long term storage
of all JavaBeans
has been added to the java.beans package.
Please see java..
java.text.Format , java.lang.Comparable
| Modifier and Type | Class and Description |
|---|---|
| pack-priv static class | InternationalFormatter.
As InternationalFormatter replaces the complete text on every edit, ExtendedReplaceHolder keeps track of the offset and length passed into canReplace. |
| private class | InternationalFormatter.
IncrementAction is used to increment the value by a certain amount. |
| Modifier and Type | Field and Description |
|---|---|
| private static final Format. | EMPTY_FIELD_ARRAY
Used by |
| private Format | format
Object used to handle the conversion. |
| private transient boolean | ignoreDocumentMutate
If true, DocumentFilter methods are unconditionally allowed, and no checking is done on their values. |
| private transient AttributedCharacterIterator | iterator
Used to iterate over characters. |
| private transient BitSet | literalMask
A bit is set for every index identified in the AttributedCharacterIterator that is not considered decoration. |
| private Comparable | max
Can be used to impose a maximum value. |
| private Comparable | min
Can be used to impose a minimum value. |
| private transient String | string
Current value being displayed. |
| private transient boolean | validMask
True if the Format was able to convert the value to a String and back. |
| Access | Constructor and Description |
|---|---|
| public | |
| public | InternationalFormatter(Format
Format instance used for converting from/to Strings format)Creates an |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv Object | adjustValue(Object value, Map<?, ?> attributes, Object field, int direction)
Subclasses supporting incrementing must override this to handle the actual incrementing. |
| pack-priv boolean | |
| pack-priv boolean | canReplace(DefaultFormatter.
Overrides javax. Overridden in an attempt to honor the literals. |
| public Object | Returns: copy of the DefaultFormatterOverrides javax. Creates a copy of the DefaultFormatter. |
| protected Action[] | getActions()
Overrides javax. If |
| pack-priv Object | getAdjustField(int start, Map<?, ?> attributes)
Returns the field that will be adjusted by adjustValue. |
| pack-priv Map | |
| pack-priv int | getAttributeStart(AttributedCharacterIterator.
Returns the start of the first run that contains the attribute
|
| pack-priv char | |
| public Format. | Returns: Format.Field constants associated with the text at the given position.offset into text to be examined offset)Returns the |
| private int | getFieldTypeCountTo(Object f, int start)
Returns the number of occurrences of |
| public Format | Returns: Format instance used for converting from/to StringsReturns the format that dictates the legal values that can be edited and displayed. |
| pack-priv AttributedCharacterIterator | |
| pack-priv char | |
| pack-priv int | |
| public Comparable | |
| public Comparable | |
| private int | getNextNonliteralIndex(int index, int
Amount to increment looking for non-literal direction)Returns the index of the next non-literal character starting at index. |
| pack-priv DefaultFormatter. | getReplaceHolder(DocumentFilter.
Overrides javax. Overridden to return an instance of |
| pack-priv boolean | getSupportsIncrement()
Returns false, indicating InternationalFormatter does not allow incrementing of the value. |
| public void | install(JFormattedTextField
JFormattedTextField to format for, may be null indicating
uninstall from current JFormattedTextField. ftf)Overrides javax. Installs the |
| pack-priv boolean | |
| pack-priv boolean | |
| pack-priv boolean | isNavigatable(int offset)
Overrides javax. Returns true if the character at offset is navigable too. |
| pack-priv boolean | |
| pack-priv boolean | isValidValue(Object value, boolean
If false, and a ClassCastException is thrown in
comparing the values, the exception is consumed and
false is returned. wantsCCE)Returns true if |
| private void | readObject(ObjectInputStream s)
Subclassed to update the internal representation of the mask after the default read operation has completed. |
| pack-priv void | replace(DocumentFilter.
Overrides javax. Overridden to unconditionally allow the replace if ignoreDocumentMutate is true. |
| pack-priv boolean | replace(DefaultFormatter.
Overrides javax. When in !allowsInvalid mode the text is reset on every edit, thus supers implementation will position the cursor at the wrong position. |
| private void | |
| pack-priv void | |
| pack-priv void | |
| public void | |
| public void | setMaximum(Comparable<?>
Maximum legal value that can be input max)Sets the maximum permissible value. |
| public void | setMinimum(Comparable<?>
Minimum legal value that can be input minimum)Sets the minimum permissible value. |
| public Object | Returns: Object representation of textString to convertOverrides javax. Returns the |
| pack-priv Object | |
| pack-priv void | updateMask()
Updates the AttributedCharacterIterator by invoking
|
| private void | |
| pack-priv void | |
| pack-priv void | updateValue(Object value)
Overrides javax. Overridden to update the mask after invoking supers implementation. |
| public String | Returns: String representation of valueValue to convert value)Overrides javax. Returns a String representation of the Object |
| EMPTY_FIELD_ARRAY | back to summary |
|---|---|
| private static final Format. Used by | |
| format | back to summary |
|---|---|
| private Format format Object used to handle the conversion. | |
| ignoreDocumentMutate | back to summary |
|---|---|
| private transient boolean ignoreDocumentMutate If true, DocumentFilter methods are unconditionally allowed, and no checking is done on their values. This is used when incrementing/decrementing via the actions. | |
| iterator | back to summary |
|---|---|
| private transient AttributedCharacterIterator iterator Used to iterate over characters. | |
| literalMask | back to summary |
|---|---|
| private transient BitSet literalMask A bit is set for every index identified in the AttributedCharacterIterator that is not considered decoration. This should only be used if validMask is true. | |
| max | back to summary |
|---|---|
| private Comparable<?> max Can be used to impose a maximum value. | |
| min | back to summary |
|---|---|
| private Comparable<?> min Can be used to impose a minimum value. | |
| string | back to summary |
|---|---|
| private transient String string Current value being displayed. | |
| validMask | back to summary |
|---|---|
| private transient boolean validMask True if the Format was able to convert the value to a String and back. | |
| InternationalFormatter | back to summary |
|---|---|
| public InternationalFormatter() Creates an | |
| InternationalFormatter | back to summary |
|---|---|
| public InternationalFormatter(Format format) Creates an
| |
| adjustValue | back to summary |
|---|---|
| pack-priv Object adjustValue(Object value, Map<?, ?> attributes, Object field, int direction) throws BadLocationException, ParseException Subclasses supporting incrementing must override this to handle
the actual incrementing. | |
| canIncrement | back to summary |
|---|---|
| pack-priv boolean canIncrement(Object field, int cursorPosition) Returns true if | |
| canReplace | back to summary |
|---|---|
| pack-priv boolean canReplace(DefaultFormatter. Overrides javax. Overridden in an attempt to honor the literals. If we do not allow invalid values and are in overwrite mode, this
| |
| clone | back to summary |
|---|---|
| public Object clone() throws CloneNotSupportedException Overrides javax. Creates a copy of the DefaultFormatter.
| |
| getActions | back to summary |
|---|---|
| protected Action[] getActions() Overrides javax. If | |
| getAdjustField | back to summary |
|---|---|
| pack-priv Object getAdjustField(int start, Map<?, ?> attributes) Returns the field that will be adjusted by adjustValue. | |
| getAttributes | back to summary |
|---|---|
| pack-priv Map Returns a Set of the attribute identifiers at | |
| getAttributeStart | back to summary |
|---|---|
| pack-priv int getAttributeStart(AttributedCharacterIterator. Returns the start of the first run that contains the attribute
| |
| getBufferedChar | back to summary |
|---|---|
| pack-priv char getBufferedChar(int index) Returns the character from the mask that has been buffered
at | |
| getFields | back to summary |
|---|---|
| public Format. Returns the | |
| getFieldTypeCountTo | back to summary |
|---|---|
| private int getFieldTypeCountTo(Object f, int start) Returns the number of occurrences of | |
| getFormat | back to summary |
|---|---|
| public Format getFormat() Returns the format that dictates the legal values that can be edited and displayed.
| |
| getIterator | back to summary |
|---|---|
| pack-priv AttributedCharacterIterator getIterator() Returns the | |
| getLiteral | back to summary |
|---|---|
| pack-priv char getLiteral(int index) Returns the literal character at index. | |
| getLiteralCountTo | back to summary |
|---|---|
| pack-priv int getLiteralCountTo(int index) Returns the number of literal characters before | |
| getMaximum | back to summary |
|---|---|
| public Comparable Returns the maximum permissible value.
| |
| getMinimum | back to summary |
|---|---|
| public Comparable Returns the minimum permissible value.
| |
| getNextNonliteralIndex | back to summary |
|---|---|
| private int getNextNonliteralIndex(int index, int direction) Returns the index of the next non-literal character starting at index. If index is not a literal, it will be returned.
| |
| getReplaceHolder | back to summary |
|---|---|
| pack-priv DefaultFormatter. Overrides javax. Overridden to return an instance of | |
| getSupportsIncrement | back to summary |
|---|---|
| pack-priv boolean getSupportsIncrement() Returns false, indicating InternationalFormatter does not allow
incrementing of the value. Subclasses that wish to support
incrementing/decrementing the value should override this and
return true. Subclasses should also override
| |
| install | back to summary |
|---|---|
| public void install(JFormattedTextField ftf) Overrides javax. Installs the
Subclasses will typically only need to override this if they
wish to install additional listeners on the
If there is a
While this is a public method, this is typically only useful
for subclassers of
| |
| isLiteral | back to summary |
|---|---|
| pack-priv boolean isLiteral(int index) Returns true if the character at index is a literal, that is not editable. | |
| isLiteral | back to summary |
|---|---|
| pack-priv boolean isLiteral(Map<?, ?> attributes) Returns true if | |
| isNavigatable | back to summary |
|---|---|
| pack-priv boolean isNavigatable(int offset) Overrides javax. Returns true if the character at offset is navigable too. This
is implemented in terms of | |
| isValidMask | back to summary |
|---|---|
| pack-priv boolean isValidMask() Returns true if the current mask is valid. | |
| isValidValue | back to summary |
|---|---|
| pack-priv boolean isValidValue(Object value, boolean wantsCCE) Returns true if
| |
| readObject | back to summary |
|---|---|
| private void readObject(ObjectInputStream s) throws IOException, ClassNotFoundException Subclassed to update the internal representation of the mask after the default read operation has completed.
| |
| replace | back to summary |
|---|---|
| pack-priv void replace(DocumentFilter. Overrides javax. Overridden to unconditionally allow the replace if ignoreDocumentMutate is true. | |
| replace | back to summary |
|---|---|
| pack-priv boolean replace(DefaultFormatter. Overrides javax. When in !allowsInvalid mode the text is reset on every edit, thus
supers implementation will position the cursor at the wrong position.
As such, this invokes supers implementation and then invokes
| |
| repositionCursor | back to summary |
|---|---|
| private void repositionCursor(int startLiteralCount, int end, int direction) Repositions the cursor. | |
| resetValue | back to summary |
|---|---|
| pack-priv void resetValue(Object value) throws BadLocationException, ParseException Resets the value of the JFormattedTextField to be
| |
| selectField | back to summary |
|---|---|
| pack-priv void selectField(Object f, int count) Selects the fields identified by | |
| setFormat | back to summary |
|---|---|
| public void setFormat(Format format) Sets the format that dictates the legal values that can be edited and displayed.
| |
| setMaximum | back to summary |
|---|---|
| public void setMaximum(Comparable<?> max) Sets the maximum permissible value. If the
| |
| setMinimum | back to summary |
|---|---|
| public void setMinimum(Comparable<?> minimum) Sets the minimum permissible value. If the
| |
| stringToValue | back to summary |
|---|---|
| public Object stringToValue(String text) throws ParseException Overrides javax. Returns the
| |
| stringToValue | back to summary |
|---|---|
| pack-priv Object stringToValue(String text, Format f) throws ParseException Invokes | |
| updateMask | back to summary |
|---|---|
| pack-priv void updateMask() Updates the AttributedCharacterIterator by invoking
| |
| updateMask | back to summary |
|---|---|
| private void updateMask(AttributedCharacterIterator iterator) Updates the internal bitset from | |
| updateMaskIfNecessary | back to summary |
|---|---|
| pack-priv void updateMaskIfNecessary() Updates the AttributedCharacterIterator and bitset, if necessary. | |
| updateValue | back to summary |
|---|---|
| pack-priv void updateValue(Object value) Overrides javax. Overridden to update the mask after invoking supers implementation. | |
| valueToString | back to summary |
|---|---|
| public String valueToString(Object value) throws ParseException Overrides javax. Returns a String representation of the Object
| |
| Modifier and Type | Field and Description |
|---|---|
| pack-priv int | endOffset
Offset of the insert/remove. |
| pack-priv int | endTextLength
Length of the text. |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| pack-priv void | resetFromValue(InternationalFormatter formatter)
Resets the region to delete to be the complete document and the text from invoking valueToString on the current value. |
| endOffset | back to summary |
|---|---|
| pack-priv int endOffset Offset of the insert/remove. This may differ from offset in that if !allowsInvalid the text is replaced on every edit. | |
| endTextLength | back to summary |
|---|---|
| pack-priv int endTextLength Length of the text. This may differ from text.length in that if !allowsInvalid the text is replaced on every edit. | |
| ExtendedReplaceHolder | back to summary |
|---|---|
| pack-priv ExtendedReplaceHolder() | |
| resetFromValue | back to summary |
|---|---|
| pack-priv void resetFromValue(InternationalFormatter formatter) Resets the region to delete to be the complete document and the text from invoking valueToString on the current value. | |
adjustValue to handle the actual
incrementing of the value.
| Modifier and Type | Field and Description |
|---|---|
| private int |
| Access | Constructor and Description |
|---|---|
| pack-priv |
| Modifier and Type | Method and Description |
|---|---|
| public void | actionPerformed(ActionEvent ae)
Implements java. Invoked when an action occurs. |
| direction | back to summary |
|---|---|
| private int direction | |
| IncrementAction | back to summary |
|---|---|
| pack-priv IncrementAction(String name, int direction) | |
| actionPerformed | back to summary |
|---|---|
| public void actionPerformed(ActionEvent ae) Implements java. Doc from java. Invoked when an action occurs. | |