Version 15 (modified by vlado, 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 ctrl 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 transferring 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 transferring 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:
- Resources - 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.
- http://en.wikipedia.org/wiki/Clipboard_(software)
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 transferring plain text (this will not keep the formating):
- from the text frame to the Clipboard.
- from the Clipboard into a text frame.
- If some text is previously selected this will replace the selection with the text from the Clipboard.
- Otherwise the text from the Clipboard will be inserted at the position the caret appears.
- from the Clipboard outside Sophie 2.0 - in another text control:
- for example into a browser or a text editor. Behavior is defined by that control.
- 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.
- Cut operation will be implemented as Copy followed by a Delete operation. The eventual Paste is arbitrary.
- In addition three more menu items should be added in the Edit menu:
- CutMenuItem
- CopyMenuItem
- PasteMenuItem
- All these should be active and inactive depending on the operation performed:
- Paste menu is inactive by default. It will be activated when there is something put into the Clipboard.
- Cut and Copy will be activated when there is something selected. For the time being selection will be limited to text and images(optionally).
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
The overall idea of the design is to cover and wrap all data, Transferables and Clipboard operations into our own classes. This would allow better extensibility, customizations for multiple types suitable to the needs of Sophie2 and better abstraction.
- A new package org.sophie2.base.dnd will be created.
- The following new classes will be defined:
- ClipboardManager - a Singleton class used to wrap the functionality for Cut/Copy/Paste operations with data and the work with the Clipboard. the System Clipboard will be used for now, but the abstraction allows to add special Clipboard functionality later (e.g. multiple custom clipboards created by name, allowing to switch between them)
- DnDData hierarchy - wraps the data needing serialization/deserialization along with information about the wanted DataFlavor (DataFlavor usage is hidden from the client code).
- DnDTransferable - contains the different representaions in which data could be serialized/deserialized, including its supported types. Implements the actual mapping data to DataFlavor.
- TransferableConverter - a Utility class providing functionality to convert from DnDTransferable to Transferable and vice-versa.
- DnDDataProvider interface and its implementor SimpleDnDDataProvider - defines Sophie extension for creation of DnDData objects.
- The following operations are supported:
- Copy
- Workflow
- A specific Logic receives Copy(or DragOut) notification.
- A List of DnDData is generated using the DnDDataProvider and the event data.
- A DnDTransferable is created and set as content to the ClipboardManager.
- It converts DnDTransferable to Transferable through the TransferableConverter class.
- The Java Transferable is sent to the Clipboard for serialization of the data.
- Usability.
- Can be initiated(fired) from:
- 'Edit' -> 'Copy' menu item
- Keyboard shortcuts as specified in Analysis#Overview
- Supported Copy locations
- Scene
- Right Flap -> Resources
- Left Flap -> Pages
- LeftFlap -> Books
- Outside Sophie2
- Can be initiated(fired) from:
- Workflow
- Paste
- Workflow
- A specific Logic receives Paste(or Drop) notification.
- Logic asks ClipboardManager for the current DnD contents (represented as DnDTransferable)
- ClipboardManager asks Clipboard for the current data contents (represented as Transferable)
- Transferable is acquired from the Clipboard after deserialization of the data.
- ClipboardManager converts Transferable to DnDTransferable through the TransferableConverter class.
- Logic receives DnDTransferable.
- DnDTransferable is asked for DnDData object corresponding to the first of the possible classes which the target of the Paste operation supports.
- Logic updates the model with the DnDData content.
- Usability.
- Can be initiated(fired) from:
- 'Edit' -> 'Paste' menu item
- Keyboard shortcuts as specified in Analysis#Overview
- Supported Copy locations
- Scene
- Right Flap -> Resources
- Left Flap -> Pages
- LeftFlap -> Books
- Outside Sophie2
- Can be initiated(fired) from:
- Workflow
- Cut - implemented as Copy + Delete (which is the typical behavior)
- Copy
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.)