
2006-06-09 Thomas Fitzsimmons <fitzsim@redhat.com> * java/lang/String.java, classpath/native/jni/classpath/jcl.h, classpath/native/jni/qt-peer/eventmethods.h, classpath/native/jni/qt-peer/qtmenupeer.cpp, classpath/native/jni/qt-peer/.cvsignore, classpath/native/jni/gtk-peer/gdkdisplay.h, classpath/native/jni/gtk-peer/cairographics2d.h, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoGraphics2D.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkFontPeer.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_FreetypeGlyphVector.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_ComponentGraphics.c, classpath/native/jni/gtk-peer/.cvsignore, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkImage.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkVolatileImage.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkToolkit.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkCanvasPeer.c, classpath/native/jni/gtk-peer/gtkpeer.h, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkClipboard.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_CairoSurface.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GdkTextLayout.c, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkFramePeer.c, classpath/native/jni/gtk-peer/Makefile.am, classpath/native/jni/gtk-peer/gnu_java_awt_peer_gtk_GtkComponentPeer.c, classpath/native/jawt/Makefile.am, classpath/native/jawt/.cvsignore, classpath/native/target/Linux/Makefile.in, classpath/native/plugin/gcjwebplugin.cc, classpath/native/plugin/Makefile.am, classpath/native/plugin/.cvsignore, classpath/resource/Makefile.in, classpath/gnu/java/awt/peer/gtk/VolatileImageGraphics.java, classpath/gnu/java/awt/peer/gtk/CairoGraphics2D.java, classpath/gnu/java/awt/peer/gtk/CairoSurface.java, classpath/gnu/java/awt/peer/gtk/GdkFontPeer.java, classpath/gnu/java/awt/peer/gtk/GdkPixbufDecoder.java, classpath/gnu/java/awt/peer/gtk/FreetypeGlyphVector.java, classpath/gnu/java/awt/peer/gtk/GdkGraphicsEnvironment.java, classpath/gnu/java/awt/peer/gtk/GdkGraphics2D.java, classpath/gnu/java/awt/peer/gtk/ComponentGraphicsCopy.java, classpath/gnu/java/awt/peer/gtk/GtkComponentPeer.java, classpath/gnu/java/awt/peer/gtk/GdkGraphics.java, classpath/gnu/java/awt/peer/gtk/GtkToolkit.java, classpath/gnu/java/awt/peer/gtk/GdkScreenGraphicsDevice.java, classpath/gnu/java/awt/peer/gtk/BufferedImageGraphics.java, classpath/gnu/java/awt/peer/gtk/GdkTextLayout.java, classpath/gnu/java/awt/peer/gtk/GdkGraphicsConfiguration.java, classpath/gnu/java/awt/peer/gtk/ComponentGraphics.java, classpath/gnu/java/awt/peer/gtk/CairoSurfaceGraphics.java, classpath/gnu/java/awt/peer/gtk/GtkImage.java, classpath/gnu/java/awt/peer/gtk/GtkVolatileImage.java, classpath/gnu/java/awt/peer/gtk/GdkGlyphVector.java, classpath/gnu/java/awt/peer/gtk/GtkCanvasPeer.java, classpath/gnu/java/awt/peer/swing/SwingContainerPeer.java, classpath/gnu/java/awt/peer/swing/SwingComponent.java, classpath/gnu/java/awt/peer/swing/SwingTextFieldPeer.java, classpath/gnu/java/awt/peer/swing/SwingMenuBarPeer.java, classpath/gnu/java/awt/peer/swing/SwingFramePeer.java, classpath/gnu/java/awt/peer/swing/SwingComponentPeer.java, classpath/gnu/java/awt/peer/swing/SwingWindowPeer.java, classpath/gnu/java/awt/print/JavaPrinterJob.java, classpath/gnu/java/awt/print/PostScriptGraphics2D.java, classpath/gnu/java/awt/print/SpooledDocument.java, classpath/gnu/java/awt/print/JavaPrinterGraphics.java, classpath/gnu/java/awt/BitwiseXORComposite.java, classpath/gnu/java/awt/font/GNUGlyphVector.java, classpath/gnu/java/awt/font/opentype/NameDecoder.java, classpath/gnu/java/awt/java2d/RasterGraphics.java, classpath/gnu/java/awt/java2d/TexturePaintContext.java, classpath/gnu/java/awt/java2d/PolyEdge.java, classpath/gnu/java/awt/java2d/AbstractGraphics2D.java, classpath/gnu/java/awt/java2d/AlphaCompositeContext.java, classpath/gnu/java/awt/java2d/ImagePaint.java, classpath/gnu/java/awt/Buffers.java, classpath/gnu/classpath/Configuration.java.in, classpath/gnu/javax/swing/text/html/CombinedAttributes.java, classpath/gnu/javax/swing/text/html/CharacterAttributeTranslator.java, classpath/gnu/javax/swing/text/html/parser/htmlAttributeSet.java, classpath/gnu/javax/swing/text/html/parser/SmallHtmlAttributeSet.java, classpath/gnu/javax/swing/text/html/ImageViewIconFactory.java, classpath/tools/toolwrapper.c, classpath/tools/gnu/classpath/tools/native2ascii/Native2ASCII.java, classpath/tools/gnu/classpath/tools/native2ascii/Messages.java, classpath/tools/gnu/classpath/tools/getopt/FileArgumentCallback.java, classpath/tools/gnu/classpath/tools/getopt/OptionGroup.java, classpath/tools/gnu/classpath/tools/getopt/OptionException.java, classpath/tools/gnu/classpath/tools/getopt/Messages.java, classpath/tools/gnu/classpath/tools/getopt/Option.java, classpath/tools/gnu/classpath/tools/getopt/Parser.java, classpath/tools/gnu/classpath/tools/getopt/ClasspathToolParser.java, classpath/tools/gnu/classpath/tools/jarsigner/JarSigner.java, classpath/tools/gnu/classpath/tools/jarsigner/Main.java, classpath/tools/gnu/classpath/tools/jarsigner/Messages.java, classpath/tools/gnu/classpath/tools/jarsigner/package.html, classpath/tools/gnu/classpath/tools/keytool/ListCmd.java, classpath/tools/gnu/classpath/tools/keytool/StorePasswdCmd.java, classpath/tools/gnu/classpath/tools/keytool/ExportCmd.java, classpath/tools/gnu/classpath/tools/keytool/GenKeyCmd.java, classpath/tools/gnu/classpath/tools/keytool/Messages.java, classpath/tools/gnu/classpath/tools/keytool/package.html, classpath/tools/gnu/classpath/tools/keytool/Command.java, classpath/tools/gnu/classpath/tools/keytool/IdentityDBCmd.java, classpath/tools/gnu/classpath/tools/keytool/Main.java, classpath/tools/gnu/classpath/tools/keytool/DeleteCmd.java, classpath/tools/gnu/classpath/tools/keytool/CertReqCmd.java, classpath/tools/gnu/classpath/tools/keytool/SelfCertCmd.java, classpath/tools/gnu/classpath/tools/keytool/KeyCloneCmd.java, classpath/tools/gnu/classpath/tools/keytool/KeyPasswdCmd.java, classpath/tools/gnu/classpath/tools/keytool/ImportCmd.java, classpath/tools/gnu/classpath/tools/keytool/PrintCertCmd.java, classpath/tools/gnu/classpath/tools/rmi/registry/package.html, classpath/tools/gnu/classpath/tools/rmi/RMIC.txt, classpath/tools/gnu/classpath/tools/rmi/RMIC.java, classpath/tools/gnu/classpath/tools/appletviewer/ErrorApplet.java, classpath/tools/gnu/classpath/tools/appletviewer/AppletClassLoader.java, classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletContext.java, classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletContext.java, classpath/tools/gnu/classpath/tools/appletviewer/AppletSecurityManager.java, classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletContext.java, classpath/tools/gnu/classpath/tools/appletviewer/AppletWarning.java, classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletViewer.java, classpath/tools/gnu/classpath/tools/appletviewer/AppletTag.java, classpath/tools/gnu/classpath/tools/appletviewer/ConsoleDialog.java, classpath/tools/gnu/classpath/tools/appletviewer/Main.java, classpath/tools/gnu/classpath/tools/appletviewer/StandaloneAppletWindow.java, classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletViewer.java, classpath/tools/gnu/classpath/tools/appletviewer/TagParser.java, classpath/tools/gnu/classpath/tools/appletviewer/PluginAppletWindow.java, classpath/tools/gnu/classpath/tools/appletviewer/CommonAppletStub.java, classpath/tools/gnu/classpath/tools/serialver/Messages.java, classpath/tools/gnu/classpath/tools/serialver/SerialVer.java, classpath/tools/gnu/classpath/tools/jar/Creator.java, classpath/tools/gnu/classpath/tools/jar/Entry.java, classpath/tools/gnu/classpath/tools/jar/Lister.java, classpath/tools/gnu/classpath/tools/jar/Main.java, classpath/tools/gnu/classpath/tools/jar/Updater.java, classpath/tools/gnu/classpath/tools/jar/Messages.java, classpath/tools/gnu/classpath/tools/jar/Extractor.java, classpath/tools/gnu/classpath/tools/jar/Action.java, classpath/tools/gnu/classpath/tools/jar/Indexer.java, classpath/tools/gnu/classpath/tools/jar/WorkSet.java, classpath/tools/gnu/classpath/tools/giop/GRMIC.txt, classpath/tools/gnu/classpath/tools/giop/grmic/GiopRmicCompiler.java, classpath/tools/gnu/classpath/tools/giop/GRMIC.java, classpath/tools/Makefile.am, classpath/tools/jarsigner.in, classpath/tools/keytool.in, classpath/tools/appletviewer.in, classpath/tools/.cvsignore, classpath/configure.ac, classpath/javax/swing/JTabbedPane.java, classpath/javax/swing/AbstractButton.java, classpath/javax/swing/JViewport.java, classpath/javax/swing/KeyboardManager.java, classpath/javax/swing/JMenuItem.java, classpath/javax/swing/JMenuBar.java, classpath/javax/swing/MenuSelectionManager.java, classpath/javax/swing/JOptionPane.java, classpath/javax/swing/JSpinner.java, classpath/javax/swing/JCheckBoxMenuItem.java, classpath/javax/swing/JEditorPane.java, classpath/javax/swing/JFormattedTextField.java, classpath/javax/swing/JTree.java, classpath/javax/swing/CellRendererPane.java, classpath/javax/swing/JScrollPane.java, classpath/javax/swing/tree/VariableHeightLayoutCache.java, classpath/javax/swing/tree/TreeNode.java, classpath/javax/swing/tree/FixedHeightLayoutCache.java, classpath/javax/swing/tree/DefaultTreeCellEditor.java, classpath/javax/swing/tree/TreePath.java, classpath/javax/swing/tree/RowMapper.java, classpath/javax/swing/tree/DefaultMutableTreeNode.java, classpath/javax/swing/tree/DefaultTreeModel.java, classpath/javax/swing/tree/AbstractLayoutCache.java, classpath/javax/swing/tree/TreeSelectionModel.java, classpath/javax/swing/tree/DefaultTreeSelectionModel.java, classpath/javax/swing/tree/DefaultTreeCellRenderer.java, classpath/javax/swing/tree/ExpandVetoException.java, classpath/javax/swing/JList.java, classpath/javax/swing/table/JTableHeader.java, classpath/javax/swing/table/AbstractTableModel.java, classpath/javax/swing/table/DefaultTableModel.java, classpath/javax/swing/table/TableCellEditor.java, classpath/javax/swing/table/TableCellRenderer.java, classpath/javax/swing/ProgressMonitor.java, classpath/javax/swing/JToolBar.java, classpath/javax/swing/TransferHandler.java, classpath/javax/swing/DefaultCellEditor.java, classpath/javax/swing/DefaultButtonModel.java, classpath/javax/swing/JLayeredPane.java, classpath/javax/swing/text/DefaultEditorKit.java, classpath/javax/swing/text/DefaultCaret.java, classpath/javax/swing/text/FieldView.java, classpath/javax/swing/text/JTextComponent.java, classpath/javax/swing/text/TextAction.java, classpath/javax/swing/text/StyleContext.java, classpath/javax/swing/text/html/HTMLDocument.java, classpath/javax/swing/text/html/MinimalHTMLWriter.java, classpath/javax/swing/text/html/ImageView.java, classpath/javax/swing/text/html/HTMLEditorKit.java, classpath/javax/swing/text/AbstractWriter.java, classpath/javax/swing/text/GapContent.java, classpath/javax/swing/text/Utilities.java, classpath/javax/swing/text/PlainView.java, classpath/javax/swing/UIManager.java, classpath/javax/swing/JSplitPane.java, classpath/javax/swing/JComponent.java, classpath/javax/swing/SwingUtilities.java, classpath/javax/swing/border/AbstractBorder.java, classpath/javax/swing/border/CompoundBorder.java, classpath/javax/swing/border/TitledBorder.java, classpath/javax/swing/border/MatteBorder.java, classpath/javax/swing/border/BevelBorder.java, classpath/javax/swing/RepaintManager.java, classpath/javax/swing/JTable.java, classpath/javax/swing/UIDefaults.java, classpath/javax/swing/DefaultDesktopManager.java, classpath/javax/swing/JMenu.java, classpath/javax/swing/JLabel.java, classpath/javax/swing/JSlider.java, classpath/javax/swing/plaf/basic/BasicToolBarUI.java, classpath/javax/swing/plaf/basic/BasicButtonUI.java, classpath/javax/swing/plaf/basic/BasicOptionPaneUI.java, classpath/javax/swing/plaf/basic/BasicTextAreaUI.java, classpath/javax/swing/plaf/basic/BasicToggleButtonUI.java, classpath/javax/swing/plaf/basic/BasicSpinnerUI.java, classpath/javax/swing/plaf/basic/BasicSliderUI.java, classpath/javax/swing/plaf/basic/BasicTabbedPaneUI.java, classpath/javax/swing/plaf/basic/BasicComboPopup.java, classpath/javax/swing/plaf/basic/BasicCheckBoxUI.java, classpath/javax/swing/plaf/basic/BasicInternalFrameUI.java, classpath/javax/swing/plaf/basic/BasicProgressBarUI.java, classpath/javax/swing/plaf/basic/BasicRadioButtonUI.java, classpath/javax/swing/plaf/basic/BasicPanelUI.java, classpath/javax/swing/plaf/basic/BasicSplitPaneUI.java, classpath/javax/swing/plaf/basic/BasicTreeUI.java, classpath/javax/swing/plaf/basic/BasicTableHeaderUI.java, classpath/javax/swing/plaf/basic/BasicFileChooserUI.java, classpath/javax/swing/plaf/basic/BasicScrollPaneUI.java, classpath/javax/swing/plaf/basic/BasicComboBoxUI.java, classpath/javax/swing/plaf/basic/BasicListUI.java, classpath/javax/swing/plaf/basic/BasicIconFactory.java, classpath/javax/swing/plaf/basic/BasicTextUI.java, classpath/javax/swing/plaf/basic/BasicLookAndFeel.java, classpath/javax/swing/plaf/basic/BasicDirectoryModel.java, classpath/javax/swing/plaf/basic/BasicRootPaneUI.java, classpath/javax/swing/plaf/basic/BasicTableUI.java, classpath/javax/swing/plaf/basic/SharedUIDefaults.java, classpath/javax/swing/plaf/multi/MultiComboBoxUI.java, classpath/javax/swing/plaf/multi/MultiListUI.java, classpath/javax/swing/plaf/multi/MultiSplitPaneUI.java, classpath/javax/swing/plaf/multi/MultiFileChooserUI.java, classpath/javax/swing/plaf/multi/MultiOptionPaneUI.java, classpath/javax/swing/plaf/multi/MultiTabbedPaneUI.java, classpath/javax/swing/plaf/multi/MultiLookAndFeel.java, classpath/javax/swing/plaf/metal/MetalSliderUI.java, classpath/javax/swing/plaf/metal/MetalIconFactory.java, classpath/javax/swing/plaf/metal/MetalComboBoxIcon.java, classpath/javax/swing/plaf/metal/MetalTabbedPaneUI.java, classpath/javax/swing/plaf/metal/MetalLookAndFeel.java, classpath/javax/swing/plaf/metal/MetalCheckBoxUI.java, classpath/javax/swing/plaf/metal/MetalSeparatorUI.java, classpath/javax/swing/plaf/metal/MetalBorders.java, classpath/javax/swing/plaf/metal/MetalSplitPaneDivider.java, classpath/javax/swing/plaf/metal/MetalScrollBarUI.java, classpath/javax/swing/plaf/metal/MetalRootPaneUI.java, classpath/javax/swing/plaf/metal/MetalInternalFrameUI.java, classpath/javax/swing/plaf/metal/MetalRadioButtonUI.java, classpath/javax/swing/plaf/metal/MetalToolTipUI.java, classpath/javax/swing/plaf/metal/MetalInternalFrameTitlePane.java, classpath/javax/swing/plaf/metal/MetalFileChooserUI.java, classpath/javax/swing/plaf/metal/MetalUtils.java, classpath/javax/swing/plaf/metal/MetalComboBoxButton.java, classpath/javax/swing/plaf/metal/MetalPopupMenuSeparatorUI.java, classpath/javax/swing/plaf/metal/MetalButtonUI.java, classpath/javax/swing/JPopupMenu.java, classpath/javax/swing/JProgressBar.java, classpath/javax/swing/WindowConstants.java, classpath/javax/swing/JFrame.java, classpath/javax/swing/JFileChooser.java, classpath/javax/swing/JComboBox.java, classpath/javax/swing/event/EventListenerList.java, classpath/javax/swing/ListSelectionModel.java, classpath/javax/swing/JScrollBar.java, classpath/java/text/SimpleDateFormat.java, classpath/java/text/NumberFormat.java, classpath/java/text/class-dependencies.conf, classpath/java/awt/image/ColorModel.java, classpath/java/awt/image/BufferedImage.java, classpath/java/awt/Window.java, classpath/java/awt/ContainerOrderFocusTraversalPolicy.java, classpath/java/awt/LightweightDispatcher.java, classpath/java/awt/EventDispatchThread.java, classpath/java/awt/BasicStroke.java, classpath/java/awt/ColorPaintContext.java, classpath/java/awt/Container.java, classpath/java/awt/TexturePaint.java, classpath/java/awt/Component.java, classpath/java/awt/Font.java, classpath/java/awt/GraphicsConfiguration.java, classpath/java/awt/DefaultKeyboardFocusManager.java, classpath/java/awt/print/PrinterJob.java, classpath/java/awt/im/InputContext.java, classpath/java/awt/dnd/DragGestureRecognizer.java, classpath/java/awt/Toolkit.java, classpath/java/awt/font/GraphicAttribute.java, classpath/java/awt/font/ImageGraphicAttribute.java, classpath/java/awt/font/GlyphVector.java, classpath/java/awt/font/GlyphMetrics.java, classpath/java/awt/font/ShapeGraphicAttribute.java, classpath/java/awt/Graphics2D.java, classpath/include/gnu_java_awt_peer_gtk_GdkGraphicsEnvironment.h, classpath/include/gnu_java_awt_peer_gtk_ComponentGraphics.h, classpath/include/gnu_java_awt_peer_gtk_CairoGraphics2D.h, classpath/include/gnu_java_awt_peer_gtk_FreetypeGlyphVector.h, classpath/include/gnu_java_awt_peer_gtk_GtkCanvasPeer.h, classpath/include/config.h.in, classpath/include/gnu_java_awt_peer_gtk_GdkTextLayout.h, classpath/include/gnu_java_awt_peer_gtk_GtkComponentPeer.h, classpath/include/gnu_java_awt_peer_gtk_GdkFontPeer.h, classpath/include/gnu_java_awt_peer_gtk_ComponentGraphicsCopy.h, classpath/include/gnu_java_awt_peer_gtk_GtkVolatileImage.h, classpath/include/gnu_java_awt_peer_gtk_GtkImage.h, classpath/include/gnu_java_awt_peer_gtk_CairoSurface.h, classpath/include/gnu_java_awt_peer_gtk_GdkScreenGraphicsDevice.h: Merge from GNU Classpath HEAD. From-SVN: r114510
648 lines
20 KiB
Java
648 lines
20 KiB
Java
/* JFormattedTextField.java --
|
|
Copyright (C) 2003, 2004 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. */
|
|
|
|
|
|
package javax.swing;
|
|
|
|
import java.awt.event.FocusEvent;
|
|
import java.io.Serializable;
|
|
import java.text.DateFormat;
|
|
import java.text.Format;
|
|
import java.text.NumberFormat;
|
|
import java.text.ParseException;
|
|
import java.util.Date;
|
|
|
|
import javax.swing.text.AbstractDocument;
|
|
import javax.swing.text.DateFormatter;
|
|
import javax.swing.text.DefaultFormatter;
|
|
import javax.swing.text.DefaultFormatterFactory;
|
|
import javax.swing.text.Document;
|
|
import javax.swing.text.DocumentFilter;
|
|
import javax.swing.text.InternationalFormatter;
|
|
import javax.swing.text.NavigationFilter;
|
|
import javax.swing.text.NumberFormatter;
|
|
|
|
/**
|
|
* A text field that makes use of a formatter to display and edit a specific
|
|
* type of data. The value that is displayed can be an arbitrary object. The
|
|
* formatter is responsible for displaying the value in a textual form and
|
|
* it may allow editing of the value.
|
|
*
|
|
* Formatters are usually obtained using an instance of
|
|
* {@link AbstractFormatterFactory}. This factory is responsible for providing
|
|
* an instance of {@link AbstractFormatter} that is able to handle the
|
|
* formatting of the value of the JFormattedTextField.
|
|
*
|
|
* @author Michael Koch
|
|
* @author Anthony Balkissoon abalkiss at redhat dot com
|
|
*
|
|
* @since 1.4
|
|
*/
|
|
public class JFormattedTextField extends JTextField
|
|
{
|
|
private static final long serialVersionUID = 5464657870110180632L;
|
|
|
|
/**
|
|
* 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.
|
|
*/
|
|
public abstract static class AbstractFormatter implements Serializable
|
|
{
|
|
private static final long serialVersionUID = -5193212041738979680L;
|
|
|
|
private JFormattedTextField textField;
|
|
|
|
public AbstractFormatter ()
|
|
{
|
|
//Do nothing here.
|
|
}
|
|
|
|
/**
|
|
* Clones the AbstractFormatter and removes the association to any
|
|
* particular JFormattedTextField.
|
|
*
|
|
* @return 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
|
|
*/
|
|
protected Object clone()
|
|
throws CloneNotSupportedException
|
|
{
|
|
// Clone this formatter.
|
|
AbstractFormatter newFormatter = (AbstractFormatter) super.clone();
|
|
|
|
// And remove the association to the JFormattedTextField.
|
|
newFormatter.textField = null;
|
|
return newFormatter;
|
|
}
|
|
|
|
/**
|
|
* Returns a custom set of Actions that this formatter supports. Should
|
|
* be subclassed by formatters that have a custom set of Actions.
|
|
*
|
|
* @return <code>null</code>. Should be subclassed by formatters that want
|
|
* to install custom Actions on the JFormattedTextField.
|
|
*/
|
|
protected Action[] getActions()
|
|
{
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Gets the DocumentFilter for this formatter. Should be subclassed
|
|
* by formatters wishing to install a filter that oversees Document
|
|
* mutations.
|
|
*
|
|
* @return <code>null</code>. Should be subclassed by formatters
|
|
* that want to restrict Document mutations.
|
|
*/
|
|
protected DocumentFilter getDocumentFilter()
|
|
{
|
|
// Subclasses should override this if they want to install a
|
|
// DocumentFilter.
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* Returns the JFormattedTextField on which this formatter is
|
|
* currently installed.
|
|
*
|
|
* @return the JFormattedTextField on which this formatter is currently
|
|
* installed
|
|
*/
|
|
protected JFormattedTextField getFormattedTextField()
|
|
{
|
|
return textField;
|
|
}
|
|
|
|
/**
|
|
* 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.
|
|
*
|
|
* @return <code>null</code>. Subclassed by formatters that want to restrict
|
|
* cursor location within the JFormattedTextField.
|
|
*/
|
|
protected NavigationFilter getNavigationFilter()
|
|
{
|
|
// This should be subclassed if the formatter wants to install
|
|
// a NavigationFilter on the JFormattedTextField.
|
|
return null;
|
|
}
|
|
|
|
/**
|
|
* 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 <code>getActions</code>.
|
|
* It also installs a DocumentFilter and NavigationFilter on the
|
|
* JFormattedTextField.
|
|
* <p>
|
|
* If there is a <code>ParseException</code> this sets the text to an
|
|
* empty String and marks the text field in an invalid state.
|
|
*
|
|
* @param textField the JFormattedTextField on which to install this
|
|
* formatter
|
|
*/
|
|
public void install(JFormattedTextField textField)
|
|
{
|
|
// Uninstall the current textfield.
|
|
if (this.textField != null)
|
|
uninstall();
|
|
|
|
this.textField = textField;
|
|
|
|
// Install some state on the text field, including display text,
|
|
// DocumentFilter, NavigationFilter, and formatter specific Actions.
|
|
if (textField != null)
|
|
{
|
|
try
|
|
{
|
|
// Set the text of the field.
|
|
textField.setText(valueToString(textField.getValue()));
|
|
Document doc = textField.getDocument();
|
|
|
|
// Set the DocumentFilter for the field's Document.
|
|
if (doc instanceof AbstractDocument)
|
|
((AbstractDocument) doc).setDocumentFilter(getDocumentFilter());
|
|
|
|
// Set the NavigationFilter.
|
|
textField.setNavigationFilter(getNavigationFilter());
|
|
|
|
// Set the Formatter Actions
|
|
// FIXME: Have to add the actions from getActions()
|
|
}
|
|
catch (ParseException pe)
|
|
{
|
|
// Set the text to an empty String and mark the field as invalid.
|
|
textField.setText("");
|
|
setEditValid(false);
|
|
}
|
|
}
|
|
}
|
|
|
|
/**
|
|
* Clears the state installed on the JFormattedTextField by the formatter.
|
|
* This resets the DocumentFilter, NavigationFilter, and any additional
|
|
* Actions (returned by <code>getActions()</code>).
|
|
*/
|
|
public void uninstall()
|
|
{
|
|
// Set the DocumentFilter for the field's Document.
|
|
Document doc = textField.getDocument();
|
|
if (doc instanceof AbstractDocument)
|
|
((AbstractDocument) doc).setDocumentFilter(null);
|
|
textField.setNavigationFilter(null);
|
|
// FIXME: Have to remove the Actions from getActions()
|
|
this.textField = null;
|
|
}
|
|
|
|
/**
|
|
* Invoke this method when invalid values are entered. This forwards the
|
|
* call to the JFormattedTextField.
|
|
*/
|
|
protected void invalidEdit()
|
|
{
|
|
textField.invalidEdit();
|
|
}
|
|
|
|
/**
|
|
* This method updates the <code>editValid</code> property of
|
|
* JFormattedTextField.
|
|
*
|
|
* @param valid the new state for the <code>editValid</code> property
|
|
*/
|
|
protected void setEditValid(boolean valid)
|
|
{
|
|
textField.editValid = valid;
|
|
}
|
|
|
|
/**
|
|
* Parses <code>text</code> to return a corresponding Object.
|
|
*
|
|
* @param text the String to parse
|
|
* @return an Object that <code>text</code> represented
|
|
* @throws ParseException if there is an error in the conversion
|
|
*/
|
|
public abstract Object stringToValue(String text)
|
|
throws ParseException;
|
|
|
|
/**
|
|
* Returns a String to be displayed, based on the Object
|
|
* <code>value</code>.
|
|
*
|
|
* @param value the Object from which to generate a String
|
|
* @return a String to be displayed
|
|
* @throws ParseException if there is an error in the conversion
|
|
*/
|
|
public abstract String valueToString(Object value)
|
|
throws ParseException;
|
|
}
|
|
|
|
/**
|
|
* Delivers instances of an {@link AbstractFormatter} for
|
|
* a specific value type for a JFormattedTextField.
|
|
*/
|
|
public abstract static class AbstractFormatterFactory
|
|
{
|
|
public AbstractFormatterFactory()
|
|
{
|
|
// Do nothing here.
|
|
}
|
|
|
|
public abstract AbstractFormatter getFormatter(JFormattedTextField tf);
|
|
}
|
|
|
|
/** The possible focusLostBehavior options **/
|
|
public static final int COMMIT = 0;
|
|
public static final int COMMIT_OR_REVERT = 1;
|
|
public static final int REVERT = 2;
|
|
public static final int PERSIST = 3;
|
|
|
|
/** The most recent valid and committed value **/
|
|
private Object value;
|
|
|
|
/** The behaviour for when this text field loses focus **/
|
|
private int focusLostBehavior = COMMIT_OR_REVERT;
|
|
|
|
/** The formatter factory currently being used **/
|
|
private AbstractFormatterFactory formatterFactory;
|
|
|
|
/** The formatter currently being used **/
|
|
private AbstractFormatter formatter;
|
|
|
|
// Package-private to avoid an accessor method.
|
|
boolean editValid = true;
|
|
|
|
/**
|
|
* Creates a JFormattedTextField with no formatter factory.
|
|
* <code>setValue</code> or <code>setFormatterFactory</code> will
|
|
* properly configure this text field to edit a particular type
|
|
* of value.
|
|
*/
|
|
public JFormattedTextField()
|
|
{
|
|
this((AbstractFormatterFactory) null, null);
|
|
}
|
|
|
|
/**
|
|
* Creates a JFormattedTextField that can handle the specified Format.
|
|
* An appopriate AbstractFormatter and AbstractFormatterFactory will
|
|
* be created for the specified Format.
|
|
*
|
|
* @param format the Format that this JFormattedTextField should be able
|
|
* to handle
|
|
*/
|
|
public JFormattedTextField(Format format)
|
|
{
|
|
this ();
|
|
setFormatterFactory(getAppropriateFormatterFactory(format));
|
|
}
|
|
|
|
/**
|
|
* Creates a JFormattedTextField with the specified formatter. This will
|
|
* create a {@link DefaultFormatterFactory} with this formatter as the default
|
|
* formatter.
|
|
*
|
|
* @param formatter the formatter to use for this JFormattedTextField
|
|
*/
|
|
public JFormattedTextField(AbstractFormatter formatter)
|
|
{
|
|
this(new DefaultFormatterFactory(formatter));
|
|
}
|
|
|
|
/**
|
|
* Creates a JFormattedTextField with the specified formatter factory.
|
|
*
|
|
* @param factory the formatter factory to use for this JFormattedTextField
|
|
*/
|
|
public JFormattedTextField(AbstractFormatterFactory factory)
|
|
{
|
|
setFormatterFactory(factory);
|
|
}
|
|
|
|
/**
|
|
* Creates a JFormattedTextField with the specified formatter factory and
|
|
* initial value.
|
|
*
|
|
* @param factory the initial formatter factory for this JFormattedTextField
|
|
* @param value the initial value for the text field
|
|
*/
|
|
public JFormattedTextField(AbstractFormatterFactory factory, Object value)
|
|
{
|
|
setFormatterFactory(factory);
|
|
setValue(value);
|
|
}
|
|
|
|
/**
|
|
* Creates a JFormattedTextField with the specified value. This creates a
|
|
* formatter and formatterFactory that are appropriate for the value.
|
|
*
|
|
* @param value the initial value for this JFormattedTextField
|
|
*/
|
|
public JFormattedTextField(Object value)
|
|
{
|
|
setValue(value);
|
|
}
|
|
|
|
/**
|
|
* Returns an AbstractFormatterFactory that will give an appropriate
|
|
* AbstractFormatter for the given Format.
|
|
* @param format the Format to match with an AbstractFormatter.
|
|
* @return a DefaultFormatterFactory whose defaultFormatter is appropriate
|
|
* for the given Format.
|
|
*/
|
|
private AbstractFormatterFactory getAppropriateFormatterFactory(Format format)
|
|
{
|
|
AbstractFormatter newFormatter;
|
|
if (format instanceof DateFormat)
|
|
newFormatter = new DateFormatter((DateFormat) format);
|
|
else if (format instanceof NumberFormat)
|
|
newFormatter = new NumberFormatter ((NumberFormat) format);
|
|
else
|
|
newFormatter = new InternationalFormatter(format);
|
|
|
|
return new DefaultFormatterFactory(newFormatter);
|
|
}
|
|
|
|
/**
|
|
* Forces the current value from the editor to be set as the current
|
|
* value. If there is no current formatted this has no effect.
|
|
*
|
|
* @throws ParseException if the formatter cannot format the current value
|
|
*/
|
|
public void commitEdit()
|
|
throws ParseException
|
|
{
|
|
if (formatter == null)
|
|
return;
|
|
// Note: this code is a lot like setValue except that we don't want
|
|
// to create a new formatter.
|
|
Object oldValue = this.value;
|
|
|
|
this.value = formatter.stringToValue(getText());;
|
|
editValid = true;
|
|
|
|
firePropertyChange("value", oldValue, this.value);
|
|
}
|
|
|
|
/**
|
|
* Gets the command list supplied by the UI augmented by the specific
|
|
* Actions for JFormattedTextField.
|
|
*
|
|
* @return an array of Actions that this text field supports
|
|
*/
|
|
public Action[] getActions()
|
|
{
|
|
// FIXME: Add JFormattedTextField specific actions
|
|
// These are related to committing or cancelling edits.
|
|
return super.getActions();
|
|
}
|
|
|
|
/**
|
|
* Returns the behaviour of this JFormattedTextField upon losing focus. This
|
|
* is one of <code>COMMIT</code>, <code>COMMIT_OR_REVERT</code>,
|
|
* <code>PERSIST</code>, or <code>REVERT</code>.
|
|
* @return the behaviour upon losing focus
|
|
*/
|
|
public int getFocusLostBehavior()
|
|
{
|
|
return focusLostBehavior;
|
|
}
|
|
|
|
/**
|
|
* Returns the current formatter used for this JFormattedTextField.
|
|
* @return the current formatter used for this JFormattedTextField
|
|
*/
|
|
public AbstractFormatter getFormatter()
|
|
{
|
|
return formatter;
|
|
}
|
|
|
|
/**
|
|
* Returns the factory currently used to generate formatters for this
|
|
* JFormattedTextField.
|
|
* @return the factory currently used to generate formatters
|
|
*/
|
|
public AbstractFormatterFactory getFormatterFactory()
|
|
{
|
|
return formatterFactory;
|
|
}
|
|
|
|
public String getUIClassID()
|
|
{
|
|
return "FormattedTextFieldUI";
|
|
}
|
|
|
|
/**
|
|
* Returns the last valid value. This may not be the value currently shown
|
|
* in the text field depending on whether or not the formatter commits on
|
|
* valid edits and allows invalid input to be temporarily displayed.
|
|
* @return the last committed valid value
|
|
*/
|
|
public Object getValue()
|
|
{
|
|
return value;
|
|
}
|
|
|
|
/**
|
|
* This method is used to provide feedback to the user when an invalid value
|
|
* is input during editing.
|
|
*/
|
|
protected void invalidEdit()
|
|
{
|
|
UIManager.getLookAndFeel().provideErrorFeedback(this);
|
|
}
|
|
|
|
/**
|
|
* Returns true if the current value being edited is valid. This property is
|
|
* managed by the current formatted.
|
|
* @return true if the value being edited is valid.
|
|
*/
|
|
public boolean isEditValid()
|
|
{
|
|
return editValid;
|
|
}
|
|
|
|
/**
|
|
* Processes focus events. This is overridden because we may want to
|
|
* change the formatted depending on whether or not this field has
|
|
* focus.
|
|
*
|
|
* @param evt the FocusEvent
|
|
*/
|
|
protected void processFocusEvent(FocusEvent evt)
|
|
{
|
|
super.processFocusEvent(evt);
|
|
// Let the formatterFactory change the formatter for this text field
|
|
// based on whether or not it has focus.
|
|
setFormatter (formatterFactory.getFormatter(this));
|
|
}
|
|
|
|
/**
|
|
* Associates this JFormattedTextField with a Document and propagates
|
|
* a PropertyChange event to each listener.
|
|
*
|
|
* @param newDocument the Document to associate with this text field
|
|
*/
|
|
public void setDocument(Document newDocument)
|
|
{
|
|
// FIXME: This method should do more than this. Must do some handling
|
|
// of the DocumentListeners.
|
|
Document oldDocument = getDocument();
|
|
|
|
if (oldDocument == newDocument)
|
|
return;
|
|
|
|
super.setDocument(newDocument);
|
|
}
|
|
|
|
/**
|
|
* Sets the behaviour of this JFormattedTextField upon losing focus.
|
|
* This must be <code>COMMIT</code>, <code>COMMIT_OR_REVERT</code>,
|
|
* <code>PERSIST</code>, or <code>REVERT</code> or an
|
|
* IllegalArgumentException will be thrown.
|
|
*
|
|
* @param behavior
|
|
* @throws IllegalArgumentException if <code>behaviour</code> is not
|
|
* one of the above
|
|
*/
|
|
public void setFocusLostBehavior(int behavior)
|
|
{
|
|
if (behavior != COMMIT
|
|
&& behavior != COMMIT_OR_REVERT
|
|
&& behavior != PERSIST
|
|
&& behavior != REVERT)
|
|
throw new IllegalArgumentException("invalid behavior");
|
|
|
|
this.focusLostBehavior = behavior;
|
|
}
|
|
|
|
/**
|
|
* Sets the formatter for this JFormattedTextField. Normally the formatter
|
|
* factory will take care of this, or calls to setValue will also make sure
|
|
* that the formatter is set appropriately.
|
|
*
|
|
* @param formatter the AbstractFormatter to use for formatting the value for
|
|
* this JFormattedTextField
|
|
*/
|
|
protected void setFormatter(AbstractFormatter formatter)
|
|
{
|
|
AbstractFormatter oldFormatter = null;
|
|
|
|
oldFormatter = this.formatter;
|
|
|
|
if (oldFormatter != null)
|
|
oldFormatter.uninstall();
|
|
|
|
this.formatter = formatter;
|
|
|
|
if (formatter != null)
|
|
formatter.install(this);
|
|
|
|
firePropertyChange("formatter", oldFormatter, formatter);
|
|
}
|
|
|
|
/**
|
|
* Sets the factory from which this JFormattedTextField should obtain
|
|
* its formatters.
|
|
*
|
|
* @param factory the AbstractFormatterFactory that will be used to generate
|
|
* formatters for this JFormattedTextField
|
|
*/
|
|
public void setFormatterFactory(AbstractFormatterFactory factory)
|
|
{
|
|
if (formatterFactory == factory)
|
|
return;
|
|
|
|
AbstractFormatterFactory oldFactory = formatterFactory;
|
|
formatterFactory = factory;
|
|
firePropertyChange("formatterFactory", oldFactory, factory);
|
|
|
|
// Now set the formatter according to our new factory.
|
|
if (formatterFactory != null)
|
|
setFormatter(formatterFactory.getFormatter(this));
|
|
else
|
|
setFormatter(null);
|
|
}
|
|
|
|
/**
|
|
* Sets the value that will be formatted and displayed.
|
|
*
|
|
* @param newValue the value to be formatted and displayed
|
|
*/
|
|
public void setValue(Object newValue)
|
|
{
|
|
if (value == newValue)
|
|
return;
|
|
|
|
Object oldValue = value;
|
|
value = newValue;
|
|
|
|
// If there is no formatterFactory then make one.
|
|
if (formatterFactory == null)
|
|
setFormatterFactory(createFormatterFactory(newValue));
|
|
|
|
// Set the formatter appropriately. This is because there may be a new
|
|
// formatterFactory from the line above, or we may want a new formatter
|
|
// depending on the type of newValue (or if newValue is null).
|
|
setFormatter (formatterFactory.getFormatter(this));
|
|
firePropertyChange("value", oldValue, newValue);
|
|
}
|
|
|
|
/**
|
|
* A helper method that attempts to create a formatter factory that is
|
|
* suitable to format objects of the type like <code>value</code>.
|
|
*
|
|
* @param value an object which should be formatted by the formatter factory.
|
|
*
|
|
* @return a formatter factory able to format objects of the class of
|
|
* <code>value</code>
|
|
*/
|
|
AbstractFormatterFactory createFormatterFactory(Object value)
|
|
{
|
|
AbstractFormatter formatter = null;
|
|
if (value instanceof Date)
|
|
formatter = new DateFormatter();
|
|
else if (value instanceof Number)
|
|
formatter = new NumberFormatter();
|
|
else
|
|
formatter = new DefaultFormatter();
|
|
return new DefaultFormatterFactory(formatter);
|
|
}
|
|
}
|