United StatesChange Country, Oracle Worldwide Web Sites Communities I am a... I want to...
JDK-4431047 : JFormattedTextField should treat replace as an atomic edit

Details
Type:
Bug
Submit Date:
2001-03-28
Status:
Resolved
Updated Date:
2001-05-09
Project Name:
JDK
Resolved Date:
2001-05-09
Component:
client-libs
OS:
solaris_7
Sub-Component:
javax.swing
CPU:
sparc
Priority:
P3
Resolution:
Fixed
Affected Versions:
1.4.0
Fixed Versions:
1.4.0 (beta2)

Related Reports
Relates:
Relates:

Sub Tasks

Description
As a replace is typically seen as two edits, a remove than an insert, this can confuse the formatter and result in odd behavior. For example if you are editing a number, select all the text and replace it with a legal number often times it won't let you as the initial removal results in a bogus value.

                                    

Comments
CONVERTED DATA

BugTraq+ Release Management Values

COMMIT TO FIX:
merlin-beta2

FIXED IN:
merlin-beta2

INTEGRATED IN:
merlin-beta2


                                     
2004-06-14
EVALUATION

 The following will be added to AbstractDocument:

    /**
     * Deletes the region of text from <code>offset</code> to
     * <code>offset + length</code>, and replaces it with <code>text</code>.
     * It is up to the implementation as to how this is implemented, some
     * implementations may treat this as two distinct operations: a remove
     * followed by an insert, others may treat the replace as one atomic  
     * operation.
     * 
     * @param offset Location in Document
     * @param length Length of text to delete
     * @param text Text to insert, null indicates no text to insert
     * @param attrs AttributeSet indicating attributes of inserted text, null
     *              is legal, and typically treated as an empty attributeset,
     *              but exact interpretation is left to the subclass
     * @exception BadLocationException the given position is not a valid 
     *            position within the document
     * @since 1.4
     */
    public void replace(int offset, int length, String text,
                        AttributeSet attrs) throws BadLocationException;

  Similarly javax.swing.text.DocumentFilter will get (there is no
    @since 1.4 here as DocumentFilter is new in 1.4):
    /**
     * Invoked prior to replacing a region of text in the
     * specified Document. Subclasses that want to conditionally allow
     * replace should override this and only call supers implementation as
     * necessary, or call directly into the FilterBypass.
     *
     * @param fb FilterBypass that can be used to mutate Document
     * @param offset Location in Document
     * @param length Length of text to delete
     * @param text Text to insert, null indicates no text to insert
     * @param attrs AttributeSet indicating attributes of inserted text,
     *              null is legal.
     * @exception BadLocationException  the given insert position is not a
     *   valid position within the document
     */
    public void replace(FilterBypass fb, int offset, int length, String text,
                        AttributeSet attrs) throws BadLocationException;

  And javax.swing.text.DocumentFilter.FilterBypass will get:
        /**
         * Deletes the region of text from <code>offset</code> to
         * <code>offset + length</code>, and replaces it with
         *  <code>text</code>.
         *
         * @param offset Location in Document
         * @param length Length of text to delete
         * @param text Text to insert, null indicates no text to insert
         * @param attrs AttributeSet indicating attributes of inserted text,
         *              null is legal.
         * @exception BadLocationException  the given insert is not a
         *   valid position within the document
         */
        public abstract void replace(int offset, int length, String string,
                                          AttributeSet attrs) throws
                                   BadLocationException;

scott.violet@eng 2001-04-24
                                     
2001-04-24



Hardware and Software, Engineered to Work Together