Hi Tony,

Am 13.2.2006 schrieb "Anthony Balkissoon" <[EMAIL PROTECTED]>:

>On Fri, 2006-02-10 at 15:10 +0000, Roman Kennke wrote:
>> I added the missing ElementBuffer.clone() method.
>>
>> 2006-02-10  Roman Kennke  <[EMAIL PROTECTED]>
>>
>>         * javax/swing/text/DefaultStyledDocument.java
>>         (ElementBuffer.clone): New method.
>
>I don't understand ... I implemented this method on November 8, 2005 and
>committed the ChangeLog and sent an email to this list ... did I forget
>to commit the actual change or something?
>
>Oh I see now...it was in the wrong place, not in the inner ElementBuffer
>class.  Wups.

:-)

>Roman, comparing the one I wrote to the one you wrote, I think your
>second argument to replace is wrong ... no Elements are being removed
>here since the just-created BranchElement has no children.  I think it
>should be branchClone.replace(0, 0, cloneChildren).

Of course you are right. This came from my playing around with clone().
My first attempt tried to clone() the elements and then call replace()
which would have needed to first remove some children. Unfortunately
this does not work because we are not allowed to call clone() on an
interface (Element). So I wrote special impls for the know classes. BTW,
we should add SectionElement (and maybe even some text.html element
impls?), so that they are created using the correct type.


>If you agree, can you fix this?  And could you remove the one I wrote at
>the same time?

Both committed using the attached fix.

2006-02-13  Roman Kennke  <[EMAIL PROTECTED]>

        * javax/swing/text/DefaultStyledDocument.java
        (ElementBuffer.clone): Fixed replace call.
        (clone): Removed method.

/Roman
Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.60
diff -u -r1.60 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java	10 Feb 2006 15:09:55 -0000	1.60
+++ javax/swing/text/DefaultStyledDocument.java	13 Feb 2006 17:19:56 -0000
@@ -671,7 +671,7 @@
               cloneChildren[i] = clone(branchClone,
                                        branchClone.getElement(i));
             }
-          branchClone.replace(0, numChildren, cloneChildren);
+          branchClone.replace(0, 0, cloneChildren);
           clone = branchClone;
         }
       else if (clonee instanceof LeafElement)
@@ -1437,40 +1437,6 @@
     
     return curr;
   }
-
-  /**
-   * Creates a copy of the element <code>clonee</code> that has the parent
-   * <code>parent</code>.
-   * 
-   * @param parent
-   *          the parent of the newly created Element
-   * @param clonee
-   *          the Element to clone
-   * @return the cloned Element
-   */
-  public Element clone(Element parent, Element clonee)
-  {
-    // If the Element we want to clone is a leaf, then simply copy it
-    if (clonee.isLeaf())
-      return createLeafElement(parent, clonee.getAttributes(),
-                               clonee.getStartOffset(), clonee.getEndOffset());
-
-    // Otherwise create a new BranchElement with the desired parent and
-    // the clonee's attributes
-    BranchElement result = (BranchElement) createBranchElement(
-                                                               parent,
-                                                               clonee.getAttributes());
-
-    // And clone all the of clonee's children
-    Element[] children = new Element[clonee.getElementCount()];
-    for (int i = 0; i < children.length; i++)
-      children[i] = clone(result, clonee.getElement(i));
-
-    // Make the cloned children the children of the BranchElement
-    result.replace(0, 0, children);
-    return result;
-  }
-
   /**
    * Instance of all editing information for an object in the Vector. This class
    * is used to add information to the DocumentEvent associated with an

Reply via email to