JFormattedTextField.AbstractFormatter (Java 2 Platform SE 5.0) (original) (raw)
javax.swing
Class JFormattedTextField.AbstractFormatter
java.lang.Object
javax.swing.JFormattedTextField.AbstractFormatter
All Implemented Interfaces:
Direct Known Subclasses:
Enclosing class:
public abstract static class JFormattedTextField.AbstractFormatter
extends Object
implements Serializable
Instances of AbstractFormatter
are used byJFormattedTextField
to handle the conversion both from an Object to a String, and back from a String to an Object.AbstractFormatter
s can also enfore editing policies, or navigation policies, or manipulate theJFormattedTextField
in any way it sees fit to enforce the desired policy.
An AbstractFormatter
can only be active in one JFormattedTextField
at a time.JFormattedTextField
invokesinstall
when it is ready to use it followed by uninstall
when done. Subclasses that wish to install additional state should overrideinstall
and message super appropriately.
Subclasses must override the conversion methodsstringToValue
and valueToString
. Optionally they can override getActions
,getNavigationFilter
and getDocumentFilter
to restrict the JFormattedTextField
in a particular way.
Subclasses that allow the JFormattedTextField
to be in a temporarily invalid state should invoke setEditValid
at the appropriate times.
Constructor Summary |
---|
JFormattedTextField.AbstractFormatter() |
Method Summary | |
---|---|
protected Object | clone() Clones the AbstractFormatter. |
protected Action[] | getActions() Subclass and override if you wish to provide a custom set ofActions. |
protected DocumentFilter | getDocumentFilter() Subclass and override if you wish to provide a DocumentFilter to restrict what can be input. |
protected JFormattedTextField | getFormattedTextField() Returns the current JFormattedTextField theAbstractFormatter is installed on. |
protected NavigationFilter | getNavigationFilter() Subclass and override if you wish to provide a filter to restrict where the user can navigate to. |
void | install(JFormattedTextField ftf) Installs the AbstractFormatter onto a particularJFormattedTextField. |
protected void | invalidEdit() This should be invoked when the user types an invalid character. |
protected void | setEditValid(boolean valid) Invoke this to update the editValid property of theJFormattedTextField. |
abstract Object | stringToValue(String text) Parses text returning an arbitrary Object. |
void | uninstall() Uninstalls any state the AbstractFormatter may have installed on the JFormattedTextField. |
abstract String | valueToString(Object value) Returns the string value to display for value. |
Methods inherited from class java.lang.Object |
---|
equals, finalize, getClass, hashCode, notify, notifyAll, toString, wait, wait, [wait](../../java/lang/Object.html#wait%28long, int%29) |
Constructor Detail |
---|
JFormattedTextField.AbstractFormatter
public JFormattedTextField.AbstractFormatter()
Method Detail |
---|
install
public void install(JFormattedTextField ftf)
Installs the AbstractFormatter
onto a particularJFormattedTextField
. This will invoke valueToString
to convert the current value from the JFormattedTextField
to a String. This will then install the Action
s fromgetActions
, the DocumentFilter
returned from getDocumentFilter
and theNavigationFilter
returned fromgetNavigationFilter
onto theJFormattedTextField
.
Subclasses will typically only need to override this if they wish to install additional listeners on theJFormattedTextField
.
If there is a ParseException
in converting the current value to a String, this will set the text to an empty String, and mark the JFormattedTextField
as being in an invalid state.
While this is a public method, this is typically only useful for subclassers of JFormattedTextField
.JFormattedTextField
will invoke this method at the appropriate times when the value changes, or its internal state changes. You will only need to invoke this yourself if you are subclassing JFormattedTextField
and installing/uninstalling AbstractFormatter
at a different time than JFormattedTextField
does.
Parameters:
ftf
- JFormattedTextField to format for, may be null indicating uninstall from current JFormattedTextField.
uninstall
public void uninstall()
Uninstalls any state the AbstractFormatter
may have installed on the JFormattedTextField
. This resets theDocumentFilter
, NavigationFilter
and additional Action
s installed on theJFormattedTextField
.
stringToValue
public abstract Object stringToValue(String text) throws ParseException
Parses text
returning an arbitrary Object. Some formatters may return null.
Parameters:
text
- String to convert
Returns:
Object representation of text
Throws:
[ParseException](../../java/text/ParseException.html "class in java.text")
- if there is an error in the conversion
valueToString
public abstract String valueToString(Object value) throws ParseException
Returns the string value to display for value
.
Parameters:
value
- Value to convert
Returns:
String representation of value
Throws:
[ParseException](../../java/text/ParseException.html "class in java.text")
- if there is an error in the conversion
getFormattedTextField
protected JFormattedTextField getFormattedTextField()
Returns the current JFormattedTextField
theAbstractFormatter
is installed on.
Returns:
JFormattedTextField formatting for.
invalidEdit
protected void invalidEdit()
This should be invoked when the user types an invalid character. This forwards the call to the current JFormattedTextField.
setEditValid
protected void setEditValid(boolean valid)
Invoke this to update the editValid
property of theJFormattedTextField
. If you an enforce a policy such that the JFormattedTextField
is always in a valid state, you will never need to invoke this.
Parameters:
valid
- Valid state of the JFormattedTextField
getActions
protected Action[] getActions()
Subclass and override if you wish to provide a custom set ofAction
s. install
will install these on the JFormattedTextField
's ActionMap
.
Returns:
Array of Actions to install on JFormattedTextField
getDocumentFilter
protected DocumentFilter getDocumentFilter()
Subclass and override if you wish to provide a DocumentFilter
to restrict what can be input.install
will install the returned value onto the JFormattedTextField
.
Returns:
DocumentFilter to restrict edits
getNavigationFilter
protected NavigationFilter getNavigationFilter()
Subclass and override if you wish to provide a filter to restrict where the user can navigate to.install
will install the returned value onto the JFormattedTextField
.
Returns:
NavigationFilter to restrict navigation
clone
protected Object clone() throws CloneNotSupportedException
Clones the AbstractFormatter
. The returned instance is not associated with a JFormattedTextField
.
Overrides:
[clone](../../java/lang/Object.html#clone%28%29)
in class [Object](../../java/lang/Object.html "class in java.lang")
Returns:
Copy of the AbstractFormatter
Throws:
[CloneNotSupportedException](../../java/lang/CloneNotSupportedException.html "class in java.lang")
- if the object's class does not support the Cloneable
interface. Subclasses that override the clone
method can also throw this exception to indicate that an instance cannot be cloned.
See Also:
Submit a bug or feature
For further API reference and developer documentation, see Java 2 SDK SE Developer Documentation. That documentation contains more detailed, developer-targeted descriptions, with conceptual overviews, definitions of terms, workarounds, and working code examples.
Copyright © 2004, 2010 Oracle and/or its affiliates. All rights reserved. Use is subject to license terms. Also see the documentation redistribution policy.