javax.swing

Class JFormattedTextField.AbstractFormatter

public abstract static class JFormattedTextField.AbstractFormatter extends Object implements Serializable

An abstract base implementation for a formatter that can be used by a JTextField. A formatter can display a specific type of object and may provide a way to edit this value.
Constructor Summary
AbstractFormatter()
Method Summary
protected Objectclone()
Clones the AbstractFormatter and removes the association to any particular JFormattedTextField.
protected Action[]getActions()
Returns a custom set of Actions that this formatter supports.
protected DocumentFiltergetDocumentFilter()
Gets the DocumentFilter for this formatter.
protected JFormattedTextFieldgetFormattedTextField()
Returns the JFormattedTextField on which this formatter is currently installed.
protected NavigationFiltergetNavigationFilter()
Gets the NavigationFilter for this formatter.
voidinstall(JFormattedTextField textField)
Installs this formatter on the specified JFormattedTextField.
protected voidinvalidEdit()
Invoke this method when invalid values are entered.
protected voidsetEditValid(boolean valid)
This method updates the editValid property of JFormattedTextField.
abstract ObjectstringToValue(String text)
Parses text to return a corresponding Object.
voiduninstall()
Clears the state installed on the JFormattedTextField by the formatter.
abstract StringvalueToString(Object value)
Returns a String to be displayed, based on the Object value.

Constructor Detail

AbstractFormatter

public AbstractFormatter()

Method Detail

clone

protected Object clone()
Clones the AbstractFormatter and removes the association to any particular JFormattedTextField.

Returns: a clone of this formatter with no association to any particular JFormattedTextField

Throws: CloneNotSupportedException if the Object's class doesn't support the {@link Cloneable} interface

getActions

protected Action[] getActions()
Returns a custom set of Actions that this formatter supports. Should be subclassed by formatters that have a custom set of Actions.

Returns: null. Should be subclassed by formatters that want to install custom Actions on the JFormattedTextField.

getDocumentFilter

protected DocumentFilter getDocumentFilter()
Gets the DocumentFilter for this formatter. Should be subclassed by formatters wishing to install a filter that oversees Document mutations.

Returns: null. Should be subclassed by formatters that want to restrict Document mutations.

getFormattedTextField

protected JFormattedTextField getFormattedTextField()
Returns the JFormattedTextField on which this formatter is currently installed.

Returns: the JFormattedTextField on which this formatter is currently installed

getNavigationFilter

protected NavigationFilter getNavigationFilter()
Gets the NavigationFilter for this formatter. Should be subclassed by formatters (such as {@link DefaultFormatter}) that wish to restrict where the cursor can be placed within the text field.

Returns: null. Subclassed by formatters that want to restrict cursor location within the JFormattedTextField.

install

public void install(JFormattedTextField textField)
Installs this formatter on the specified JFormattedTextField. This converts the current value to a displayable String and displays it, and installs formatter specific Actions from getActions. It also installs a DocumentFilter and NavigationFilter on the JFormattedTextField.

If there is a ParseException this sets the text to an empty String and marks the text field in an invalid state.

Parameters: textField the JFormattedTextField on which to install this formatter

invalidEdit

protected void invalidEdit()
Invoke this method when invalid values are entered. This forwards the call to the JFormattedTextField.

setEditValid

protected void setEditValid(boolean valid)
This method updates the editValid property of JFormattedTextField.

Parameters: valid the new state for the editValid property

stringToValue

public abstract Object stringToValue(String text)
Parses text to return a corresponding Object.

Parameters: text the String to parse

Returns: an Object that text represented

Throws: ParseException if there is an error in the conversion

uninstall

public void uninstall()
Clears the state installed on the JFormattedTextField by the formatter. This resets the DocumentFilter, NavigationFilter, and any additional Actions (returned by getActions()).

valueToString

public abstract String valueToString(Object value)
Returns a String to be displayed, based on the Object value.

Parameters: value the Object from which to generate a String

Returns: a String to be displayed

Throws: ParseException if there is an error in the conversion