Index: javax/swing/text/DefaultStyledDocument.java =================================================================== RCS file: /cvsroot/classpath/classpath/javax/swing/text/DefaultStyledDocument.java,v retrieving revision 1.16 diff -u -r1.16 DefaultStyledDocument.java --- javax/swing/text/DefaultStyledDocument.java 4 Nov 2005 22:50:03 -0000 1.16 +++ javax/swing/text/DefaultStyledDocument.java 8 Nov 2005 16:40:02 -0000 @@ -772,6 +772,34 @@ } offset += len; } + + /** + * Creates a copy of the element clonee that has the parent + * parent. + * @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; + } } /**