Version 10 (modified by peko, 16 years ago) (diff) |
---|
Analysis
Overview
- This task is about the base Drag'N'Drop implementation. Sophie 2.0 should be able to provide a relatively complex DnD behavior. In addition the DND implementation should be consistent to behave properly with the Scene and VisualElements. What is more, the DND is tightly connected with the clipboard.
- The DND allows three main operations:
- COPY
- MOVE
- LINK
- While performing these operations the mouse cursor should change accordingly. Generally they are invoked by keyboard combinations that include the cntrl and shift keys. There is also a default operation that is invoked by just dragging without another key pressed.
- The clipboard allows the following operations:
- CUT
- COPY
- PASTE
- These are performed by keyboard combinations as follow:
- Windows and Linux:
- Ctrl + x is cut
- Ctrl + c is copy
- Ctrl + v is paste
- Alternative:
- Ctrl-Insert is copy
- Shift-Delete is cut
- Shift-Insert is paste
- Macintosh Operating System:
- Command-c to copy data into the clipboard
- Command-x to cut into it
- Command-v
- General requirements for all the revisions should combine the following things:
- DnD and Clipboard should allow the user to manipulate data and transfer it in and outside sophie. What is more, it should allow transfering data between several opened Sophies.
- For an overview of DnD transfers inside Sophie 2.0 you can use the following table: http://spreadsheets.google.com/ccc?key=p-0Oq38E1aysuTs69KE68Nw&hl=en
- Another such table should be provided for the Clipboard behavior.
- DnD and Clipboard should allow the user to manipulate data and transfer it in and outside sophie. What is more, it should allow transfering data between several opened Sophies.
- DnD and Clipboard should be able to transfer the following things (some more may be added later):
- Strings
- Serialized objects
- Files
- Sophie Objects:
- Resourses - generally speaking.
- Frames (Image, Text, Media frames)
- Pages
- Embedded books
- etc.
- May include the buttons that are dragable (for resizing the Page, moving the Frame etc.) - this is optional since we already have some implementaion for dragging these buttons.
* New tables should be defined:
- A table for possible DnD transfers and scenarios.
- A table for possible Clipboard transfers and scenarios.
Task requirements
- For the current revision we will consider implementing a base Clipboard functionality. This include the following:
- base Clipboard library that support the clipboard operations.
- It should allow transfering plain text:
- from the text frame to the Clipboard.
- from the Clipboard into a text frame.
- from the Clipboard outside Sophie 2.0 - in another text control:
- for example into a browser or a text editor.
- Optional transfers (if there is time left):
- transfers of images from and to Sophie 2.0:
- this is connected with the Image frames.
- transfers of images from and to Sophie 2.0:
- A module containing the base library should be created.
- Use cases from above should be implemented into other modules.
Task result
- source code:
- base library - a module
- implementation in other modules
- unit test for the base library.
- UML diagram
- Another table describing the Clipboard possible transfers. (see link above for such a table about the DnD transfers).
Implementation Idea
- Research how Clipboard works in Java.
- Define the behavior of Clipboard in Sophie 2.0 using the possible transfers table.
- Create the base library.
Related
- Old wiki:
- AUTHOR_PAGE_WORK_AREA_R0 - should be responsible for processing clipboard operations.
- READER_PAGE_WORK_AREA_R0 - should be responsible for processing clipboard operations.
How to demo
- Open Sophie 2.0
- demostrate the scenarios described in the Task Requirements section.
Design
General things
- Drag and Drop should be able to transfer things from Source to Target.
- Both Source and Target should be able to export and import different types of data, called DataFlavor.
- As of Java 1.4, dragging and dropping things is done through the so called TransferHandler.
- it is responsible for initiating a drag, accepting a drop and changing the UI correspondingly (changing the mouse cursor depending on the action performed - COPY, MOVE, LINK.)
- the TransferHandler need a JComponent in order to detect drag and drop gestures. It is usually enough for a simple Java application, since it transfers text, images, files etc. almost on the fly.
- the drag and drop mechanism in Java is quite complicated since it can be done in two ways which is sometimes misleading.
- We need to define three things in order to be able to perform Drad and Drop. The things below are enough to create a library that can provide drag and drop.
- SophieTransferHandler
- Transferable
- DataFlavor
SophieTransferHandler
- a class representing a TransferHandler similar to the one described above. It can wrap the one in Java and use part of the methods.
- It will be responsible for:
- initiating a drag.
- accepting a drop.
- changing the cursor.
- dropping something.
- It will be responsible for:
- Wrapping the TransferHandler in Java will help us with the cursor and the drag and drop gestures.
- We need to following methods to perform a drag and drop operation:
- protected abstract boolean canDropIn(Transferable transferable); - should tell whether a drop is acceptable provided a Transferable with a DataFlavor.
- protected abstract boolean dropIn(Transferable transferable, DropLocation dropLocation, int dropAction); - should perform the actual drop. The Data is contained in the Transferable.
- protected abstract Transferable createTransferable(); - creates the actual Transferable.
- protected abstract void transferDone(Transferable data, int action); - invoked after the transfer has been performed.
- The SophieTransferHandler should be provided a JComponent and set such so that Drad and Drop gestures are recognized from it.
- Transferring of data will be done by creating Transferables.
- SophieTransferHandler should be extended and defined for most UI components that support drag and drop (Palettes, BookDesktop etc.) - for example in an inner class and an AutoProperty that depends on the JComponent of a Palette one can create a handler and latter change the Palette's model if a drop operation is performed.
Transferables
- provides information about the drag operation.
- type of data transferred - through DataFlavor constants.
- may provide more than one type of data, depending on the number of DataFlavors supported.
- contains the data transferred - obtained through the DataFlavor.
- We should define several Transferables:
- FileTransferable - responsible for Transferring of files. Transferring of files between the OS and Sophie will not create such but it will be useful for transferring inside Sophie.
- ResourceTransferable - it should have some implementing classes for pages, frames etc.
- we may later need to define more.
DataFlavor
- Used to unify the types of data a drag and drop operation should deal with.
- There are some DataFlavors defined in the Java library.
- For some things we need to define DataFlavors.
- FrameResources.
- BookResources.
- and other depending on what other drag and drop operations will be implemented.
Note: Some DataFlavors are not created properly in different platforms despite the idea of being so. For example dragging and dropping of files works fine on windows (the system uses the DataFlavor.javaFileListFlavor flavor) while it does not in gnome (creating different flavor usually with text/uri-list mime type). So be careful when using the Transferables and DataFlavors.
Implementation
(Implementation results should be described and linked here (from the wiki or the repository))
Testing
Comments
(Write comments for this or later revisions here.)