wiki:BASE_DND_R0
Last modified 16 years ago Last modified on 06/01/09 19:25:23

Error: Macro BackLinksMenu(None) failed
compressed data is corrupt

Error: Macro TicketQuery(summary=BASE_DND_R0, format=table, col=summary|owner|status|type|component|priority|effort|importance, rows=description|analysis_owners|analysis_reviewers|analysis_score|design_owners|design_reviewers|design_score|implementation_owners|implementation_reviewers|implementation_score|test_owners|test_reviewers|test_score|) failed
current transaction is aborted, commands ignored until end of transaction block

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.
  • 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:

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.
  • 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.

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 system Clipboard internally. 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 etc.)
    • DndData hierarchy - wraps the transferred data. It is connected internally with the system clipboard data through DataFlavors. (DataFlavor usage is hidden from the client code).
    • DndTransferable - an interface, representing the common functionality of the different implementations of transferables.
      • BaseDndTransferable is a class that implements most of DndTransferable. See the javadoc for more info.
    • DndProvider is an interface that defines Sophie extension point for creation of DndData objects. Every DndData would have a corresponding DndProvider that creates the DndData. Extensions will be defined only for DndData that come from AWT.
    • AwtTransferable and SophieTransferable are the BaseDndTransferable implementations. The AwtTransferable is a BaseDndTransferable for transferring data that comes from AWT to Sophie, as opposed to SophieTransferable which transfers that to Sophie and to Awt. This is needed since we need a way to convert transfers from awt to out own transfers. The AwtTransferable is not suppossed to be inherited. If one wants to provide support for additional DndData, they should implement is and implement a corresponding DndProvider. See ImageData and StringData for more information. The SophieTransferable on the other hand should be implemented and should add the DndData that it supports. In addition the deleteOriginal method should be implemented in case the user performs CUT operation.
      • The AwtTransferable is an adapter for awt Transferables.
      • The SophieTransferable delegates to a awt Trasnferable and awt as a whole.
    • DndData:
      • The DndData implementations should differ in the way they are used. If a DndData is created inside Sophie2.0 in a SophieTransferable, it should override the exportToAwt method in order to provide the data needed for an AWT Transferable. If it is used inside Sophie2.0 and comes from awt one is not supposed to use this method and not implement it at all. Instead they will obtain data through a corresponding method typical for every DndData instance (for StringData it is the getContents method). This make the DndData class slightly dual, but will make easier implementing new transfers of data.

source:/trunk/sophie2-platform/doc/uml-design-diagrams/base-dnd-uml.png

  • Available transfers: http://spreadsheets.google.com/ccc?key=r4yyW_VIrTvloMDKwpfWtag
  • The following operations are supported:
    • Cut - implemented as Copy + Delete (which is the typical behavior). The deleteOriginal method of SophieTransferable instances should be overridden. For AwtTrasferable we need NOT implement such, because it is handled by AWT or OS.
  • Handling for Cut/Copy/Paste keyboard shortcuts should be added - interaction maps for VisualElements and using the already implemented interaction of the Scene.
  • Menu items for Cut/copy/Paste surrounded by separators would be added in next revision. The ClipboardManager is already a BaseProObject but it is time consuming to provide implementations for menus here, since we do not have most of the interaction implemented.
  • Design related code:

Design related code merged into the trunk in [3018].

Implementation

  • Done:
    • A HotTextTransferable created for transfers of HotText. For the time being it transfers StringData. In future it should be able to transfer even more complicated DndData (hot text, html, formatted text etc implementations of the DndData). It transfers plain text between sophie text frames and other application as well.
  • 3017
  • 3028
  • 3029
  • 3030
  • Comments:
    • Should consider implementing a CUT/COPY/PASTE operations for resources.

Merged to the trunk in [3046].

Testing

Comments

(Write comments for this or later revisions here.)