Dn d clipboard

969 views
889 views

Published on

0 Comments
0 Likes
Statistics
Notes
  • Be the first to comment

  • Be the first to like this

No Downloads
Views
Total views
969
On SlideShare
0
From Embeds
0
Number of Embeds
2
Actions
Shares
0
Downloads
5
Comments
0
Likes
0
Embeds 0
No embeds

No notes for slide

Dn d clipboard

  1. 1. SWT Drag-N-Drop & Clipboard Praveen Innamuri
  2. 2. Agenda <ul><li>Drag & Drop </li></ul><ul><ul><li>Drag Source </li></ul></ul><ul><ul><li>Drop Target </li></ul></ul><ul><ul><li>Drag/Drop Events and Operations </li></ul></ul><ul><ul><li>Feedback </li></ul></ul><ul><li>Transfer Types </li></ul><ul><li>Defining your own Transfer Type </li></ul><ul><li>Clipboard </li></ul><ul><ul><li>Primary Clipboard vs Selection Clipboard </li></ul></ul><ul><ul><li>Setting/Getting multiple content types altogether </li></ul></ul>
  3. 3. Dragging and Dropping.....
  4. 4. Drag and Drop <ul><li>What is the use of Drag-N-Drop ? </li></ul><ul><li>Entities in Drag-N-Drop : </li></ul><ul><ul><li>DragSource. </li></ul></ul><ul><ul><li>DropTarget. </li></ul></ul><ul><ul><li>Transfer data - Text/Image. </li></ul></ul><ul><ul><li>Kind of drag/drop actions - Move/Copy/Link. </li></ul></ul><ul><ul><li>Interaction between DragSource and DropTarget. with drag-and-drop operation using listeners. </li></ul></ul>
  5. 5. Type of Drop Operations <ul><ul><li>int operations = DND.DROP_MOVE | DND.DROP_COPY; DragSource source = new DragSource(label, operations); </li></ul></ul><ul><li>DROP_COPY </li></ul><ul><li>DROP_MOVE Data is moved from source to target </li></ul><ul><li>DROP_LINK A link of data is created at target </li></ul><ul><li>DROP_TARGET_MOVE Applicable to non-SWT applications </li></ul><ul><li>DROP_DEFAULT </li></ul><ul><li>DROP_NONE </li></ul>
  6. 6. Transfer Types Transfer[] types = new Transfer[] {TextTransfer.getInstance()}; source.setTransfer(types);
  7. 7. DragSourceEvent <ul><li>public int detail; // Move, Copy, Link, None etc. </li></ul><ul><li>public boolean doit; //true or false </li></ul><ul><li>public TransferData dataType; //data that is transferred </li></ul><ul><li>public Image image; //DragSourceEffect </li></ul>DropTargetEvent <ul><li>public int detail; //choose from operations </li></ul><ul><li>public int operations; //(DROP_NONE, DROP_MOVE etc..) </li></ul><ul><li>public int feedback; //feedback_insert/expand/scroll etc. </li></ul><ul><li>public TransferData currentDataType; //type of data that will be dropped </li></ul><ul><li>public TransferData[] dataTypes; //all supported data types by source </li></ul>
  8. 8. DragSourceListener – Events of DragSource <ul><li>DragStart : </li></ul><ul><ul><li>Notified when the drag is started at drag source. </li></ul></ul><ul><ul><li>Cancel the operation if no valid items are currently selected. </li></ul></ul><ul><ul><li>One can defer to set the transfer type in this event. </li></ul></ul><ul><ul><li>DragSourceEffect : Provide custom image to the drag cursor. </li></ul></ul><ul><li>DragSetData : </li></ul><ul><ul><li>Invoked when the data is requested. </li></ul></ul><ul><ul><li>Once the operation is started, it has to provide the requested data, otherwise, DnD contract is violated. </li></ul></ul><ul><li>DragFinished : </li></ul><ul><ul><li>Perform any cleanup operation after the drag is finished depending upon the event.detail and event.doit fields. Also used for cleaning DragSourceEffect. </li></ul></ul><ul><ul><li>Example: handle refresh if it is TARGET_MOVE, or delete data for DROP_MOVE </li></ul></ul>
  9. 9. DropTargetEffect : Feedback Options <ul><li>FEEDBACK_NONE </li></ul><ul><li>FEEDBACK_SELECT </li></ul><ul><li>FEEDBACK_INSERT_BEFORE </li></ul><ul><li>FEEDBACK_INSERT_AFTER </li></ul><ul><li>FEEDBACK_SCROLL </li></ul><ul><li>FEEDBACK_EXPAND </li></ul>
  10. 10. Drop Target Events <ul><li>DragEnter </li></ul><ul><ul><li>Indicates that cursor enters the bounds of the drop target widget. </li></ul></ul><ul><ul><li>Generally used for initializing any data. </li></ul></ul><ul><ul><li>Can modify : c urrentDataType – modify the data type detail – when DND.DROP_DEFAULT is set ? Feedback – provides a default drag under effect for the feedback. </li></ul></ul><ul><ul><li>Can not modify : dataTypes, operations </li></ul></ul><ul><li>DragOver </li></ul><ul><ul><li>Occurs when the user drags the cursor over the drop target widget. </li></ul></ul><ul><ul><li>This is mostly used with widgets like Tree, or Table for modifying feedback as the cursor moves over various item types. </li></ul></ul><ul><ul><li>To control drop operation if the drop is going to happen on a invalid item. </li></ul></ul>
  11. 11. Drop Target Events (contd......) <ul><li>DragOperationChange </li></ul><ul><ul><li>This event occurs when the user presses or releases a modifier key (such as Ctrl, Shift, Command, Option). </li></ul></ul><ul><ul><li>Can change : CurrentDataType,detail, Feedback </li></ul></ul><ul><ul><li>have access to : dataTypes, operations. </li></ul></ul><ul><li>DragLeave </li></ul><ul><ul><li>This is invoked when the cursor moves outside of the drop target widget, or if the user cancels the Drag and Drop operation by hitting Escape, or just before a drop is performed. </li></ul></ul><ul><ul><li>Used for cleaning up the code the initialized data in dragEnter. </li></ul></ul><ul><ul><li>Example : StyledText sets back it's cursor to it's original position. </li></ul></ul>
  12. 12. Drop Target Events (contd......) <ul><li>DropAccept </li></ul><ul><ul><li>This event provides the application with one last chance to define the type of data that will be returned in the drop event. </li></ul></ul><ul><ul><li>Example : StyledText sets the position for dropping the data. </li></ul></ul><ul><ul><li>Can Modify : currentDataType, detail. </li></ul></ul><ul><li>Drop </li></ul><ul><ul><li>This occurs when the user releases the mouse over the drop target if a valid operation and currentDataType. </li></ul></ul><ul><ul><li>Example : StyledText paste the content; Tree adds the new item. </li></ul></ul><ul><ul><li>It still can cancel the operation through event.detail field if there is a failure while processing the drop operation. </li></ul></ul>
  13. 13. Possible sequence of Events.. <ul><li>DragSourceEvents - </li></ul><ul><ul><li>dragStart </li></ul></ul><ul><ul><li>dragStart, one or more dragSetData, dragFinished </li></ul></ul><ul><ul><li>dragStart, dragFinished </li></ul></ul><ul><li>DropTargetEvents - </li></ul><ul><ul><li>dragEnter, dragLeave </li></ul></ul><ul><ul><li>dragEnter, one or more dragOver *, dragLeave </li></ul></ul><ul><ul><li>dragEnter, one or more dragOver *, dragLeave, dropAccept </li></ul></ul><ul><ul><li>dragEnter, one or more dragOver *, dragLeave, dropAccept, drop </li></ul></ul><ul><ul><li>*may be a mixture of dragOver and dragOperationChanged </li></ul></ul>
  14. 14. Defining Own Transfer Type <ul><li>Extend existing predefine transfer types : ByteArrayTransferType </li></ul><ul><li>Methods to override : </li></ul><ul><ul><li>Create a unique type name for describing the type of data. </li></ul></ul><ul><ul><li>Register the typeName to get a unique ID. </li></ul></ul><ul><ul><li>JavaToNative (Object object, TransferData transferData) </li></ul></ul><ul><ul><ul><li>Converts a java representation of data to a platform specific representation of the data. </li></ul></ul></ul><ul><ul><li>NativeToJava (TransferData transferData) </li></ul></ul><ul><ul><ul><li>Converts a platform specific representation of data to a java representation. </li></ul></ul></ul><ul><ul><li>GetTypeNames() </li></ul></ul><ul><ul><li>GetTypeIds() </li></ul></ul>
  15. 15. Clipboard <ul><li>Selection vs Primary Clipboard </li></ul><ul><li>Setting clipboard contents – multiple data types can be set together at once. </li></ul><ul><li>Querying existing data types in the clipboard </li></ul><ul><li>Clearing the clipboard </li></ul><ul><li>Retrieving the clipboard contents. Clipboard clipboard = new Clipboard(display); String textData = &quot;Hello World&quot;; String rtfData = &quot;{tf1 Hello World}&quot;; TextTransfer textTransfer = TextTransfer.getInstance(); RTFTransfer rtfTransfer = RTFTransfer.getInstance(); Transfer[] transfers = new Transfer[]{textTransfer, rtfTransfer}; Object[] data = new Object[]{textData, rtfData}; clipboard.setContents(data, transfers); clipboard.dispose(); </li></ul>
  16. 16. Thank YOU Q & A ?

×