Package org.faceless.pdf2.viewer2.util
Class RichTextTransferHandler
- java.lang.Object
-
- javax.swing.TransferHandler
-
- org.faceless.pdf2.viewer2.util.RichTextTransferHandler
-
- All Implemented Interfaces:
Serializable
public class RichTextTransferHandler extends TransferHandler
A
TransferHandler
that can copy/paste RichText. The default TransferHandler on a JEditorPane can't copy RichText, and pasting it will insert it at the end of the document rather than at the caret (because RTFEditorKit ignores the "pos" attribute in read).This isn't a perfect solution - in particular the following faults exist:
- pasting into the middle of a document always appends a line-feed - but it is an improvement.
- pasting RTF DataFlavor into HTMLDocument puts weird spaces in place, and deleting those spaces isn't possible as it deletes the text instead.
Tested on Windows and OS X for copying/pasting between plain, RTF and HTML JEditorPanes with or without the handler, and also testing paste in from and copy out to external application.
Also works with TextTool to allow copying of styled text.
- See Also:
- Serialized Form
-
-
Nested Class Summary
Nested Classes Modifier and Type Class Description static class
RichTextTransferHandler.RichTransferable
Transferable class that can transfer Rich-Text as plain, RTF or HTML.-
Nested classes/interfaces inherited from class javax.swing.TransferHandler
TransferHandler.DropLocation, TransferHandler.TransferSupport
-
-
Field Summary
-
Fields inherited from class javax.swing.TransferHandler
COPY, COPY_OR_MOVE, LINK, MOVE, NONE
-
-
Constructor Summary
Constructors Constructor Description RichTextTransferHandler()
-
Method Summary
All Methods Instance Methods Concrete Methods Modifier and Type Method Description boolean
canImport(JComponent c, DataFlavor[] f)
protected Transferable
createTransferable(JComponent c)
int
getSourceActions(JComponent c)
boolean
importData(JComponent c, Transferable tran)
-
Methods inherited from class javax.swing.TransferHandler
canImport, exportAsDrag, exportDone, exportToClipboard, getCopyAction, getCutAction, getDragImage, getDragImageOffset, getPasteAction, getVisualRepresentation, importData, setDragImage, setDragImageOffset
-
-
-
-
Method Detail
-
canImport
public boolean canImport(JComponent c, DataFlavor[] f)
- Overrides:
canImport
in classTransferHandler
-
importData
public boolean importData(JComponent c, Transferable tran)
- Overrides:
importData
in classTransferHandler
-
createTransferable
protected Transferable createTransferable(JComponent c)
- Overrides:
createTransferable
in classTransferHandler
-
getSourceActions
public int getSourceActions(JComponent c)
- Overrides:
getSourceActions
in classTransferHandler
-
-