I added the missing ElementBuffer.clone() method.

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

        * javax/swing/text/DefaultStyledDocument.java
        (ElementBuffer.clone): New method.

/Roman
Index: javax/swing/text/DefaultStyledDocument.java
===================================================================
RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v
retrieving revision 1.59
diff -u -r1.59 DefaultStyledDocument.java
--- javax/swing/text/DefaultStyledDocument.java	7 Feb 2006 12:17:41 -0000	1.59
+++ javax/swing/text/DefaultStyledDocument.java	10 Feb 2006 15:08:56 -0000
@@ -643,6 +643,47 @@
     }
 
     /**
+     * Creates and returns a deep clone of the specified <code>clonee</code>
+     * with the specified parent as new parent.
+     *
+     * This method can only clone direct instances of [EMAIL PROTECTED] BranchElement}
+     * or [EMAIL PROTECTED] LeafElement}.
+     *
+     * @param parent the new parent
+     * @param clonee the element to be cloned
+     *
+     * @return the cloned element with the new parent
+     */
+    public Element clone(Element parent, Element clonee)
+    {
+      Element clone = clonee;
+      // We can only handle AbstractElements here.
+      if (clonee instanceof BranchElement)
+        {
+          BranchElement branchEl = (BranchElement) clonee;
+          BranchElement branchClone =
+            new BranchElement(parent, branchEl.getAttributes());
+          // Also clone all of the children.
+          int numChildren = branchClone.getElementCount();
+          Element[] cloneChildren = new Element[numChildren];
+          for (int i = 0; i < numChildren; ++i)
+            {
+              cloneChildren[i] = clone(branchClone,
+                                       branchClone.getElement(i));
+            }
+          branchClone.replace(0, numChildren, cloneChildren);
+          clone = branchClone;
+        }
+      else if (clonee instanceof LeafElement)
+        {
+          clone = new LeafElement(parent, clonee.getAttributes(),
+                                  clonee.getStartOffset(),
+                                  clonee.getEndOffset());
+        }
+      return clone;
+    }
+
+    /**
      * Inserts new <code>Element</code> in the document at the specified
      * position. Most of the work is done by [EMAIL PROTECTED] #insertUpdate}, after some
      * fields have been prepared for it.

Reply via email to