Transferring Data Between Applications Handling the system clipboard - - PowerPoint PPT Presentation

transferring data between applications
SMART_READER_LITE
LIVE PREVIEW

Transferring Data Between Applications Handling the system clipboard - - PowerPoint PPT Presentation

Transferring Data Between Applications Handling the system clipboard Drag-and-Drop operations Data transfer classes Data Transfer GUI architectures require a mechanism to Drag-drop is move data between application windows. expected with


slide-1
SLIDE 1

Transferring Data Between Applications

Handling the system clipboard Drag-and-Drop operations Data transfer classes

slide-2
SLIDE 2

Data Transfer

§ Two primary methods evolved to enable “user-interface level data

transfer”

  • Clipboard: copy, cut, paste operations to a system-wide storage

area (’clipboard’) that is used to transfer data.

  • Drag-and-drop: drag data directly from one view/application

window to another.

§ They are different mechanisms that attempt to address some of the

same problems (and there’s overlap in implementations).

2

§ GUI architectures require a mechanism to

move data between application windows.

§ Ideally, something that aligns well with

direct-manipulation principles

  • e.g. select data, drag-to-move it

elsewhere

Drag-drop is expected with direct manipulation interfaces

slide-3
SLIDE 3

Clipboard Transfer

§ We want to copy-paste data between applications, so the clipboard

need to be managed at the system level.

§ Data transfer method using a generic data buffer

  • Copy/Cut data from document to clipboard
  • Paste data from clipboard to document

§ Issues that arise

  • Is access to clipboard contents a potential security risk?
  • How to you handle different data, and different formats, between

applications? e.g. text, image, data table, HTML, SVG.

3

slide-4
SLIDE 4

Clipboard Supported Data Formats

Sender and Receiver negotiate the data format

§ When data is placed on clipboard (cut/copy), the sender indicates the data

formats that it can support

§ When data is retrieved (paste) by the receiver, it can request a list of supported

formats and then specifically request the data in a supported format. All requests are routed through the system clipboard! There are a wide variety of formats that are handled this way:

§ Formatted text like HTML, RTF, MS Office, … § Vector-based drawing? (SVG, Illustrator, …) § Images in different file formats (JPG, PNG, TIF, …) § PostScript/PDF drawings? § Tables? Charts? Grouped objects? Filters? § Proprietary graphics formats? (Photoshop layers) § 3D meshes? Video?

4

slide-5
SLIDE 5

JavaFX Classes

5

javafx.scene.input.Clipboard

Represents an operating system clipboard, on which data may be placed during, for example, cut, copy, and paste operations.

javafx.scene.input.ClipboardContent

Data container for Clipboard data. It can hold multiple data in several data formats.

javafx.scene.input.DataFormat

Data format identifier used as means of identifying the data stored

  • n a clipboard/dragboard.
slide-6
SLIDE 6

Copying Data to the Clipboard

6

1.

Get a reference to the system clipboard.

2.

Create a clipboard content instance to hold the data (it’s a map, with each named method storing a particular representation of data).

3.

Store the content on the clipboard.

You should put LOTS of different formats on the clipboard.

slide-7
SLIDE 7

Pasting Data from the Clipboard

7

1.

Get a reference to the system clipboard.

2.

If your desired format exists on the clipboard, fetch the data directly.

3.

You can also fetch and iterate through the list of data formats (e.g. HTML, IMAGE) and then decide which one to fetch.

slide-8
SLIDE 8

Drag-and-Drop

8

§ User clicks-and-drags the source window

  • Mouse drag listener needs to be setup to start the drag operation

§ User drops on the destination window

  • Receiving operation needs to define nodes that will handle the drop
  • peration (e.g. window below)
slide-9
SLIDE 9

Receiving a Drag-and-Drop Operation

9

§ Any node in JavaFX can accept drag-and-drop data from another

application through the supported event handler mechanism (see

DragBoard below).

§ Node method setOnDragOver() needs to be overridden and

implemented to handle the drop on the receiving application.

§ Data is transferred as a file from the sending application.