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
    Modifier and Type
    Field
    Description
    static final Clipboard
    A clipboard of its own that no other program sees, for a widget outside any scene.
  • Method Summary

    Modifier and Type
    Method
    Description
    What the clipboard holds now.
    static Clipboard
    A clipboard that is only memory: what is set is what is read, and no other program is involved.
    onChange(Runnable listener)
    Hears the clipboard's content change, whoever changed it, where the platform tells.
    void
    set(Transfer content)
    Replaces what the clipboard holds.
    default void
    setText(@Nullable String text)
    Puts text, and nothing else, on the clipboard.
    The clipboard's text, now.
  • Field Details

    • NONE

      static final Clipboard NONE
      A clipboard of its own that no other program sees, for a widget outside any scene.
  • Method Details

    • inMemory

      static Clipboard 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

      default void setText(@Nullable String text)
      Puts text, and nothing else, on the clipboard.
      Parameters:
      text - the text; null is the empty string
    • set

      void set(Transfer content)
      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.EMPTY empties 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 with TransferGoneException.
      Returns:
      the offer; Offer.EMPTY's equal when the clipboard is empty
    • onChange

      Subscription onChange(Runnable listener)
      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