javax.swing
Class JFormattedTextField.AbstractFormatter

java.lang.Object sample code for java.lang.Object definition code for java.lang.Object 
  extended by javax.swing.JFormattedTextField.AbstractFormatter
All Implemented Interfaces:
Serializable sample code for java.io.Serializable definition code for java.io.Serializable
Direct Known Subclasses:
DefaultFormatter sample code for javax.swing.text.DefaultFormatter definition code for javax.swing.text.DefaultFormatter
Enclosing class:
JFormattedTextField sample code for javax.swing.JFormattedTextField definition code for javax.swing.JFormattedTextField

public abstract static class JFormattedTextField.AbstractFormatter
extends Object sample code for java.lang.Object definition code for java.lang.Object
implements Serializable sample code for java.io.Serializable definition code for java.io.Serializable

Instances of AbstractFormatter are used by JFormattedTextField to handle the conversion both from an Object to a String, and back from a String to an Object. AbstractFormatters can also enfore editing policies, or navigation policies, or manipulate the JFormattedTextField in any way it sees fit to enforce the desired policy.

An AbstractFormatter can only be active in one JFormattedTextField at a time. JFormattedTextField invokes install when it is ready to use it followed by uninstall when done. Subclasses that wish to install additional state should override install and message super appropriately.

Subclasses must override the conversion methods stringToValue 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.

See Also:
Serialized Form

Constructor Summary
JFormattedTextField.AbstractFormatter sample code for javax.swing.JFormattedTextField.AbstractFormatter.JFormattedTextField.AbstractFormatter() definition code for javax.swing.JFormattedTextField.AbstractFormatter.JFormattedTextField.AbstractFormatter() ()
           
 
Method Summary
protected  Object sample code for java.lang.Object definition code for java.lang.Object clone sample code for javax.swing.JFormattedTextField.AbstractFormatter.clone() definition code for javax.swing.JFormattedTextField.AbstractFormatter.clone() ()
          Clones the AbstractFormatter.
protected  Action sample code for javax.swing.Action definition code for javax.swing.Action [] getActions sample code for javax.swing.JFormattedTextField.AbstractFormatter.getActions() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getActions() ()
          Subclass and override if you wish to provide a custom set of Actions.
protected  DocumentFilter sample code for javax.swing.text.DocumentFilter definition code for javax.swing.text.DocumentFilter getDocumentFilter sample code for javax.swing.JFormattedTextField.AbstractFormatter.getDocumentFilter() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getDocumentFilter() ()
          Subclass and override if you wish to provide a DocumentFilter to restrict what can be input.
protected  JFormattedTextField sample code for javax.swing.JFormattedTextField definition code for javax.swing.JFormattedTextField getFormattedTextField sample code for javax.swing.JFormattedTextField.AbstractFormatter.getFormattedTextField() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getFormattedTextField() ()
          Returns the current JFormattedTextField the AbstractFormatter is installed on.
protected  NavigationFilter sample code for javax.swing.text.NavigationFilter definition code for javax.swing.text.NavigationFilter getNavigationFilter sample code for javax.swing.JFormattedTextField.AbstractFormatter.getNavigationFilter() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getNavigationFilter() ()
          Subclass and override if you wish to provide a filter to restrict where the user can navigate to.
 void install sample code for javax.swing.JFormattedTextField.AbstractFormatter.install(javax.swing.JFormattedTextField) definition code for javax.swing.JFormattedTextField.AbstractFormatter.install(javax.swing.JFormattedTextField) (JFormattedTextField sample code for javax.swing.JFormattedTextField definition code for javax.swing.JFormattedTextField  ftf)
          Installs the AbstractFormatter onto a particular JFormattedTextField.
protected  void invalidEdit sample code for javax.swing.JFormattedTextField.AbstractFormatter.invalidEdit() definition code for javax.swing.JFormattedTextField.AbstractFormatter.invalidEdit() ()
          This should be invoked when the user types an invalid character.
protected  void setEditValid sample code for javax.swing.JFormattedTextField.AbstractFormatter.setEditValid(boolean) definition code for javax.swing.JFormattedTextField.AbstractFormatter.setEditValid(boolean) (boolean valid)
          Invoke this to update the editValid property of the JFormattedTextField.
abstract  Object sample code for java.lang.Object definition code for java.lang.Object stringToValue sample code for javax.swing.JFormattedTextField.AbstractFormatter.stringToValue(java.lang.String) definition code for javax.swing.JFormattedTextField.AbstractFormatter.stringToValue(java.lang.String) (String sample code for java.lang.String definition code for java.lang.String  text)
          Parses text returning an arbitrary Object.
 void uninstall sample code for javax.swing.JFormattedTextField.AbstractFormatter.uninstall() definition code for javax.swing.JFormattedTextField.AbstractFormatter.uninstall() ()
          Uninstalls any state the AbstractFormatter may have installed on the JFormattedTextField.
abstract  String sample code for java.lang.String definition code for java.lang.String valueToString sample code for javax.swing.JFormattedTextField.AbstractFormatter.valueToString(java.lang.Object) definition code for javax.swing.JFormattedTextField.AbstractFormatter.valueToString(java.lang.Object) (Object sample code for java.lang.Object definition code for java.lang.Object  value)
          Returns the string value to display for value.
 
Methods inherited from class java.lang.Object sample code for java.lang.Object definition code for java.lang.Object
equals sample code for java.lang.Object.equals(java.lang.Object) definition code for java.lang.Object.equals(java.lang.Object) , finalize sample code for java.lang.Object.finalize() definition code for java.lang.Object.finalize() , getClass sample code for java.lang.Object.getClass() definition code for java.lang.Object.getClass() , hashCode sample code for java.lang.Object.hashCode() definition code for java.lang.Object.hashCode() , notify sample code for java.lang.Object.notify() definition code for java.lang.Object.notify() , notifyAll sample code for java.lang.Object.notifyAll() definition code for java.lang.Object.notifyAll() , toString sample code for java.lang.Object.toString() definition code for java.lang.Object.toString() , wait sample code for java.lang.Object.wait() definition code for java.lang.Object.wait() , wait sample code for java.lang.Object.wait(long) definition code for java.lang.Object.wait(long) , wait sample code for java.lang.Object.wait(long, int) definition code for java.lang.Object.wait(long, int)
 

Constructor Detail

JFormattedTextField.AbstractFormatter sample code for javax.swing.JFormattedTextField.AbstractFormatter() definition code for javax.swing.JFormattedTextField.AbstractFormatter()

public JFormattedTextField.AbstractFormatter()
Method Detail

install sample code for javax.swing.JFormattedTextField.AbstractFormatter.install(javax.swing.JFormattedTextField) definition code for javax.swing.JFormattedTextField.AbstractFormatter.install(javax.swing.JFormattedTextField)

public void install(JFormattedTextField sample code for javax.swing.JFormattedTextField definition code for javax.swing.JFormattedTextField  ftf)
Installs the AbstractFormatter onto a particular JFormattedTextField. This will invoke valueToString to convert the current value from the JFormattedTextField to a String. This will then install the Actions from getActions, the DocumentFilter returned from getDocumentFilter and the NavigationFilter returned from getNavigationFilter onto the JFormattedTextField.

Subclasses will typically only need to override this if they wish to install additional listeners on the JFormattedTextField.

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 sample code for javax.swing.JFormattedTextField.AbstractFormatter.uninstall() definition code for javax.swing.JFormattedTextField.AbstractFormatter.uninstall()

public void uninstall()
Uninstalls any state the AbstractFormatter may have installed on the JFormattedTextField. This resets the DocumentFilter, NavigationFilter and additional Actions installed on the JFormattedTextField.


stringToValue sample code for javax.swing.JFormattedTextField.AbstractFormatter.stringToValue(java.lang.String) definition code for javax.swing.JFormattedTextField.AbstractFormatter.stringToValue(java.lang.String)

public abstract Object sample code for java.lang.Object definition code for java.lang.Object  stringToValue(String sample code for java.lang.String definition code for java.lang.String  text)
                              throws ParseException sample code for java.text.ParseException definition code for java.text.ParseException 
Parses text returning an arbitrary Object. Some formatters may return null.

Parameters:
text - String to convert
Returns:
Object representation of text
Throws:
ParseException sample code for java.text.ParseException definition code for java.text.ParseException - if there is an error in the conversion

valueToString sample code for javax.swing.JFormattedTextField.AbstractFormatter.valueToString(java.lang.Object) definition code for javax.swing.JFormattedTextField.AbstractFormatter.valueToString(java.lang.Object)

public abstract String sample code for java.lang.String definition code for java.lang.String  valueToString(Object sample code for java.lang.Object definition code for java.lang.Object  value)
                              throws ParseException sample code for java.text.ParseException definition code for java.text.ParseException 
Returns the string value to display for value.

Parameters:
value - Value to convert
Returns:
String representation of value
Throws:
ParseException sample code for java.text.ParseException definition code for java.text.ParseException - if there is an error in the conversion

getFormattedTextField sample code for javax.swing.JFormattedTextField.AbstractFormatter.getFormattedTextField() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getFormattedTextField()

protected JFormattedTextField sample code for javax.swing.JFormattedTextField definition code for javax.swing.JFormattedTextField  getFormattedTextField()
Returns the current JFormattedTextField the AbstractFormatter is installed on.

Returns:
JFormattedTextField formatting for.

invalidEdit sample code for javax.swing.JFormattedTextField.AbstractFormatter.invalidEdit() definition code for javax.swing.JFormattedTextField.AbstractFormatter.invalidEdit()

protected void invalidEdit()
This should be invoked when the user types an invalid character. This forwards the call to the current JFormattedTextField.


setEditValid sample code for javax.swing.JFormattedTextField.AbstractFormatter.setEditValid(boolean) definition code for javax.swing.JFormattedTextField.AbstractFormatter.setEditValid(boolean)

protected void setEditValid(boolean valid)
Invoke this to update the editValid property of the JFormattedTextField. 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 sample code for javax.swing.JFormattedTextField.AbstractFormatter.getActions() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getActions()

protected Action sample code for javax.swing.Action definition code for javax.swing.Action [] getActions()
Subclass and override if you wish to provide a custom set of Actions. install will install these on the JFormattedTextField's ActionMap.

Returns:
Array of Actions to install on JFormattedTextField

getDocumentFilter sample code for javax.swing.JFormattedTextField.AbstractFormatter.getDocumentFilter() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getDocumentFilter()

protected DocumentFilter sample code for javax.swing.text.DocumentFilter definition code for javax.swing.text.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 sample code for javax.swing.JFormattedTextField.AbstractFormatter.getNavigationFilter() definition code for javax.swing.JFormattedTextField.AbstractFormatter.getNavigationFilter()

protected NavigationFilter sample code for javax.swing.text.NavigationFilter definition code for javax.swing.text.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 sample code for javax.swing.JFormattedTextField.AbstractFormatter.clone() definition code for javax.swing.JFormattedTextField.AbstractFormatter.clone()

protected Object sample code for java.lang.Object definition code for java.lang.Object  clone()
                throws CloneNotSupportedException sample code for java.lang.CloneNotSupportedException definition code for java.lang.CloneNotSupportedException 
Clones the AbstractFormatter. The returned instance is not associated with a JFormattedTextField.

Overrides:
clone sample code for java.lang.Object.clone() definition code for java.lang.Object.clone() in class Object sample code for java.lang.Object definition code for java.lang.Object
Returns:
Copy of the AbstractFormatter
Throws:
CloneNotSupportedException sample code for java.lang.CloneNotSupportedException definition code for java.lang.CloneNotSupportedException - 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:
Cloneable sample code for java.lang.Cloneable definition code for java.lang.Cloneable