javax.swing.text
Class DefaultFormatter
- Cloneable, Serializable
The
DefaultFormatter
is a concrete formatter for use in
JFormattedTextField
s.
It can format arbitrary values by invoking
their
Object.toString()
method.
In order to convert a String back to
a value, the value class must provide a single argument constructor that
takes a String object as argument value. If no such constructor is found,
the String itself is passed back by #stringToValue.
clone , getActions , getDocumentFilter , getFormattedTextField , getNavigationFilter , install , invalidEdit , setEditValid , stringToValue , uninstall , valueToString |
clone , equals , extends Object> getClass , finalize , hashCode , notify , notifyAll , toString , wait , wait , wait |
DefaultFormatter
public DefaultFormatter()
Creates a new instance of DefaultFormatter
.
getAllowsInvalid
public boolean getAllowsInvalid()
Returns whether or not invalid edits are allowed or not. If invalid
edits are allowed, the JFormattedTextField may temporarily contain invalid
characters.
- the value of the allowsInvalid property
getCommitsOnValidEdit
public boolean getCommitsOnValidEdit()
Returns true
if the value should be committed after
each valid modification of the input field, false
if
it should never be committed by this formatter.
- the state of the
commitsOnValidEdit
property
getOverwriteMode
public boolean getOverwriteMode()
Returns the value of the overwriteMode
property.
If that is set to true
then newly inserted characters
overwrite existing values, otherwise the characters are inserted like
normal. The default is true
.
- the value of the
overwriteMode
property
getValueClass
public Class> getValueClass()
Returns the class that is used for values. When Strings are converted
back to values, this class is used to create new value objects.
- the class that is used for values
install
public void install(JFormattedTextField ftf)
Installs the formatter on the specified
JFormattedTextField
.
This method does the following things:
- Display the value of #valueToString in the
JFormattedTextField
- Install the Actions from #getActions on the
JTextField
- Install the DocumentFilter returned by #getDocumentFilter
- Install the NavigationFilter returned by #getNavigationFilter
This method is typically not overridden by subclasses. Instead override
one of the mentioned methods in order to customize behaviour.
- install in interface JFormattedTextField.AbstractFormatter
setAllowsInvalid
public void setAllowsInvalid(boolean allowsInvalid)
Sets the value of the allowsInvalid
property.
allowsInvalid
- the new value for the property
setCommitsOnValidEdit
public void setCommitsOnValidEdit(boolean commitsOnValidEdit)
Sets the value of the commitsOnValidEdit
property.
commitsOnValidEdit
- the new state of the
commitsOnValidEdit
property
setOverwriteMode
public void setOverwriteMode(boolean overwriteMode)
Sets the value of the overwriteMode
property.
If that is set to true
then newly inserted characters
overwrite existing values, otherwise the characters are inserted like
normal. The default is true
.
overwriteMode
- the new value for the overwriteMode
property
setValueClass
public void setValueClass(Class> valueClass)
Sets the class that is used for values.
valueClass
- the class that is used for values
stringToValue
public Object stringToValue(String string)
throws ParseException
Converts a String (from the JFormattedTextField input) to a value.
In order to achieve this, the formatter tries to instantiate an object
of the class returned by #getValueClass() using a single argument
constructor that takes a String argument. If such a constructor cannot
be found, the String itself is returned.
- stringToValue in interface JFormattedTextField.AbstractFormatter
string
- the string to convert
ParseException
- if the string cannot be converted into
a value object (e.g. invalid input)
DefaultFormatter.java --
Copyright (C) 2005 Free Software Foundation, Inc.
This file is part of GNU Classpath.
GNU Classpath is free software; you can redistribute it and/or modify
it under the terms of the GNU General Public License as published by
the Free Software Foundation; either version 2, or (at your option)
any later version.
GNU Classpath is distributed in the hope that it will be useful, but
WITHOUT ANY WARRANTY; without even the implied warranty of
MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
General Public License for more details.
You should have received a copy of the GNU General Public License
along with GNU Classpath; see the file COPYING. If not, write to the
Free Software Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA
02110-1301 USA.
Linking this library statically or dynamically with other modules is
making a combined work based on this library. Thus, the terms and
conditions of the GNU General Public License cover the whole
combination.
As a special exception, the copyright holders of this library give you
permission to link this library with independent modules to produce an
executable, regardless of the license terms of these independent
modules, and to copy and distribute the resulting executable under
terms of your choice, provided that you also meet, for each linked
independent module, the terms and conditions of the license of that
module. An independent module is a module which is not derived from
or based on this library. If you modify this library, you may extend
this exception to your version of the library, but you are not
obligated to do so. If you do not wish to do so, delete this
exception statement from your version.