Package limn.backend
Interface Clipboard
- All Known Implementing Classes:
PlatformClipboard
public interface Clipboard
The system clipboard: what the user last copied, in this application or another, in every
format it was offered in.
Text has the two direct calls every text control uses, text() and setText(java.lang.String).
Anything richer is a Transfer going in and an Offer coming out:
clipboard.set(Transfer.of(DataFormat.IMAGE, chart).with(DataFormat.TEXT, title));
Offer there = clipboard.content();
if (there.has(DataFormat.IMAGE)) {
there.read(DataFormat.IMAGE).thenAccept(attachment::setImage);
}
UI thread only, like everything a scene hands out, and what it answers arrives there.
A worker that has something for the clipboard posts it with Ui.post.
-
Field Summary
Fields -
Method Summary
Modifier and TypeMethodDescriptioncontent()What the clipboard holds now.static ClipboardinMemory()A clipboard that is only memory: what is set is what is read, and no other program is involved.Hears the clipboard's content change, whoever changed it, where the platform tells.voidReplaces what the clipboard holds.default voidPuts text, and nothing else, on the clipboard.text()The clipboard's text, now.
-
Field Details
-
NONE
A clipboard of its own that no other program sees, for a widget outside any scene.
-
-
Method Details
-
inMemory
A clipboard that is only memory: what is set is what is read, and no other program is involved. A headless backend hands one to its windows, and a test hands one to a scene.- Returns:
- a new, empty clipboard
-
text
String text()The clipboard's text, now. A paste in a key handler and a menu that greys its Paste item both want the answer in the same breath, so this one read does not wait: where the text has to come from another program through a pipe, it gives up after a second.- Returns:
- the text; the empty string when the clipboard holds none, never null
-
setText
Puts text, and nothing else, on the clipboard.- Parameters:
text- the text;nullis the empty string
-
set
Replaces what the clipboard holds. A lazy value of the transfer is asked for when a program, this one included, first reads that format.- Parameters:
content- what to offer;Transfer.EMPTYempties the clipboard
-
content
Offer content()What the clipboard holds now. The formats are answered from what the platform last reported, without a round trip, so a menu can ask on every opening; a read of something that has been replaced meanwhile fails withTransferGoneException.- Returns:
- the offer;
Offer.EMPTY's equal when the clipboard is empty
-
onChange
Hears the clipboard's content change, whoever changed it, where the platform tells.- Parameters:
listener- called on the UI thread after each change- Returns:
- the way to stop listening
-