Cut and paste mechanism in Java
Cut and paste uses the clipboard to copy a certain part of a document. Data is transferred from one part of a document to the clipboard and later it is transferred from the clipboard to another place of this or another cocument.
Cut, copy and paste actions and methods
In the javax.swing packages there are predefined actions one can use to add cut and paste to an application in an 'Edit' menu for instance. DefaultEditorKit.CutAction, DefaultEditorKit.CopyAction and DefaultEditorKit.PasteAction already deliver functionality by calling a target object's cut , copy and paste methods.
Class JTextComponent , which is a superclass to JEditorPane, in turn implements these methods to perform the actual cut and paste on a Document connected to that JTextComponent.
How data is transported
To be able to transport data regardless of its type, the Java language has an object Transferable which one has to use or design to certain needs. Transferables make use of DataFlavors to inform about the data types they support. Transport of Transferables in cut and paste operations is done through Clipboard objects.
Extending the mechanism
Unfortunately this mechanism is not extended by class JEditorPane for the transport of HTML during cut and paste operations. JEditorPane is limited to plain text in cut and paste operations even when its content type is set to text/html. SimplyHTML therefore extends JEditorPane with class SHTMLEditorPane overriding its cut, copy and paste methods so that cut and paste including styles and HTML specific parts is possible.