I implemented the method ElementBuffer.clone in DefaultStyledDocument,
one of the remaining missing methods in javax.swing.text.
2005-11-08 Anthony Balkissoon <[EMAIL PROTECTED]>
* javax/swing/text/DefaultStyledDocument.java:
(ElementBuffer.clone): New API method.
--Tony
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 <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;
+ }
}
/**
_______________________________________________
Classpath-patches mailing list
[email protected]
http://lists.gnu.org/mailman/listinfo/classpath-patches