Clipboard and Drop-and-Drop
- Enables "user-interface level data transfer" within and in between applicatins
Clipboard - copy, cut, paste
Drag-and-Drop - drag data from one view/application to another
Clipboard Transfer
Uses a system-level generic data buffer
- Copy/Cut data from document to clipboard
- Paste data from clipboard to document
When a data is placed on a clipboard, application indicates formats
- e.g. vector image, bitmap image, text etc.
Also need to deal with
- Formatted text (HTML, RTF, MS Office)
- Vector-based rawing
- Different format images
- PostScript/PDF drawing?
- MacOS Human Interface Guidelines specify all application must
- At least support plaintext or image on clipboard
- At least accept plaintext or image from clipboard
Java Clipboard API
- Key classes
Clipboard
,DataFlavor
,Transferable
,ClipboardOwner
Supports local and system clipboards
- Local clipboards are named clipboards holding data only accessible by the application
- System clipboard is operating-system-wide clipboard
See slide for sample code
Transferable Object
- Encapsulates all data to copy
Data formats are called "flavours"
See slide for sample code
Drag-and-Drop
- Also uses Transferable, DataFlavor objects
- Attach a TransferHandler to each widget to manage data transfer
- Need to detect the start-of-drag gesture
Supporting Drop
Pasting data into your widget at end of drag
Create a TransferHandler
Override TransferHandler.importData method
Set the TransferHandler on the widget
See the slides for sample code
Supporting Drag
Copying data out of your widget at start of drag
Create a TransferHandler
Override createTransferable with data Transferable
- Set the TransferHandler on the widget
- Define a mouse listener that knows when drag starts
On drag, get widget's transfer handler and call exportAsDrag
See slides for sample code